CLEO Help Question: Color Finder? Detect client message colors?

CLEO related
Status
Not open for further replies.

Crayder

Active member
Joined
Mar 6, 2014
Messages
148
Reaction score
0
If there is a way, I would like to detect the color of all received client messages... Like when you receive the message from the server the variable would be set to that color... In my script I would compare that color to a simple hex color and if it matches the function would return true and the rest of my code would execute...

I wanted to know because with this I could create an auto script to help with RP jobs such as fishing, if the last color matches the fishing message then I would send the /fish cmd again...

Since the client messages can be multi-colored, this may be problematic (but easy to work around), so is there a way to store the client message's string?
 

Crayder

Active member
Joined
Mar 6, 2014
Messages
148
Reaction score
0
Ok, so, I made a test script regarding this... I used that opcode but nothing happens when I receive the messages...

Code:
{$CLEO .cs}

thread "FISHING" 
0000: NOP 
wait 5000 
jump @FISHING_25 

:FISHING_25
wait 0 
if 
   SAMP.Available
else_jump @FISHING_25 
SAMP.GetChatString(1@, 2@, 3@, 4@, 5@)
if or
    06D2: 1@ = "YOU CAUGHT A" // @v = string 
    06D2: 1@ = "SOMETHING PULLS BUT YOU DIDN'T REEL IT IN IN TIME." // @v = string 
    06D2: 1@ = "YOUR BAIT FELL OFF. TRY AGAIN." // @v = string 
    06D2: 1@ = "A FISH BRUSHES PAST THE HOOK AND YOU REEL IT IN TOO SOON." // @v = string 
else_jump @FISHING_257 
say "/FISH" 

:FISHING_257
jump @FISHING_25

