CLEO Help How to break or stop FOR cycle

CLEO related
Status
Not open for further replies.

mokinys98

Member
Joined
Feb 15, 2018
Messages
5
Reaction score
1
Hello again,

I was making a program that actually is key-bind when you open dialog you can select what to write "not to input your text"

And I'm using a FOR cycle for that to write messages in chat

First of all how to make that if player opens a chat or presses t letter the FOR cycle going to stop and do not write anything else?
Secondly can some make that if you write command in chat like /test1 program dialog will show up. I know that has to do with label and jumps but when i do all SA:MP crashes
 

Attachments

  • Radijas.txt
    8.3 KB · Views: 13

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
@mokinys98
I modified the code so it's much easier to edit/extend, it automatically gets the name of picked option (so the long "if then end" sequence is not needed anymore)

Code:
{$CLEO .cs}
0000: NOP
0662: printstring "Aurimo radistø script'as."
REPEAT
Wait 0 
Until 0AFA: is_samp_structures_available
1@ = FALSE
alloc 5@ 100 // max length of option text (e.g. Taip arba Ne)
alloc 6@ 200 // max length of the thing to say (including option text, e.g. /rad [Taip arba Ne] Kas nori ? /radistams að)

0B34: samp register_client_command "radijas" to_label @activation


While True
Wait 0

    If
    1@ == TRUE
    Then         
    0AC6: 0@ = label @RADIJAS offset
    0B3B: samp show_dialog id 1000 caption "Rubrikos" text 0@ button_1 "Pasirinkti" button_2 "Iðeiti" style 2 
    1@ = FALSE
    end    

    If
    0B3C: samp is_dialog_responded id 1000 button 2@ list_item 3@ input_text 0
    Then  
        If 
        2@ == 1
        Then
        0AB1: @GetNthRADIJAS 2 option_id 3@ string_pointer 5@
        format 6@ "/rad [%s] Kas nori ? /radistams að" 5@
        7@ = True   
        32@ = 15001 // 32@ is self-increasing timer/counter
        end
    end // dialoga uzbaige  
    

    if 7@ == True // if some radijas was picked
    then   
        if 0B21:     samp is_chat_opened  
        //Not Samp.IsDialogActive(-1)
        then  
        0AD1: show_formatted_text_highpriority "Radijas notifications ~R~stopped" time 1000
        7@ = False 
        end
        
        if 32@ > 15000 // using 32@ timer will not block the code the way "wait 15000" did, so it will be able to deactivate it
        then
        
        chatmsg 6@ -1
        say 6@
        32@ = 0
        end  
    end
    
END // While True loopas


