CLEO Help Get Dialog Numbers

CLEO related
Status
Not open for further replies.

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
Hi , can somebody help me?
Need explane how i can take all number from this dialog text?
http://i.imgur.com/vQYrYI8.png
@supahdupahnubah
@monday
and others...

Numbers every time change places! 
Sometimes need input first number or sometimes need input second number or sometimes need input then third number...

@springfield
You say use this? 
0C18: 2@ = strstr string1 0@ string2 1@
I'm not sure whether i understood what you say....


I started code.:

[shcode=cpp]
{$CLEO .cs}
0000:


REPEAT
  WAIT 0
UNTIL 0AFA:  SAMP_IS_READY 

 
WHILE TRUE
WAIT 0
IF
0B4C: samp is_dialog_active -1
THEN
   alloc 1@ 512 //alloc
   0BD7: 1@ //get text
   IF
   0ad4: 2@ = scan 1@ "%s %s %s %s %s%c %s %s %s %s %s %s %s %s %s %s %s %s %s %s%c %s %s %s %s %s" 6@ /// %c = next line
   THEN
      /*
        Here need something get all number from all ' %s '
      */
       alloc 0@ 8
       format 0@ "%d" 6@
       0209: 29@ = random_int_in_ranges 2873 3861
       wait 29@
       0B4B: samp set_current_dialog_editbox_text // 0@ set result
       free 0@
       0B47: samp close_current_dialog_with_button 1
       wait 200
   END
END

END  /// END WHILE TRUE 
[/shcode]
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
you could use a function like this
Code:
{$CLEO}
0000:

repeat
wait 50
until 0AFA:  is_samp_available

0AC6: 1@ = label @myString offset //1@ becomes a pointer to the following string: "test1test2test3test"


//First method (custom function)
call @Get3DigitsFromString 1 stringPointer 1@ _returnedDigits 2@ 3@ 4@
chatmsg "First method: %d %d %d" -1 2@ 3@ 4@

//Second method (scan_string function) doesn't work, I guess the first %s "eats" whole string but idk didn't check it
//0AD4: 31@ = scan_string 1@ format "%s%d%s%d%s%d%s" 9@v 5@ 14@v 6@ 19@v 7@ 25@v // this alone won't work if the digit is at the begining or at the end of the string or if digits are next to each other 
//chatmsg "Second method: %d %d %d" -1 5@ 6@ 7@
0A93: end_custom_thread


:myString
hex
"test1test2test3test" 00
end

//call @Get3DigitsFromString 1 stringPointer 0@ _returnedDigits 21@ 22@ 23@
:Get3DigitsFromString
0AC7: 20@ = var 21@ offset // 20@ will store pointer to variable 21@, so then we can add 4 to it and store values in: 21@ 22@ 23@ in a compact way
18@ = 0 //"safety" counter, to prevent checking for more than 3 numbers (otherwise variables like 30@ could be overwritten and it could mess the loop)

0C17: 31@ = strlen 0@
31@ -= 1
    for 30@ = 0 to 31@ //for each char/byte in string
    0A8D: 29@ = read_memory 0@ size 1 virtual_protect 1 //read the character and store it's ascii value to 29@
        
        if and // if is equal or higher than "0" in ascii, and if is equal or lower than "9" in ascii (http://www.asciitable.com/index/asciifull.gif)
        0029:   29@ >= 48
        002B:   57 >= 29@
        then
        29@ -= 48 // now 29@ will contain the actual number, not ascii representation of it (48 will become 0, 49 will become 1)
        0A8C: write_memory 20@ size 4 value 29@ virtual_protect 0
        20@ += 4 // from now 20@ will point to the next variable (21@ -> 22@ -> 23@)
        18@++
            if 18@ > 3
            then
            ret 3 21@ 22@ 23@
            end
        end   

    0@++ //proceeding to the next char
    end
ret 3 21@ 22@ 23@
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
springfield said:
Can you explain which numbers? You mean you need to get all the numbers from words like 'g2alima'?

Yes. 
1. If word is "First" then need find from all text first number and then put in dialog.
2. If word is "Second" then need find from all text sencond number not first and then put in dialog. I mean.: " Hell2o I'a3m ugb4ase.eu" So then need only number "3".
3. If word is "Last" then need find from all text the last number and then put in dialog.
....

[shcode=cpp]
if                                                            ↓↓↓
0ad4: 2@ = scan 1@ "%s %s %s %s %s%c %s %s %s %s %s %s %s %s first %s %s %s %s %s%c %s %s %s %s %s" 6@ /// %c = next line
then
....
end
[/shcode]
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
273
Well, if you can get the word that contains the number, then you could do something like

