CLEO Help Getting value from chat string

CLEO related
Status
Not open for further replies.

KamikazeSripterul

Well-known member
Joined
Jun 30, 2019
Messages
353
Reaction score
23
So what I've tried to do is to get the value from the chat and write it in .ini file.
This is the string : Your account balance is now $25.255.525. It doesn't work. It just gives a lot of errors then crashes.
Code:
alloc 2@ 260
    0B75: samp get_chat_string 99 text_to 2@ prefix_to 3@ color_to 4@ prefix_color_to 5@
    
    if 0C18: 10@ = strstr string1 2@ string2 "Your account balance is now" 15@
    then
        format "%d" 2@
        0AF5: write_string 15@ to_ini_file "cleo\ServerCMD.ini" section "Bank" key "balance"
        chatmsg "{000089}[{770089}Bank Manager{000089}]: {e0388f}Account Balance Changed."
        chatmsg "{000089}[{770089}Bank Manager{000089}]: {e0388f}You can check your new balance using {ffffff}[/bankmenu] {e0388f}> {ffffff}Check your balance"
        wait 1000
    end
    
    free 2@
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
This snippet Return string after symbol $
PHP:
:GetText
{
    0AB1: @GetText 1 WriteStringPointer 0@ rnt 1@
}
0C17: 31@ = strlen 0@
31@ -= 1
    for 30@ = 0 to 31@
    0A8D: 29@ = read_memory 0@ size 1 virtual_protect 1
  
        if
        29@ == 36 // 36 = $
        then
            0@++ 
            0AB2: ret 1 0@                                                
        end 

    0@++
    end
0AB2: ret 0
 

KamikazeSripterul

Well-known member
Joined
Jun 30, 2019
Messages
353
Reaction score
23
This snippet Return string after symbol $
PHP:
:GetText
{
    0AB1: @GetText 1 WriteStringPointer 0@ rnt 1@
}
0C17: 31@ = strlen 0@
31@ -= 1
    for 30@ = 0 to 31@
    0A8D: 29@ = read_memory 0@ size 1 virtual_protect 1
 
        if
        29@ == 36 // 36 = $
        then
            0@++
            0AB2: ret 1 0@                                               
        end

    0@++
    end
0AB2: ret 0
And how exactly do I use this code in my code? I'm a bit confused. What do I have to do with it?
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
PHP:
if 0C29: $not_used = strstr string1 2@ string2 "Your account balance is now"
then
    0AB1: @GetText 1 WriteStringPointer 2@ rnt 15@
    0AF5: write_string 15@ to_ini_file "cleo\ServerCMD.ini" section "Bank" key "balance"
end

:GetText
{
    0AB1: @GetText 1 WriteStringPointer 0@ rnt 1@
}
0C17: 31@ = strlen 0@
31@ -= 1
    for 30@ = 0 to 31@
    0A8D: 29@ = read_memory 0@ size 1 virtual_protect 1
  
        if
        29@ == 36 // 36 = $
        then
            0@++ 
            0AB2: ret 1 0@                                                
        end 

    0@++
    end
0AB2: ret 0
 

KamikazeSripterul

Well-known member
Joined
Jun 30, 2019
Messages
353
Reaction score
23
PHP:
if 0C29: $not_used = strstr string1 2@ string2 "Your account balance is now"
then
    0AB1: @GetText 1 WriteStringPointer 2@ rnt 15@
    0AF5: write_string 15@ to_ini_file "cleo\ServerCMD.ini" section "Bank" key "balance"
end

:GetText
{
    0AB1: @GetText 1 WriteStringPointer 0@ rnt 1@
}
0C17: 31@ = strlen 0@
31@ -= 1
    for 30@ = 0 to 31@
    0A8D: 29@ = read_memory 0@ size 1 virtual_protect 1
 
        if
        29@ == 36 // 36 = $
        then
            0@++
            0AB2: ret 1 0@                                               
        end

    0@++
    end
0AB2: ret 0
Do I need to allocate any memory?
 
Status
Not open for further replies.
Top