How to break or stop FOR cycle

Joined
Feb 15, 2018
Messages
6
Likes
1
Points
3
#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

monday

Well-Known Member
Joined
Jun 23, 2014
Messages
961
Likes
23
Points
68
#6
@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
[email protected] = FALSE
alloc [email protected] 100 // max length of option text (e.g. Taip arba Ne)
alloc [email protected] 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
    [email protected] == TRUE
    Then         
    0AC6: [email protected] = label @RADIJAS offset
    0B3B: samp show_dialog id 1000 caption "Rubrikos" text [email protected] button_1 "Pasirinkti" button_2 "Iðeiti" style 2 
    [email protected] = FALSE
    end    

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

    if [email protected] == 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
        [email protected] = False 
        end
        
        if [email protected] > 15000 // using [email protected] timer will not block the code the way "wait 15000" did, so it will be able to deactivate it
        then
        
        chatmsg [email protected] -1
        say [email protected]
        [email protected] = 0
        end  
    end
    
END // While True loopas


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

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

// remove the empty space from the end of option name
0C17: [email protected] = strlen [email protected]
005A: [email protected] += [email protected]
[email protected]
0A8C: write_memory [email protected] size 1 value 0 virtual_protect 0

free [email protected]
0AB2: 0

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

[email protected]++
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 [email protected] == False
then
[email protected] = True
0AD1: show_formatted_text_highpriority "Radijas ~G~activated" time 1000
end
samp.CmdRet()
 
OP
OP
M
Joined
Feb 15, 2018
Messages
6
Likes
1
Points
3
#7
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
282
Likes
17
Points
33
Location
Romania
#8
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
 
Top