0@ = the word, for example "fir3st"

[shcode=cpp]
for 1@ = 0x30 to 0x39 //hex codes for 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 chars
wait 0
    if 0C2A: 2@ = strchr 0@ char 1@ //search char in string
    then 
        alloc 3@ = 2
        format 3@ "%c" 1@
        chatmsg "%s" -1 3@ //should say 3
        free 3@
    end
end
[/shcode]
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
springfield said:
Well, if you can get the word that contains the number, then you could do something like

0@ = the word, for example "fir3st"

[shcode=cpp]
for 1@ = 0x30 to 0x39 //hex codes for 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 chars
wait 0
    if 0C2A: 2@ = strchr 0@ char 1@ //search char in string
    then 
        alloc 3@ = 2
        format 3@ "%c" 1@
        chatmsg "%s" -1 3@ //should say 3
        free 3@
    end
end
[/shcode]

So i try do something , you think is good?

[shcode=cpp]
{$CLEO .cs}
0000:
  
  
REPEAT
   WAIT 0
UNTIL 0AFA:  SAMP_IS_READY 

WHILE TRUE
WAIT 0
IF 0B4C:  samp is_dialog_active -1
THEN
   alloc 1@ 512 //alloc
   0BD7: 1@ //get text
   IF
   0ad4: 2@ = scan 1@ "%s %s %s %s %s %s%c %s %s %s %s %s %s %s second %s %s %s %s %s%c %s %s %s %s %s" 0@ 0@ 0@ 0@ 0@ 0@ $NOT_USED 0@ 0@ 0@ 0@ 0@ 0@ 0@ 0@ 0@ 0@ 0@ 0@ $NOT_USED 0@ 0@ 0@ 0@ 0@ /// %c = next line
   THEN
    for 1@ = 0x30 to 0x39 //hex codes for 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 chars
    wait 0
    IF 0C2A: 2@ = strchr 0@ char 1@ //search char in string
    THEN
        alloc 3@ = 2
        format 3@ "%c" 1@
        chatmsg "%s" -1 3@ //should say 3
        free 3@
    END
END
END
END   /// END WHILE TRUE
[/shcode]
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
get tagged and asked for help, make a code specially for it, get ignored  :sadpepe:
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
monday said:
get tagged and asked for help, make a code specially for it, get ignored  :sadpepe:

Sorry if i ignore you, i just trying understand all this codes .
Thanks you for trying help to me.
@monday
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
so I tested this thing but without the dialog using the following string instead: "Prim7as hel2lo worl4d" and it printed 7, it also printed 3 for "some9thing antr3as some8thing".

So the parsing/input method is working well, I tested it without the dialog but then I commented out the testing stuff and made it ready for checking the dialog.

