CLEO Help Question

CLEO related
Status
Not open for further replies.

Parazitas

God
Joined
Jan 2, 2017
Messages
3,116
Solutions
5
Reaction score
882
Location
Lithuania
How i can detect car distance traveled kilometers?

I mena start point is when i sit in car and driving, end point is when i left car. After then kilometers restart.
It's like kilometers recorder.

@supahdupahnubah
@Springfield
@Monday
 

bladero

Active member
Joined
Jan 3, 2017
Messages
73
Reaction score
0
The way i see doing this is by getting ur current x,y pos then waiting some time(not much) and then getting another x,y position and then calculating distance by using 0509. And at the begining you would just need condition if and check if player is in car then just set some variable thats gonna be ur travelled distance to 0.
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,126
Solutions
1
Reaction score
158
don't measure the distance. Measure the time and speed, add speed up over the time and divide it by number of measurements, this way you'll get the average speed. By knowing average speed and the time of travel you can calculate the distance travelled.

Measuring distance by checking difference between coordinates will lead you to incorrect result if the vector of movement isn't completely straight
 
Joined
Dec 31, 2015
Messages
712
Reaction score
27
monday said:
don't measure the distance. Measure the time and speed, add speed up over the time and divide it by number of measurements, this way you'll get the average speed. By knowing average speed and the time of travel you can calculate the distance travelled.

Measuring distance by checking difference between coordinates will lead you to incorrect result if the vector of movement isn't completely straight

If I wasn't sleeping on the class in the college 3 hours ago and was at home - I'd say the same thing
The probably accurate and better thing would be setting up a hook on a instruction that writes coords value to the ped structure then incrementing your local counter variable with the delta based on previous and current value 
Might be pretty much expensive function if you don't add a "choke" variable which will count the amount of calls, so it will do the above calculations only if the X amount of calls passed by before
 
Joined
Feb 18, 2005
Messages
2,963
Reaction score
267
GTA keeps track of distance travelled by each vehicle type(plane, boat, bike, car, foot etc.), to display these values in the stats menu.
This should be way easier and more accurate than checking speed, distance etc.
[shcode=cpp]
WHILE TRUE
   WAIT 0
   //check if actor is in a car & driving
   IF 00DF: actor $PLAYER_ACTOR driving
   THEN
       //distance travelled by car
       0653: 0@ = float_stat 4
       WHILE 00DF: actor $PLAYER_ACTOR driving
           WAIT 0
           0653: 1@ = float_stat 4
           0063: 1@ -= 0@          
           1@ *= 0.0003048 //feet to kilometers
           0AD1: "You've driven %0.3fkm" 100 1@
       END
   END
END
[/shcode]

This will reset KMs, once you leave that car.
To display the total distance travelled by car in that game session, just read the stat with id 4, and convert from ft to km.
Here's the rest of stat id that could be useful https://www.gtamodding.com/wiki/List_of_statistics_(SA)
 
Joined
Dec 31, 2015
Messages
712
Reaction score
27
springfield said:
GTA keeps track of distance travelled by each vehicle type(plane, boat, bike, car, foot etc.), to display these values in the stats menu.
This should be way easier and more accurate than checking speed, distance etc.

This will reset KMs, once you leave that car.
To display the total distance travelled by car in that game session, just read the stat with id 4, and convert from ft to km.
Here's the rest of stat id that could be useful https://www.gtamodding.com/wiki/List_of_statistics_(SA)


No doubt springfield have grabbed all the pussies as always
 

HowEnCokkien

Well-known member
Joined
Jul 9, 2017
Messages
307
Reaction score
9
springfield said:
GTA keeps track of distance travelled by each vehicle type(plane, boat, bike, car, foot etc.), to display these values in the stats menu.
This should be way easier and more accurate than checking speed, distance etc.
[shcode=cpp]
WHILE TRUE
   WAIT 0
   //check if actor is in a car & driving
   IF 00DF: actor $PLAYER_ACTOR driving
   THEN
       //distance travelled by car
       0653: 0@ = float_stat 4
       WHILE 00DF: actor $PLAYER_ACTOR driving
           WAIT 0
           0653: 1@ = float_stat 4
           0063: 1@ -= 0@          
           1@ *= 0.0003048 //feet to kilometers
           0AD1: "You've driven %0.3fkm" 100 1@
       END
   END
END
[/shcode]

This will reset KMs, once you leave that car.
To display the total distance travelled by car in that game session, just read the stat with id 4, and convert from ft to km.
Here's the rest of stat id that could be useful https://www.gtamodding.com/wiki/List_of_statistics_(SA)
tech me wey to heck samp plz springfold i ned it
 