Is that opcode case sensitive? If so I can't stop that because the script compiles those strings capitalized... If It's not case sensitive, I need help...  :bawww:
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
You need to allocate memory for strings.
To compare you use ==
Either use strcmp or stricmp.
You need to specify the chat line number, 99 being the last one. (GetChatString(99, 0@, 1@, 2@, 3@)

Also, go to sanny builder Tools - Options - Format - Formating - chose 'as is'.
 

Crayder

Active member
Joined
Mar 6, 2014
Messages
148
Reaction score
0
springfield link said:
You need to allocate memory for strings.
To compare you use ==
Either use strcmp or stricmp.
You need to specify the chat line number, 99 being the last one. (GetChatString(99, 0@, 1@, 2@, 3@)

Also, go to sanny builder Tools - Options - Format - Formating - chose 'as is'.
Ok, so now I have a crash... Here is what i have now...
Code:
{$CLEO .cs}

thread "FISHING" 
0000: NOP 
wait 5000 
jump @FISHING_25 

:FISHING_25
wait 0 
if 
   SAMP.Available
else_jump @FISHING_25 
SAMP.GetChatString(99, 1@, 2@, 3@, 4@)
if or
    0C14: 1@ "You caught a" 
    0C14: 1@ "Something pulls but you didn't reel it in in time." 
    0C14: 1@ "Your bait fell off. Try again." 
    0C14: 1@ "A fish brushes past the hook and you reel it in too soon." 
else_jump @FISHING_257 
say "/fish" 

:FISHING_257
jump @FISHING_25
Also, I don't know how to allocate memory, would that be what is causing the crash? Can you show me how to allocate memory?
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
Code:
{$CLEO .cs}

thread "FISHING" 
0000: NOP 
wait 5000 


0ac8: 1@ = 260
0ac8: 2@ = 260
0ac8: 3@ = 260
0ac8: 4@ = 260

:chat
wait 0
SAMP.GetChatString(99, 1@, 2@, 3@, 4@)
if or
    0C14: 1@ "You caught a" 
    0C14: 1@ "Something pulls but you didn't reel it in in time." 
    0C14: 1@ "Your bait fell off. Try again." 
    0C14: 1@ "A fish brushes past the hook and you reel it in too soon." 
then
    say "/fish"
end 
jump @chat
 

Crayder

Active member
Joined
Mar 6, 2014
Messages
148
Reaction score
0
Ok, so far the only problem is the "You caught a" line... It doesn't work because the string isn't exactly "You caught a", and the end is usually random so is there a strfind opcode?
 

pepeelpubero

Well-known member
Joined
Jan 21, 2014
Messages
433
Reaction score
1
Crayder link said:
Ok, so far the only problem is the "You caught a" line... It doesn't work because the string isn't exactly "You caught a", and the end is usually random so is there a strfind opcode?

I use this:

Code:
if
0AD4: 4@ = scan_string CHATLINE/VAR(1@) format "You caught a %s" 5@v
then
do something

%s = 5@v = some text that appears there. Also with 0AD4 you can find text with hex colors.
For example "You {FF0000}caught a %s"
 

Crayder

Active member
Joined
Mar 6, 2014
Messages
148
Reaction score
0
springfield link said:
Then use 0C18/0C29
Ok, this works perfect... But now I have just two more problems... 1. The script spams the command a few times, so its finding the strings match too quickly; 2. The script sometimes doesn't send the command, so sometimes it's not finding the string even though it IS there...

How would you go about resolving these problems?

Thanks for the help btw.

EDIT: I made some temporary fixes, I added some time to the initial wait, and made a 50 ms wait before jumping back... But it still sometimes fail to find the strings...
 

pepeelpubero

Well-known member
Joined
Jan 21, 2014
Messages
433
Reaction score
1
Crayder link said:
2. The script sometimes doesn't send the command, so sometimes it's not finding the string even though it IS there...

... But it still sometimes fail to find the strings...

It's because you are searching on LAST LINE (99) so if the cleo doesn't read THE LAST LINE then can't send the command.
 

Crayder

Active member
Joined
Mar 6, 2014
Messages
148
Reaction score
0
pepeelpubero link said:
It's because you are searching on LAST LINE (99) so if the cleo doesn't read THE LAST LINE then can't send the command.
Obviously, but the last line is the only one i want to search, if i search 98 and there is an interruption below (such as the message received when you do /fish) then it will spam the command...


ASLO: How do I compare hex colors? For example, when doing this [SAMP.GetChatString(99, 1@, 2@, 3@, 4@)], the color 3@ is the initial color, how do I compare it to see if it is equal to 0x4BB1FF?
 

pepeelpubero

Well-known member
Joined
Jan 21, 2014
Messages
433
Reaction score
1
Hmm i don't know how to use that opcode, i use this:

Code:
0AC8: 3@ = allocate_memory_size 260
0AB1: call @GETCHATTEXT 1 ID 99 TO 3@
if
0AD4: 4@ = scan_string 3@ format "I'm {FF0000}SEARCHING {0000FF}FOR RED TEXT ON LAST LINE"
then
0AF9: "WORKS"
end

:GETCHATTEXT
wait 500
0AB1: call @GETSAMPBASE 0 1@
1@ += 0x212A6C
0A8D: 1@ = read_memory 1@ size 4 virtual_protect 0
1@ += 0x136
0@ *= 252 
005A: 1@ += 0@
1@ += 28
0AB2: ret 1 1@

:GETSAMPBASE
wait 0
0AA2: 31@ = load_library "kernel32.dll" // IF and SET
0AA4: 30@ = get_proc_address "GetModuleHandleA" library 31@ // IF and SET
0AA7: call_function 30@ num_params 1 pop 0 "samp.dll" 0@
0ab2: ret 1 0@

So, if the last line is like this:
I'm SEARCHING FOR RED TEXT ON LAST LINE
Then the cleo will send "works" in chat. Also it works without sampfuncs (if you don't use 0AF9)
 

Crayder

Active member
Joined
Mar 6, 2014
Messages
148
Reaction score
0
pepeelpubero link said:
Hmm i don't know how to use that opcode, i use this:

Code:
0AC8: 3@ = allocate_memory_size 260
0AB1: call @GETCHATTEXT 1 ID 99 TO 3@
if
0AD4: 4@ = scan_string 3@ format "I'm {FF0000}SEARCHING {0000FF}FOR RED TEXT ON LAST LINE"
then
0AF9: "WORKS"
end

:GETCHATTEXT
wait 500
0AB1: call @GETSAMPBASE 0 1@
1@ += 0x212A6C
0A8D: 1@ = read_memory 1@ size 4 virtual_protect 0
1@ += 0x136
0@ *= 252 
005A: 1@ += 0@
1@ += 28
0AB2: ret 1 1@

:GETSAMPBASE
wait 0
0AA2: 31@ = load_library "kernel32.dll" // IF and SET
0AA4: 30@ = get_proc_address "GetModuleHandleA" library 31@ // IF and SET
0AA7: call_function 30@ num_params 1 pop 0 "samp.dll" 0@
0ab2: ret 1 0@

So, if the last line is like this:
I'm SEARCHING FOR RED TEXT ON LAST LINE
Then the cleo will send "works" in chat. Also it works without sampfuncs (if you don't use 0AF9)

I know how to use the sscanf opcode to find the color, but I want to just compare the color received in 3@, you don't need to know how to use the SAMP opcodes to compare hex colors... But, if I'm correct I could just compare it to an integer right? (By converting the hex color into a integer then comparing)
 

pepeelpubero

Well-known member
Joined
Jan 21, 2014
Messages
433
Reaction score
1
Maybe yes, converting that hex to int (cotrol+h). That's all what i know, i never use get or set chat string opcode.

IF
3@ == HEX TO INT
THEN
DO SOMETHING

Maybe it works, try it.
 

DogoCaraballo

Active member
Joined
Dec 1, 2014
Messages
25
Reaction score
0
pepeelpubero link said:
So, if the last line is like this:
I'm SEARCHING FOR RED TEXT ON LAST LINE
Then the cleo will send "works" in chat. Also it works without sampfuncs (if you don't use 0AF9)

So, is there a way to do this with the normal white text? the one wich everyone talks
 
Status
Not open for further replies.
Top