#1 15-09-2014 04:55

Registered: 15-09-2014
Posts: 1

[Help] Bugs in my code

Hi, sorry if i'm making dumb questions. I've programmed mods on GTA SA for 5 years, but when i say 5 years, i mean 1 year modding and other 4 doing almost nothing, and then i got back now.

Though i did some sucessful mods and missions, i got stuck with a project i always wished to work: recording the path of a vehicle and being able to reproduce it in any vehicle.

So, the first method i applied was just making an array of floats to save the vehicle positions, and then reproduce them later. I did a small one, and it worked.

Then i sophisticated it, i made bigger arrays, made it save the Z and Y angles (there is no opcode for the x_angle) and the speed, used it to smooth the movement, so the vehicle would be moving while it jumps between the positions.

The problem is: The code seems to run very slowly, it crashes if i make any array with more than 400 floats, and it also present several bugs, like jumping to coordinates that have nothing to do with the path recorded (and they aren't 0,0,0 too, they seem pretty random). I've checked the order of the variables to ensure that nothing was getting mixed, and nothing was.

When making bigger arrays, the code crashes on the recording, after some seconds have elapsed.

Can anyone help me here? Thank you!

Ps.: Do anyone know why the game doesn't start without a "wait" before all jumps on the code?. The loading bar of the game just gets stuck, i've tried everything, but, by the simplest the code can be, it'll still freeze the game if i don't put wait's before the jump's (and that include else_jumps too). I just put a "wait 0", i tried NOP's, and they don't work. I've suffered from it since i started, with different CLEO and GTA SA versions and installations, on differente computers and OS's.

//File header and declaration of the variables, the array and thread.
{$CLEO .cs}
thread 'REC'
$Array: array 300 of Float
Int 1@
Int 2@
Float 3@ 
Float 4@ 
Float 5@ 
Float 6@
Float 7@
Float 8@

//Condition to recording process (pressing of TAB+R), and main loop starting point

if and
0AB0:   key_pressed 9 
0AB0:   key_pressed 82 

//recording process (if TAB+R is not pressed, the process flow continues on the else below this block)

2@ = 0 //--                                 --setting the array index to zero
03C0: 1@ = actor $PLAYER_ACTOR car //--      --preparing the player car variable
Car.StorePos(1@, 3@, 4@, 5@) //--            --take position values from the player car to this variables
0174: 6@ = car 1@ Z_angle
06BE: 7@ = car 1@ y_angle
02E3: 8@ = car 1@ speed //--       --same thing with Z/Y angles and speed (i didn't find any opcode to the x angle)
$Array[2@]=3@           //Ps.: Speed is set to smooth the movement, that otherwise would be more like a jumping.
2@ += 1
2@ += 1
2@ += 1
2@ += 1
2@ += 1
2@ += 1 //---          --Save values from the local variables to the array, incrementing the index after each one
wait 250 //--          --Wait 250ms to make the recording be 4hz
if //---               --Condition bolock to check if the recording have filled the array  
2@ >= 300
wait 0
jump @REC_1 //--        --Go back to the start of the key press check loop in case the array is full        
wait 0
jump @REC_2 //--        --Keep recording if array is not full yet

else //--               --Process flow continues here in case of TAB+R was not pressed

if and //--             --Same thing as the TAB+R condition, now checking for TAB+P, for playback process
0AB0:   key_pressed 9 
0AB0:   key_pressed 80

//This block will behave much like the first, except that it'll retrieve the data from the array to variables,
//and use them set the vehicle position, angles and speed. Frequency is slightly higher to smooth the movement.

2@ = 0
03C0: 1@ = actor $PLAYER_ACTOR car
2@ += 1
2@ += 1
2@ += 1
2@ += 1
2@ += 1
2@ += 1
Car.Putat(1@, 3@, 4@, 5@)
0175: set_car 1@ Z_angle_to 6@ 
0731: set_car 1@ y_angle_to 7@
04BA: set_car 1@ speed_to 8@ 
wait 220
2@ >= 300
wait 0
jump @REC_1
wait 0
jump @REC_3

else //--     --And the process flow will continue here in case nothing was pressed, going back to the start.

wait 0
jump @REC_1

end //--      --Closing the previous "if"'s


Board footer

Powered by FluxBB