//0AB1: @ReadStrFromList 2 at @STRINGS with_id 3 save_into 0@
:GetNthRADIJAS
{
    0@ = option_id
    1@ = string_pointer (where RADIJAS option (e.g. Taip arba Ne) will be writen
}

0AC6: 29@ = label @RADIJAS offset 
alloc 28@ 300
call @GetNthLineFromString 3 line_id 0@ string_pointer 29@ destination_string_pointer 28@
0AA5: call 0x8220AD num_params 3 pop 3 1@ "%*[^}]}%[^[]" 28@

// remove the empty space from the end of option name
0C17: 27@ = strlen 1@
005A: 1@ += 27@
1@--
0A8C: write_memory 1@ size 1 value 0 virtual_protect 0

free 28@
0AB2: 0

:GetNthLineFromString
{
 0@ - line number
 1@ - string pointer
 2@ - destination string pointer
}
30@ = 0 // count of new lines
while true
0A8D: 31@ = read_memory 1@ size 1 virtual_protect 0
    if 31@ == 0
    then
    // END OF STRING FOUND
    break
    end
    
    if 31@ == 0xA //'\n'
    then
    30@++
        if 003B: 30@ == 0@
        then
        1@++
        0085: 29@ = 1@ // 29@ = str pointer
        28@ = 0 // 28@ = line length
            while true
            0A8D: 31@ = read_memory 1@ size 1 virtual_protect 0
                if or
                31@ == 0xA //'\n'
                31@ == 0
                then
                // COPY LINE AND RETURN
                0C24: strncpy destination 2@ source 29@ size 28@
                ret 0
                end
            1@++
            28@++
            end
        end   
    end

1@++
end
ret 0


:RADIJAS
hex
"{FF0000}Pirmadienio rubrikos" 0A
"•{328951}Taip arba Ne [Rangas:2]" 0A
"•{328951}Atspëk þodá [Rangas:2]" 0A
"•{eefb1c}Anekdotai [Rangas:3]" 0A
"•{eefb1c}Veidrodis [Rangas:3]" 0A
"•{eefb1c}Euras ar Litas [Rangas:3]" 0A
"{FF0000}Antradienio rubrikos" 0A
"•{328951}Raðyk kol gali [Rangas:2]" 0A
"•{328951}Darbai [Rangas:2]" 0A
"•{328951}Raidþiø Matematika [Rangas:2]" 0A
"•{eefb1c}Tiesa ir Melas [Rangas:3]" 0A
"•{ea9b07}Spëk ir laimëk [Rangas:4]" 0A 
"{FF0000}Treèiadienio rubrikos" 0A   
"•{328951}Sostinës [Rangas:2]" 0A   
"•{328951}Skaièiø dëlionë [Rangas:2]" 0A
"•{328951}Atspëk dainà [Rangas:2]" 0A
"•{328951}Ðalys [Rangas:2]" 0A
"•{eefb1c}Máslë [Rangas:3]" 0A       
"{FF0000}Ketvirtadienis rubrikos" 0A
"•{328951}Auto þinovas [Rangas:2]" 0A  
"•{328951}10 Sekundþiø [Rangas:2]" 0A    
"•{328951}Vertëjas [Rangas:2]" 0A          
"•{328951}Atspëk futbolininkà [Rangas:2]" 0A 
"•{328951}Miestai[Rangas:2]" 0A            
"•{eefb1c}Telefonø modeliai [Rangas:3]" 0A  
"{FF0000}Penktadienio rubrikos" 0A
"•{328951}Mënesiai [Rangas:2]" 0A       
"•{328951}Lietuvos miestai [Rangas:2]" 0A   
"•{eefb1c}Atspëk gyvunà [Rangas:3]" 0A     
"•{eefb1c}Lyginis ar Nelyginis [Rangas:3]" 0A   
"•{eefb1c}Surask klaidà [Rangas:3]" 0A    
"{FF0000}Ðeðtadienio rubrikos" 0A
"•{328951}Kur þaidþia ðis þaidëjas [Rangas:2]" 0A   
"•{328951}Miklieji pirðtai [Rangas:2]" 0A
"•{eefb1c}Klausimanija [Rangas:3]" 0A
"•{ea9b07}Daugiau arba Maþiau [Rangas:4]" 00
end

:activation
if 1@ == False
then
1@ = True
0AD1: show_formatted_text_highpriority "Radijas ~G~activated" time 1000
end
samp.CmdRet()
 

mokinys98

Member
Joined
Feb 15, 2018
Messages
5
Reaction score
1
Thanks for your help, that's very nice off your side. I'm same programmer 5 years c++ and php.

Still the cleo and its opcodes I don't know very much that's what hold me in place. .

I thought my self that I need like a function so the I could call it for printing because my code in cleo looks low level

Again thanks for your hard work!
 

shanker

Well-known member
Joined
Sep 18, 2016
Messages
291
Reaction score
16
Location
Romania
Thanks for your help, that's very nice off your side. I'm same programmer 5 years c++ and php.

Still the cleo and its opcodes I don't know very much that's what hold me in place. .

I thought my self that I need like a function so the I could call it for printing because my code in cleo looks low level

Again thanks for your hard work!

you have sanny documentation..its very good explained
 
Status
Not open for further replies.
Top