Parazitas

God
Joined
Jan 2, 2017
Messages
3,116
Solutions
5
Reaction score
882
Location
Lithuania
1. Why  killometers bug all cleo code?
2. Why i get wrong car speed?
[shcode=cpp]
{$CLEO}

0000: NOP

REPEAT
wait 0
UNTIL 0AFA:

0B34: "carinfo" @CarInformative
0AC8: 7@ = allocate_memory_size 260  /// Car name
0AC8: 8@ = allocate_memory_size 260  /// Gass
0AC8: 9@ = allocate_memory_size 260  /// Speed
0AC8: 13@ = allocate_memory_size 260  /// Kilometers

WHILE TRUE
wait 0

IF AND
00DF:   actor $PLAYER_ACTOR driving
11@ == TRUE
THEN
   5@ = TRUE
ELSE
   5@ = FALSE
END

IF
5@ == TRUE
THEN
///////////////////////////////////////// Box /////////////////////////////////////////
   03F0: enable_text_draw 1
   038E: draw_box_position 320.0 409.0 size 136.0 45.0 RGBA 255 255 255 255 //White//
   038E: draw_box_position 320.0 409.0 size 134.0 43.0 RGBA 0 0 0 255 //Black//
   03C0: 0@ = actor $PLAYER_ACTOR car
   0227: 2@ = car 0@ health
   02E3: 3@ = car 0@ speed
   IF
   056E:   car 0@ defined
   THEN
       0441: 1@ = car 0@ model
       0ADB: 0@s = car_model 1@ name
       0C50: samp textdraw 421 set_string "Transport:"
       0AD3: string_format 7@ format "%s" 0@s /// Format car name                    
       0C28: strlwr in 7@ out 7@  /// Make all small letters
       0C50: samp textdraw 420 set_string 7@ /// Car name
       0C50: samp textdraw 425 set_string "Kilometers:"
       0C50: samp textdraw 424 set_string "Speed:"
       0AD3: string_format 9@ format "%0.1f" 3@
       0C50: samp textdraw 426 set_string 9@
       0C50: samp textdraw 422 set_string "G:"
       0AD3: string_format 8@ format "%d" 2@
       0C50: samp textdraw 423 set_string 8@
//////////// Killometers ////////////  
   0653: 14@ = float_stat 4
   WHILE 00DF: actor $PLAYER_ACTOR driving
   WAIT 0
   0653: 15@ = float_stat 4
   0063: 15@ -= 14@          
   15@ *= 0.0003048 //feet to kilometers
   0AD3: string_format 13@ format "%0.3f" 15@
   0C50: samp textdraw 427 set_string 13@
   END /// END WHILE 00DF: actor $PLAYER_ACTOR driving
   
   END
END

END // END WHILE TRUE

:CarInformative
IF
11@ == TRUE
THEN
   0C5E: samp textdraw 420 delete
   0C5E: samp textdraw 421 delete
   0C5E: samp textdraw 422 delete
   0C5E: samp textdraw 423 delete
   0C5E: samp textdraw 424 delete
   0C5E: samp textdraw 425 delete
   0C5E: samp textdraw 426 delete
   0C5E: samp textdraw 427 delete
   11@ = FALSE
ELSE
   11@ = TRUE