I bet it will work but the only things I'm not sure are:
-alloc 1@ 512 (whether it's needed)
-same with free 1@
-whether will it work with the third num because of the special "c" and "j" characters that take 2 ascii values according to google, but I bet it will work

[shcode=cpp]{$CLEO .cs}
0000:


REPEAT
 WAIT 0
UNTIL 0AFA:  SAMP_IS_READY

 
WHILE TRUE
WAIT 0
   IF 0B4C: samp is_dialog_active -1
   //IF key_down 49 // testing
   THEN
       alloc 1@ 512 // if something goes wrong I'd check whether 0BD7 automatically allocates memory (I remember that some sampfuncs opcode did this but I don't remember which)
       0BD7: 1@ //get text
       //0AC6: 1@ = label @TestingString offset //testing (this opcode was used for testing instead of 0BD7)    
       call @Get3DigitsFromString 1 stringPointer 1@ _returnedDigits 2@ 3@ 4@
       //chatmsg "The 3 numbers within string are: %d %d %d" -1 2@ 3@ 4@
       //chatmsg "Original string:" -1
       //chatmsg 1@ -1
       call @RemoveDigitsFromString 1 stringPointer 1@ // no need for return value becuase 1@ is a pointer                
       //chatmsg "String without numbers:" -1
       //chatmsg 1@ -1        
       call @WaitRandomTime 2 lowerBorder 2873 higherBorder 3861
       call @GetRequiredNumber 4 stringPointer 1@ num1 2@ num2 3@ num3 4@ _returned 5@        
       call @InputNumberToDialog 1 number 5@        
       //chatmsg "The input number is: %d" -1 5@  //testing      
       wait 200
                     
       free 1@    
   END
END  /// END WHILE TRUE

:TestingString // should input 7 (it actually worked :)
hex
"Prim7as hel2lo worl4d" 00
end

:TestingString_2  // should input 3
hex
"some9thing antr3as some8thing" 00
end

:WaitRandomTime// 2 2873 3861
0209: 31@ = random_int_in_ranges 0@ 1@
wait 31@
ret 0

:InputNumberToDialog
alloc 31@ 8
format 31@ "%d" 0@
0B4B: samp set_current_dialog_editbox_text 31@
free 31@
0B47: samp close_current_dialog_with_button 1
ret 0

:GetRequiredNumber
0AC6: 28@ = label @thirdKeyword offset
0AC6: 29@ = label @alternativeThirdKeyword offset
       
if 0C29: 31@ = stristr string1 0@ string2 "primas"
then
   0085: 30@ = 1@ // the number which has to be written is 1@ (first)
   //chatmsg "primas found" -1
else
   if 0C29: 31@ = stristr string1 0@ string2 "antras"
   then
       0085: 30@ = 2@ // the number which has to be written is 2@ (second)
       //chatmsg "antras found" -1
   else                      
       if or
           0C29: 31@ = stristr string1 0@ string2 28@ // "tre<c>ia" check
           0C29: 27@ = stristr string1 0@ string2 29@ // "paskutin<j>" check
       then
           0085: 30@ = 4@ // the number which has to be written is 4@ (third)
           //chatmsg "third/last found" -1
       end
   end
end
ret 1 30@

:thirdKeyword  //the keyword
hex
"tre" C4 8D "ia" 00 // according to http://www.unit-conversion.info/texttools/ascii/  the Lithuanian special character resembling "c" is 2 bytes in ascii "C4 8D"
end

:alternativeThirdKeyword
hex
"paskutin" C4 AF 00 //same situation with the special character resembling "j", it also takes 2 bytes "C4 AF"
end

//call @Get3DigitsFromString 1 stringPointer 0@ _returnedDigits 21@ 22@ 23@
:Get3DigitsFromString
0AC7: 20@ = var 21@ offset // 20@ will store pointer to variable 21@, so then we can add 4 to it and store values in: 21@ 22@ 23@ in a compact way
18@ = 0 //"safety" counter, to prevent checking for more than 3 numbers (otherwise variables like 30@ could be overwritten and it could mess the loop)

0C17: 31@ = strlen 0@
31@ -= 1
   for 30@ = 0 to 31@ //for each char/byte in string
   0A8D: 29@ = read_memory 0@ size 1 virtual_protect 1 //read the character and store it's ascii value to 29@
       
       if and // if is equal or higher than "0" in ascii, and if is equal or lower than "9" in ascii (http://www.asciitable.com/index/asciifull.gif)
       0029:   29@ >= 48
       002B:   57 >= 29@
       then
       29@ -= 48 // now 29@ will contain the actual number, not ascii representation of it (48 will become 0, 49 will become 1)
       0A8C: write_memory 20@ size 4 value 29@ virtual_protect 1
       20@ += 4 // from now 20@ will point to the next variable (21@ -> 22@ -> 23@)
       18@++
           if 18@ > 3
           then
           ret 3 21@ 22@ 23@
           end
       end  

   0@++ //proceeding to the next char
   end
ret 3 21@ 22@ 23@

:RemoveDigitsFromString //after using this function it will be possible to use a simple check for "primas, antras, paskutini, trecia" within the string
0C17: 31@ = strlen 0@
31@ -= 1
0085: 28@ = 0@ // copy base string pointer
005A: 28@ += 31@ //byte ending the string (0)
0085: 27@ = 0@ // copy of the base string pointer (needed for manipulation to rewrite the string without the digits, mayme 0@ could be used for that but because It's used in the "for loop" I don't want to risk and cba to check whether manipulating it affects the loop)
   for 30@ = 0@ to 28@ // 30@ = pointer to each byte in the string
   0A8D: 29@ = read_memory 30@ size 1 virtual_protect 1
       if and // if is equal or higher than "0" in ascii, and if is equal or lower than "9" in ascii (http://www.asciitable.com/index/asciifull.gif)
       0029:   29@ >= 48
       002B:   57 >= 29@
       then
       //do nothing if it's a digit
       else
       0A8C: write_memory 27@ size 1 value 29@ virtual_protect 1  
       27@++ //27@ increases only if it's not a digit, making sure digits won't be rewritten    
       end        
   end
   0A8C: write_memory 27@ size 1 value 0 virtual_protect 1 //last byte set to 0 to end the string (27@ is already increased by 1 by the opcode within the loop)
//the remaining bytes (probably 3) could be set to 0 but let's live dangerously and leave them alone
ret 0 //not need to return the string because we didn't pass the string itself to a function (the pointer of it was passed meaning that the memory at its address was and will stay rewritten)[/shcode]
 
Status
Not open for further replies.
Top