CLEO Help Help textdraw string

CLEO related
Status
Not open for further replies.

davidel

Well-known member
Joined
Jan 17, 2020
Messages
207
Reaction score
7
Location
Germania
Hello
If i have an textdraw which shows the km travelled with a car, how i can make to do something every 5 km travelled?

the km travelled appears in a textdraw, and keeps gathering and never reset

for example
TExtdraw 2222 is “KM travelled: 100”
I want when reach KM Travelled: 105, 110, 115, 120 and so on..every 5 km travelled to say “You travelled 5 km”
 

davidel

Well-known member
Joined
Jan 17, 2020
Messages
207
Reaction score
7
Location
Germania
but how i compare to type in chat every 5 km travelled?
Code:
{$CLEO .cs}

THREAD "Distance"

REPEAT
    WAIT 0
UNTIL 0AFA:
0B34: "distance" @cmd
0@ = FALSE

WHILE TRUE
    WAIT 0
    IF 0@ == TRUE
    THEN
    IF      0C5D: samp textdraw 2052 is_exists
THEN
ALLOC 1@ = 1024
0C5A: samp textdraw 2052 get_string_to 1@
0AC8: 2@ = allocate_memory_size 260
0AB1: @get_digits_to_print param_count 2 text 1@ memory_to_store_digits_as_text 2@
0@ = FALSE
FREE 1@
END
END

:get_digits_to_print
{
0@ = text
1@ = pointer to memory where digits will be stored as text
}
0C17: 31@ = strlen 0@
for 30@ = 0 to 31@
0085: 29@ = 0@ // copy pointer
005A: 29@ += 30@ // add offset (as the loop progresses it becomes pointers to first-last character)
0A8D: 28@ = read_memory 29@ size 1 virtual_protect 1 // 28@ is the ascii number representing character
if and
28@ >= 0x30 // '0'
28@ <= 0x39 // '9'
then
0A8C: write_memory 1@ size 1 value 28@ virtual_protect 1
1@ += 1 // move to next address
end
end
0A8C: write_memory 1@ size 1 value 0 virtual_protect 1 // null-termination
0AB2: ret 0

:cmd
0B12: 0@ = 0@ XOR 1
  SAMP.CmdRet()
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
Method 1:
Read it From textdraw, calculate and do compares.

Method 2:
Make your own travelled KM tracker.
Read below:

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.
PHP:
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

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://gtamods.com/wiki/List_of_statistics_(SA)
 

davidel

Well-known member
Joined
Jan 17, 2020
Messages
207
Reaction score
7
Location
Germania
Method 1:
Read it From textdraw, calculate and do compares.

Method 2:
Make your own travelled KM tracker.
Read below:

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.
PHP:
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

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://gtamods.com/wiki/List_of_statistics_(SA)
Ok so the KM tracker it s not working for my method, i need first method to read, calculate and compare..idk how to calculate and compare can you help me?
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
you can use modulo operation and compare result with 0 (distance mod 5 == 0).

Or just check if last digit of a numer is 5 or 0
 

davidel

Well-known member
Joined
Jan 17, 2020
Messages
207
Reaction score
7
Location
Germania
so i've been trying and the only thing i made it was this
Code:
0AB1: @get_digits_to_print param_count 2 text 1@ memory_to_store_digits_as_text 2@
wait 100
0A8E: 4@ = 2@ + 2
2 means the number of digits. it will delete first 2 digits. for example if the number is 20220 after i read 4@ i will have 220
but how can i check the number of digits? for example if i have 2020 i want to delete only first “2” and if i have 20202 i want to delete first “20”
 
Last edited:

davidel

Well-known member
Joined
Jan 17, 2020
Messages
207
Reaction score
7
Location
Germania
so i've been trying and the only thing i made it was this
Code:
0AB1: @get_digits_to_print param_count 2 text 1@ memory_to_store_digits_as_text 2@
wait 100
0A8E: 4@ = 2@ + 2
2 means the number of digits. it will delete first 2 digits. for example if the number is 20220 after i read 4@ i will have 220
but how can i check the number of digits? for example if i have 2020 i want to delete only first “2” and if i have 20202 i want to delete first “20”

bump
 
Status
Not open for further replies.
Top