CLEO Help Help with textdraw of timer

CLEO related
Status
Not open for further replies.

Invader666

Member
Joined
Jun 3, 2020
Messages
10
Reaction score
1
Location
-
Hello, I'm not very experienced in coding, I mostly just see snippets and try to combine codes. I tried to make a mod which keeps sending command "/towcars" every 11 mins with a textdraw timer, in loop.
I have here 2 files, in file #1 i tried doing this with "show_formatted_text_highpriority" which works fine, but i want it to be textdraw, so i can position the timer above my Minimap.
But (in File #2) when i tried to add textdraw, it doesnt work. I know the code is little fucked up, but I am trying to learn :D


Code:
{$CLEO .cs}
0000:
thread "KeyBind"
0B34: samp register_client_command "att" to_label @cmd
0@ = 0

/// wait 1000 - 1 seconds
/// wait 660000 - 11 minutes

//////

:MAIN       
wait 0
if
0@ == 1
then
   0AC8: 2@ = allocate_memory_size 260
        33@ = 0
        const
            TIMER_DURATION = 660000
          end   
        while 33@ < TIMER_DURATION       
            0A8F: 1@ = 33@ - TIMER_DURATION
            0012: 1@ *= -1
            0016: 1@ /= 1000   

            0AD1: show_formatted_text_highpriority "Timp: ~r~ %d sec" time 100  1@
            wait 100
             end
        0C8F: samp process_chat_input "/towcars"
        wait 100
        0AC9: free_allocated_memory 2@
    end
  

SAMP.CmdRet()
jump @MAIN       

:CMD
wait 0
if
056D:   actor $PLAYER_ACTOR defined
then
0B12: 0@ = 0@ XOR 1
if
0@ == 1
then
0ACD: show_text_highpriority "Auto Tow-Cars: ~g~ON~w~" time 1500
else
0ACD: show_text_highpriority "Auto Tow-Cars: ~r~OFF~w~" time 1500
end
end
SAMP.CmdRet()
jump @MAIN

Code:
{$CLEO .cs}
0000:
thread "KeyBind"
0B34: samp register_client_command "att" to_label @cmd
0@ = 0

/// wait 1000 - 1 seconds
/// wait 660000 - 11 minutes

//////

:MAIN       
wait 0
if
0@ == 1
then
   0AC8: 2@ = allocate_memory_size 260
        33@ = 0
        const
            TIMER_DURATION = 660000
          end   
        while 33@ < TIMER_DURATION       
            0A8F: 1@ = 33@ - TIMER_DURATION
            0012: 1@ *= -1
            0016: 1@ /= 1000
              
                0C48: samp textdraw 155 create "Respawning cars in: ~r~%d" pos 150.5 425.0 1@   
                0C4E: samp textdraw 155 set_outline 1 color 0xFF000000
                0C4A: samp textdraw 155 set_align 3
                0C4C: samp textdraw 155 set_style 1
                0C52: samp textdraw 155 set_letter_size 0.33 1.2 color 0xFFffffff
                0C4B: samp textdraw 155 set_proportional true -1
                
            //0AD1: show_formatted_text_highpriority "Respawning cars in: ~r~ %d " time 100  1@
            wait 100
             end
        0C8F: samp process_chat_input "/towcars"
        wait 100
        0AC9: free_allocated_memory 2@
    end
  

SAMP.CmdRet()
jump @MAIN       

:CMD
wait 0
if
056D:   actor $PLAYER_ACTOR defined
then
0B12: 0@ = 0@ XOR 1
if
0@ == 1
then
0ACD: show_text_highpriority "Auto Tow-Cars: ~g~ON~w~" time 1500
else
0ACD: show_text_highpriority "Auto Tow-Cars: ~r~OFF~w~" time 1500
end
end
SAMP.CmdRet()
jump @MAIN
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
You can use My old made code source.
Without SAMPFUNCS

0.3.7 - R1
PHP:
{$CLEO .cs}

0000: NOP

REPEAT
WAIT 1000
0A8D: 31@ = readMem 0xC8D4C0 sz 4 vp 0
UNTIL 31@ == 9 // SAMP_IS_READY

0AA8: call_function_method 0x6A0050 0xC1B340 num_params 1 pop 0 'CRED098' 30@
0AA5: call 0x718600 2 pop 2 30@ "Respawning cars in: ~1~ sec"

32@ = 0 // keep timer active

while true
wait 0

if
0256:   player $PLAYER_CHAR defined
then
    0AB1: @GetLastSentTextFromChatBox 0 _Return: Command 0@ Text 1@
    0AC8: 2@ = allocate_memory_size 260
    0AD3: 2@ = format "att" // format to check command
    if
    0AB1: @IfTextContains 2 String1 0@ String2 2@ _returned: Text 3@
    then
        0A8C: write_memory 1@ size 1 value 0 virtual_protect 0 // clear last enter text
        32@ = 0   // start count only when text is detected
        30@ = true // enable draw text
    end
end

if
30@ == true
then  
    03F0: enable_text_draw 1
    0342: set_text_draw_centered 1
    03E0: draw_text_behind_textures 0
    0349: set_text_draw_font 1
    0340: set_text_draw_RGBA 255 255 255 255
    033F: set_text_draw_letter_size width 0.255 height 0.955
    081C: draw_text_outline 1 RGBA 10 10 10 255
    0AB1: @Timer 2 Seconds 66 TimingVariable 32@ _Return: TimeLeft 29@ SetTimeCountEndStatus 30@
    045A: draw_text_1number 320.0 390.0 GXT 'CRED098' numbers 29@  // Respawning cars in: ~1~ sec
end

end

:GetLastSentTextFromChatBox
{
    0.3.7 - R1
    0AB1: @GetLastSentTextFromChatBox 0 _Return: 0@
}
if 0AA2: 2@ = "samp.dll"
then              
    0A8E: 3@ = 2@ + 0x21A0E8       
    0A8D: 3@ = readMem 3@ sz 4 vp 0   
    0A8E: 4@ = 3@ + 0x14E5 // command
    0A8E: 5@ = 3@ + 0x1565 // text
end
0AB2: 2 4@ 5@

:IfTextContains
//0AB1: @IfTextContains 2 String1 0@ String2 1@
0AB1: @strlen 1 string 0@ _length 31@
0AB1: @strlen 1 string 1@ _length 30@

//initial length check (the phrase can't be longer than the main text)
if 001D:   30@ > 31@  // (int)
then
059A:  return_false
0AB2: ret 1 0
end

31@ -= 1
26@ = 0 // counter of the same chars in a row
for 29@ = 0 to 31@ // for each char of the main text  (29@ = index)
    0085: 24@ = 0@ // (int)
    005A: 24@ += 29@  // (int)
    0A8D: 28@ = read_memory 24@ size 1 virtual_protect 0

    0085: 23@ = 1@ // (int)
    005A: 23@ += 26@  // (int)
    0A8D: 27@ = read_memory 23@ size 1 virtual_protect 0

    if 003B:   28@ == 27@  // (int)
    then
    26@++
        if 002D:   26@ >= 30@  // (int)
        then
        0485:  return_true
        0062: 24@ -= 30@  // (int)
        24@ += 1
        0AB2: ret 1 24@
        end
    else
        if 26@ > 0
        then
        29@-- //check the same char again and assume it's the begining of the string but only if there was matching parts before (otherwise it would go back all the time and make infinite loop)
        end
    26@ = 0
    end       
end

059A:  return_false
0AB2: ret 1 0

:strlen
// 0AB1: @strlen 1 string 1@ _return: size 3@
for 1@ = 0 to 1024
    0A8D: 2@ = read_memory 0@ size 1 virtual_protect 0
    if not 2@ == 0
    jf break
    0@ += 1
end
0AB2: ret 1 1@

:Timer
2@ = TRUE
IF
2@ == TRUE
THEN
    0@ *= 1000
    0085: 4@ = 0@ // (int)
    0085: 3@ = 1@ // (int)
    0062: 3@ -= 4@  // (int)

    3@ /= 1000
  
    3@ *= -1
END

IF AND
2@ == TRUE
001D:   1@ > 0@  // (int)
THEN
    2@ = FALSE
END
0AB2: ret 2 3@ 2@
 
Status
Not open for further replies.
Top