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]