///////////////////////////////////////// Car Name /////////////////////////////////////////////////    
0C48: samp textdraw 420 create "" pos 326.000000 390.000000 // Poss textdraw.: Left - / right + , Z.
0C4D: samp textdraw 420 set_shadow 2 color 0xFF000000 // Shadow textdraw .
0C4E: samp textdraw 420 set_outline 1 color 0xFF000000 // Outline textdraw .
0C4F: samp textdraw 420 set_model 0 rotation 0.0 0.0 0.0 zoom 1.0 veh_color 0xFFFFFFFF 0xFFFFFFFF
0C52: samp textdraw 420 set_letter_size 0.300000 1.000000 color 0xFFC4A656 /// textdraw color , etc...
///////////////////////////////////////// Word.: Transport: ////////////////////////////////////////
0C48: samp textdraw 421 create "" pos 265.000000 390.000000 // Poss textdraw.: Left - / right + , Z.
0C4D: samp textdraw 421 set_shadow 2 color 0xFF000000 // Shadow textdraw .
0C4E: samp textdraw 421 set_outline 1 color 0xFF000000 // Outline textdraw .
0C4F: samp textdraw 421 set_model 0 rotation 0.0 0.0 0.0 zoom 1.0 veh_color 0xFFFFFFFF 0xFFFFFFFF
0C52: samp textdraw 421 set_letter_size 0.300000 1.000000 color 0xFFFFFFFF /// textdraw color , etc...
///////////////////////////////////////// Word.: G ////////////////////////////////////////
0C48: samp textdraw 422 create "" pos 262.000000 401.000000 // Poss textdraw.: Left - / right + , Z.
0C4D: samp textdraw 422 set_shadow 2 color 0xFF000000 // Shadow textdraw .
0C4E: samp textdraw 422 set_outline 1 color 0xFF000000 // Outline textdraw .
0C4F: samp textdraw 422 set_model 0 rotation 0.0 0.0 0.0 zoom 1.0 veh_color 0xFFFFFFFF 0xFFFFFFFF
0C52: samp textdraw 422 set_letter_size 0.300000 1.000000 color 0xFF282F64 /// textdraw color , etc...
///////////////////////////////////////// G ////////////////////////////////////////
0C48: samp textdraw 423 create "" pos 275.000000 401.000000 // Poss textdraw.: Left - / right + , Z.
0C4D: samp textdraw 423 set_shadow 2 color 0xFF000000 // Shadow textdraw .
0C4E: samp textdraw 423 set_outline 1 color 0xFF000000 // Outline textdraw .
0C4F: samp textdraw 423 set_model 0 rotation 0.0 0.0 0.0 zoom 1.0 veh_color 0xFFFFFFFF 0xFFFFFFFF
0C52: samp textdraw 423 set_letter_size 0.300000 1.000000 color 0xFFFFFFFF /// textdraw color , etc...
///////////////////////////////////////// Word.: Speed ////////////////////////////////////////
0C48: samp textdraw 424 create "" pos 305.000000 401.000000 // Poss textdraw.: Left - / right + , Z.
0C4D: samp textdraw 424 set_shadow 2 color 0xFF000000 // Shadow textdraw .
0C4E: samp textdraw 424 set_outline 1 color 0xFF000000 // Outline textdraw .
0C4F: samp textdraw 424 set_model 0 rotation 0.0 0.0 0.0 zoom 1.0 veh_color 0xFFFFFFFF 0xFFFFFFFF
0C52: samp textdraw 424 set_letter_size 0.300000 1.000000 color 0xFF282F64 /// textdraw color , etc...
///////////////////////////////////////// Word.: Killometers ////////////////////////////////////////
0C48: samp textdraw 425 create "" pos 262.000000 412.000000 // Poss textdraw.: Left - / right + , Z.
0C4D: samp textdraw 425 set_shadow 2 color 0xFF000000 // Shadow textdraw .
0C4E: samp textdraw 425 set_outline 1 color 0xFF000000 // Outline textdraw .
0C4F: samp textdraw 425 set_model 0 rotation 0.0 0.0 0.0 zoom 1.0 veh_color 0xFFFFFFFF 0xFFFFFFFF
0C52: samp textdraw 425 set_letter_size 0.300000 1.000000 color 0xFF282F64 /// textdraw color , etc...
///////////////////////////////////////// Speed ////////////////////////////////////////
0C48: samp textdraw 426 create "" pos 345.000000 401.000000 // Poss textdraw.: Left - / right + , Z.
0C4D: samp textdraw 426 set_shadow 2 color 0xFF000000 // Shadow textdraw .
0C4E: samp textdraw 426 set_outline 1 color 0xFF000000 // Outline textdraw .
0C4F: samp textdraw 426 set_model 0 rotation 0.0 0.0 0.0 zoom 1.0 veh_color 0xFFFFFFFF 0xFFFFFFFF
0C52: samp textdraw 426 set_letter_size 0.300000 1.000000 color 0xFFFFFFFF /// textdraw color , etc...
///////////////////////////////////////// Kilometers ////////////////////////////////////////
0C48: samp textdraw 427 create "" pos 310.000000 401.000000 // Poss textdraw.: Left - / right + , Z.
0C4D: samp textdraw 427 set_shadow 2 color 0xFF000000 // Shadow textdraw .
0C4E: samp textdraw 427 set_outline 1 color 0xFF000000 // Outline textdraw .
0C4F: samp textdraw 427 set_model 0 rotation 0.0 0.0 0.0 zoom 1.0 veh_color 0xFFFFFFFF 0xFFFFFFFF
0C52: samp textdraw 427 set_letter_size 0.300000 1.000000 color 0xFF282F64 /// textdraw color , etc...  

END

0B43:
[/shcode]

@supahdupahnubah
@springfield
@monday
 
Status
Not open for further replies.
Top