supahdupahnubah said:To make a dialog key press you can use : 0B47: samp close_current_dialog_with_button 0@, 0 goes for right button, 1 for left, so you use it like this : 0B47: 1
OFC it is requires sampfuncs SB data and ingame plugin
springfield said:Pressing enter should work too, since it will close the dialog with button 0(left).
@mondayParazitas said:springfield said:Pressing enter should work too, since it will close the dialog with button 0(left).
Ok close work. How detect if is "Taip" ?
Something like that:
Now "Taip" are in the right, then close the must go to dialog with button 1(right).
Else
Now "Taip" are in the left, then close the must go to dialog with button 0(left).
So how detect if "Taip" are right or left ?
@springfield
@supahdupahnubah
supahdupahnubah said:There's lot of excuses if someone\you want to use this snippet globaly (i.e. on other server), so you have to adapt it for global usage yourself
Also I could've use Dialog ID check, but used Title one, in case admin on your server will change its ID and also Title, so you will only have to update title and string allocation size
However it was kinda hard for me, because of high body temperature, but I did it because it was quite interesting
In exchange for that, I only want you to make something simillar, so I will know you're not just a freebie, but also capable to do something yourself
Also @springfield am I retarded or there's no actual way to read string from memory properly, so I have to do this noobish function myself? :-/ :-/
P.S. Don't judge me for lot of "so" in this text, ty
[shcode=cpp]
{$CLEO .cs}
if not 31@ = samp.Base()
then
end_thread
else
while not samp.Available()
wait 100
end
end
0000:
alloc 2@ 8
format 2@ "AFK" //dialog title to detect
alloc 0@ 16
format 0@ "Taip" //button to detect
//get pointer to dialog class
0AF7: samp 13@ = get_base
13@ += 0x21A0B8
0A8D: 13@ = 13@ 4 0
13@ += 0x20
0A8D: 13@ = 13@ 4 0
while true
wait 0
if
0B4C: samp is_dialog_active -1 //is any dialog active
then
alloc 3@ 256 //alloc memory for string
0BD8: samp get_dialog_caption 3@ //get title of dialog
if 0C14: strcmp string1 2@ string2 3@ //comparing
then
0AB1: call_scm_func @allahu_akbar 2 button_to_detect 0@ initialized_ptr 13@ //calling function on line ¹43
end
end
wait 500 // avoid function flooding in both cases (succ\fail), just wooden pc things
end
:allahu_akbar
//so on this function call 0@ from line ¹36 equals 0@, while 13@ equals 1@
1@ += 0x1AD //left button string offset, right button offset is 0x1315
0C17: 2@ = strlen 0@ //size of string to detect (needed to read right amount of bytes for string)
alloc 3@ 128 //alloc memory for button string
0AB1: call_scm_func @_read_string 2 address 1@ size 2@ output 3@ //call function on line ¹60
if 0C14: strcmp string1 0@ string2 3@ //comparing
then //if on left
0B47: samp close_current_dialog_with_button 1
ret 0
else //else if on right
0B47: samp close_current_dialog_with_button 0
ret 0
end
chatmsg "Something is happened inside of my function, damn" 120007
ret 0
:_read_string //Usage : 0AB1: call_scm_func @_read_string 2 address 0@ size 1@ output 2@
0085: 2@ = 1@ * 2 // (int)
alloc 3@ 2@
format 3@ ""
for 5@ = 1 to 1@
0A8D: 4@ = 0@ 1 0
format 3@ "%s%c" 3@ 4@
0@ += 1
end
ret 1 3@
[/shcode]
supahdupahnubah said:Also @springfield am I retarded or there's no actual way to read string from memory properly, so I have to do this noobish function myself? :-/ :-/
1@ += 0x1AD //left button string offset, right button offset is 0x1315
springfield said:Normally strings are null terminated, so they end with a 0 in memory -> "0x55, 0x66 ... 0x00". That's how most C string function understand where a string ends.
So, if a variable holds the address of the text start then you can use most functions like strlen, strcpy, strncpy on it, without having to worry it will read behind the end of the text.
So a shorter version would be
Damn,gods of cleosupahdupahnubah said:Simplified, so it wont look that dumb, thanks to springfield <3
[shcode=cpp]
{$CLEO .cs}
0000:
while not samp.Available()
wait 100
end
alloc 2@ 8
format 2@ "AFK" //dialog title to detect
alloc 0@ 16
format 0@ "Taip" //button to detect
0BB0: samp 13@ = get_dialog_info_ptr
13@ += 0x20
0A8D: 13@ = 13@ 4 0
13@ += 0x1AD
while true
wait 0
if
0B4C: samp is_dialog_active -1
then
alloc 3@ 256
0BD8: samp get_dialog_caption 3@
if 0C14: strcmp string1 2@ string2 3@ //comparing
then
free 3@
if 0C14: strcmp string1 13@ string2 0@
then
0B47: samp close_current_dialog_with_button 1
else
0B47: samp close_current_dialog_with_button 0
end
end
end
wait 500
end
[/shcode]
springfield said:also.. free 3@ should be in the same context as alloc 3@
springfield said:Nice stuff, someone should post a snippet to get/read the dialog buttons since there's no default opcode for this, i think.
supahdupahnubah said:Why? I thought you can easily free it when it's not needed anymore, i.e. inside condition
supahdupahnubah said:I'd make it but afraid there might be even better version of this with RPC and other stuff which I didn't get used to
springfield said:3@ contains a pointer to the allocated memory, if the strcmp compare fails(dialog caption is not 'AFK') new memory will be allocated on the same variable, and the previous pointer will be lost, thus the previous allocated memory won't be freed.