CLEO Help [Lock] Cut a string [Lock]

CLEO related
Status
Not open for further replies.

Grubitsh

Active member
Joined
Jul 28, 2014
Messages
104
Reaction score
0
Hi

I need to extract some informations from a chatlog string.
See the typical sentence http://image.noelshack.com/fichiers/2016/02/1452927126-eeeeee.png

The structure of the string is always the same: NAME + Rank: INTEGER + Tel: INTEGER + Random String
Code:
Alloc Memory for string variables (1 2 3 4 7 10)
samp.GetChatString(99, 1@, 2@, 3@, 4@)
 IF
0AD4: 6@ = scan_string 1@ format "%s Rank: %d, Tel: %d  %s" 7@ 8@ 9@ 10@
THEN
0AF8: "Name: %s" -1 7@ // Crash
0AF8: "Rank: %d" -1 8@  // Works good
0AF8: "Telephone Number: %d" -1 9@ // Works good
0AF8: "Random string: %s" -1 10@ // Crash 
END

Free memory

Rank and Telephone works good (they are INT) but the NAME and Random String don't work I don't know why.

Can you help me please ?
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
Re: Cut a string

0AD4 doesn't work with normal vars, even if memory is allocated(0ac8). Use @v, and remember they occupy the next 4 vars.
 

Juanbustillos

Active member
Joined
Mar 29, 2014
Messages
29
Reaction score
4
Location
Ecuador
Re: Cut a string

Try this
Code:
{$CLEO}
0000:

repeat
    wait 40
until SAMP.Available()

0B34: "get" @get

WHILE TRUE
WAIT 0
END

:get
alloc 1@ 256
FOR 0@ = 90 TO 99
    SAMP.GetChatString(0@, 1@, 2@, 2@, 2@)
    IF 0C29: 2@ = str 1@ find "Rank:"
    THEN
    0AD4: 2@ = scan 1@ format "%s, Rank: %d, Tel: %d %s" 5@v 3@ 4@ 10@v
    chatmsg "%s" -1 5@v
    chatmsg "Rank: %d" -1 3@
    chatmsg "Tel: %d" -1 4@
    chatmsg "String: %s" -1 10@v
    END
END
free 1@
cmdret
 

Grubitsh

Active member
Joined
Jul 28, 2014
Messages
104
Reaction score
0
Re: Cut a string

Ok thx.

Your code works a bit. I get what I want, but it only gave me the first word of the big random string. (in this example I only showed the last chatmsg, i don't need rank,tel or name, I only need the random string after telephone number).

Here is what I scanned: http://image.noelshack.com/fichiers/2016/02/1452987123-scan.png

Here is hat I recieved: http://image.noelshack.com/fichiers/2016/02/1452987122-sca-2.png


Springfield, in fact I only need the last part of the sentence, which is just after the telephone number.


Is their a way to cut a string at a specified point ?
Like if the sentence is: "Policeman_Number1, Rank: 3, Tel 171717 Tango197 Los Santos" and say to CLEO: "I want you to cut that sentence just after the telephone number?"
 

Grubitsh

Active member
Joined
Jul 28, 2014
Messages
104
Reaction score
0
Re: Cut a string

Hi,

Here is a sentence: http://image.noelshack.com/fichiers/2016/02/1452927126-eeeeee.png
The sentence can change but the structure is always the same: [String_Name] Rank: [Int_Rank], Tel: [Int_Tel] [Random String]

I already got the full string with
Code:
 samp.GetChatString(0@, 1@, 2@, 3@, 4@)
.
It works well.
Now I would like to cut this full string, in order to have only the "Random String" at the end . (In exemple, I want to extract the: "Tango-136 Messer 10.02"

I tried:
Code:
0C16:
NOt Working

I tried:
Code:
0AD4: 31@v = scan_string 1@ format "%s Rank: %d, Tel: %d %s" 20@v 18@ 19@ 25@v
It returns only the first word of the "big string" I expect to have.
For example If I scan THIS: http://image.noelshack.com/fichiers/2016/02/1452987123-scan.png
I got this: http://image.noelshack.com/fichiers/2016/02/1452987122-sca-2.png
So, not working.


Can you help me please ?
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
Re: Cut a string

I merged your posts, since they are about the same thing.

ontopic: if you know your string has constants just use 'strstr'.. easily.

Code:
{$CLEO}
0000:
REPEAT
    wAIT 20
UNTIL 0AFA:

ALLOC 0@ = 260

WHILE TRUE
WAIT 0
samp.GetChatString(99, 0@, -1, -1, -1)  //99 is the index of last string in chat
                                        //-1 so we don't waste vars. on usless stuff
                                                                                             
    //we know the message struct. is always the same
    // [String_Name] Rank: [Int_Rank], Tel: [Int_Tel] [Random String]
    // Policeman_Number1, Rank: 3, Tel: 171717 Tango197 Los Santos
                                       
    //so we have two constants, one is 'Tel:' 
    IF 0C18: 1@ = strstr string1 0@ string2 "Tel:" //1@ returns pointer to occurance of 'Tel:" in string
    THEN 
         //could use 0AD4 here, but we have another constant
         //the phone number is the same format, everytime.. ie; 6 chars - 171717
         1@ += 12 // 'Tel: 171717 ' 
         0AD1: "%s" 1000 1@  //1@ = 'Tango197 Los Santos'
    END
END
 

Grubitsh

Active member
Joined
Jul 28, 2014
Messages
104
Reaction score
0
Re: Cut a string

LOOOOOOOOOOOOOLL I am so dumb, it works perfectly with 0C18:, thanks for your help !

Last question ! It's about memory.

I alloc my memory in a function 0AB1: (at variable 7@ in my function) then I return the result (in variable 2@ in main)
Is it a problem ?

I mean, 2@ is a string, 2@ is the returned value of a function, 2@ have never been alloc = 260

Does the program understand like: "Ok, he alloc memory  at variable 7@ (function), then he returned it into 2@ (main) so I will automaticaly alloc 260 for the variable 2@ in the main ?
It works for the moment but is it a correct way to do it ?
Code:
//Starting stuff blablabla

While true
wait 0

render.DrawText(31@, 2@, 29@, 30@, 28@)

  if
  0ADC:   test_cheat "I"
  then
  0AB1: @An_Amazing_Function 0 2@ 
  end


end

:An_Amazing_Function

//Conditions + FOR 99 to 0 Blablabla
samp.GetChatString(0@, 1@, -1, 3@, -1)
//Conditions
//If True then:
alloc 7@ = 260
0AD3: 7@ = "%s" 1@ 

//Blablablbla It's amazing stuff

0AB2: ret 1 7@
 
Status
Not open for further replies.
Top