Jump to content

How do I calculate the difference between a local variable and an upda


Recommended Posts

genghisfuckingkhan

This is the snippet of the code relevant to my question:

:DRIVE...004D: jump_if_false @ERROR00A0: store_actor $PLAYER_ACTOR position_to 4@ 5@ 6@0509: 7@ = distance_between_XY 4@ 5@ and_XY 1@ 2@0AD0: show_formatted_text_lowpriority "~w~[iNFO]~w~ CHECKPOINT FOUND! ~r~%f ~w~ meters left!" time 100 7@ 03C0: 0@ = actor $PLAYER_ACTOR car00AD: set_car 0@ max_speed_to 100.000A8: set_car 0@ to_psycho_driver00AE: set_car 0@ traffic_behaviour_to 40704: car 0@ drive_to 1@ 2@ 3@0001: wait 2000 ms   02E3: get_car_speed 0@ store_to 8@00D6: if and0019:   8@ > 0.00019:   7@ > 10.0004D: jump_if_false @REVERSE0002: jump @ON:REVERSE04BA: set_car_forward_speed 0@ to -10.00001: wait 3000 ms04BA: set_car_forward_speed 0@ to 0.00002: jump @DRIVE

What I want to do is when the car drives, it begins a loop of two second increments where the value of 7@ is grabbed and after two seconds the value of 7@ is grabbed again and program calculates the difference. What it returns is the distance the car has driven over two seconds.

 

Later on, I want to implement a code that when certain value is reached, this is 0, the car reverses at maximum speed for two seconds and then the cycle repeats. If 7@ doesn't work, I could just use the speed, from 8@, instead.

 

The most important problem is I can't seem to a value tracker while the car is driving, as in OPCODE 0704 is run, so that the car can reverse whenever it hits an obstacle and does not move. This way the car actually reaches its destination in a crude but successful manner.

 

Any help is welcome and will be appreciated.

Edited by Alfyn

What I want to do is when the car drives, it begins a loop of two second increments where the value of 7@ is grabbed and after two seconds the value of 7@ is grabbed again and program calculates the difference. What it returns is the distance the car has driven over two seconds.

you forgot this code

 

00A0: store_actor $PLAYER_ACTOR position_to 1@ 2@ 6@
with it, the distance you need is already calculated by this code 0509: 7@ = distance_between

example:

 

if00DF:   actor $PLAYER_ACTOR drivingjf @Cartest_100A0: store_actor $PLAYER_ACTOR position_to 1@ 2@ 6@wait 200000A0: store_actor $PLAYER_ACTOR position_to 4@ 5@ 6@0509: 7@ = distance_between_XY 4@ 5@ and_XY 1@ 2@if7@ > 10.0jf @next
If you want to compare a first driven distance with the second driven distance, you can do in this way:

 

 

 

if00DF:   actor $PLAYER_ACTOR drivingjf @Cartest_100A0: store_actor $PLAYER_ACTOR position_to 1@ 2@ 6@wait 200000A0: store_actor $PLAYER_ACTOR position_to 4@ 5@ 6@0509: 7@ = distance_between_XY 4@ 5@ and_XY 1@ 2@wait 200000A0: store_actor $PLAYER_ACTOR position_to 1@ 2@ 6@0509: 8@ = distance_between_XY 4@ 5@ and_XY 1@ 2@if0025:   8@ > 7@  // (float)jf @next

But i don't think that it was your plan

 

 

Later on, I want to implement a code that when certain value is reached, this is 0, the car reverses at maximum speed for two seconds and then the cycle repeats. If 7@ doesn't work, I could just use the speed, from 8@, instead.

There're codes to let the car automaticly drive back

 

06C7: AS_actor $PLAYER_ACTOR driver_of_car 0@ perform_action 6 timelimit 1000     //a short stop                    06C7: AS_actor $PLAYER_ACTOR driver_of_car 0@ perform_action 6 timelimit 2000000  //a long stop                    06C7: AS_actor $PLAYER_ACTOR driver_of_car 0@ perform_action 3 timelimit 3000     //backwards to the right side, than straight ahead06C7: AS_actor $PLAYER_ACTOR driver_of_car 0@ perform_action 22 timelimit 3000    //backwards to the left side, than straight ahead  06C7: AS_actor $PLAYER_ACTOR driver_of_car 0@ perform_action 14 timelimit 3000    //backward circle                  06C7: AS_actor $PLAYER_ACTOR driver_of_car 0@ perform_action 9 timelimit 3000     //bump forward                        06C7: AS_actor $PLAYER_ACTOR driver_of_car 0@ perform_action 7 timelimit 3000     //steer left                            06C7: AS_actor $PLAYER_ACTOR driver_of_car 0@ perform_action 8 timelimit 3000     //steer right

 

 

 

Furhtermore this code can check if the car have movement progress:

 

06A2: get_car 0@ velocity_in_direction_XYZ 2@ 3@ 4@
Example script to display the output on screen

 

 

 

{$CLEO .cs}thread 'GCRVELO':GCRVELO_3wait 0 if0256:   player $PLAYER_CHAR defined jf @GCRVELO_3if00DF:   actor $PLAYER_ACTOR drivingjf @GCRVELO_303C0: 0@ = actor $PLAYER_ACTOR car:GCRVELO_50001: wait 0 ms if0256:   player $PLAYER_CHAR defined jf @GCRVELO_3if  and8119:   not   car 0@ wrecked00DF:   actor $PLAYER_ACTOR drivingjf @GCRVELO_306A2: get_car 0@ velocity_in_direction_XYZ 2@ 3@ 4@0092: 2@ = float_to_integer 2@  0092: 3@ = float_to_integer 3@0092: 4@ = float_to_integer 4@03F0: enable_text_draw 1045A: text_draw_1number  50.0  45.0 'NUMBER' 2@    // value045A: text_draw_1number  50.0  65.0 'NUMBER' 3@    // value045A: text_draw_1number  50.0  85.0 'NUMBER' 4@    // valuejump @GCRVELO_5

 

Edited by ZAZ
genghisfuckingkhan

Thanks for replying, I really appreciate it!

 

Furhtermore this code can check if the car have movement progress:

06A2: get_car 0@ velocity_in_direction_XYZ 2@ 3@ 4@
Example script to display the output on screen
{$CLEO .cs}thread 'GCRVELO':GCRVELO_3wait 0 if0256:   player $PLAYER_CHAR defined jf @GCRVELO_3if00DF:   actor $PLAYER_ACTOR drivingjf @GCRVELO_303C0: 0@ = actor $PLAYER_ACTOR car:GCRVELO_50001: wait 0 ms if0256:   player $PLAYER_CHAR defined jf @GCRVELO_3if  and8119:   not   car 0@ wrecked00DF:   actor $PLAYER_ACTOR drivingjf @GCRVELO_306A2: get_car 0@ velocity_in_direction_XYZ 2@ 3@ 4@0092: 2@ = float_to_integer 2@  0092: 3@ = float_to_integer 3@0092: 4@ = float_to_integer 4@03F0: enable_text_draw 1045A: text_draw_1number  50.0  45.0 'NUMBER' 2@    // value045A: text_draw_1number  50.0  65.0 'NUMBER' 3@    // value045A: text_draw_1number  50.0  85.0 'NUMBER' 4@    // valuejump @GCRVELO_5

 

OK but what is the variable/integer that tells me the speed of the car? Because the code is going to give me three and I only need one.

Edited by Alfyn

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 0 User Currently Viewing
    0 members, 0 Anonymous, 0 Guests

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.