Read commands and do something about them

hello guys , this is off topic xD
this means it is kinda related to the tutorial series but it is just for open source codes :p


this will read your command like (/get , /spawn , /kill) ..etc and do something about


the following code generally  took from [member=6677]TH3RM4L[/member] , i wanted to share it because it is very simple and easy to understand , i got it from some cleo that he made (open source) -- you better say thanks to him too.

i edit some of it to make it easier and the explanations are in comments in the place you need it .



big mistakes has been fixed !
Code:
{$CLEO .cs}

0000: NOP
0B34: samp register_client_command "target" to_label @start //now when you type "/target id" it will run
//to change just replace target with any word you like >>  
//  like  0B34: samp register_client_command "whatever" to_label @start >> now "/whatever id"
31@ = 0  // = 0 make it not active

:main
wait 0                                  
if 
  31@ == 1  //check if it is active
jf @main

//your codes are here 
//ps: >> player(target) id = 4@
// player(target) car = 6@

31@ = 0      //after you finishing your coding , make it = 0 to deactive it  
SAMP.CmdRet
jump @main









:start
wait 0 
   SAMP.IsCommandTyped(0@)
if 
0AD4: 1@ = scan_string 0@ format "%d" 2@ 
else_jump @USAGE
if 
   SAMP.IsPlayerConnected(2@)
else_jump @INVLID_ID 
4@ = SAMP.GetActorHandleByPlayerID(2@)
if 
056D:   actor 4@ defined      //the target actor = 4@
else_jump @NOT_STREAMED 


// here you can do more conditions like:
if                          
    Actor.Driving(4@)
else_jump @NOT_DRIVING
00D9: 6@ = actor 4@ car
31@ = 1    // = 1 make it active
SAMP.CmdRet //retrieve the command line
goto @main 

:USAGE
wait 0 
0AF8: samp add_message_to_chat "USAGE: /target <player ID> <veh ID>" color 12566463  
31@ = 0   //make it false so  the main label don't start
SAMP.CmdRet //retrieve the command line
goto @main
:NOT_STREAMED
wait 0 
0AF8: samp add_message_to_chat "ERROR: The target is not streamed" color 12451840  
31@ = 0   //make it false so  the main label don't start
SAMP.CmdRet //retrieve the command line
goto @main 

:INVLID_ID
wait 0  
0AF8: samp add_message_to_chat "ERROR: Invalid player ID" color 12451840  
SAMP.CmdRet //retrieve the command line
31@ = 0 //make it false so  the main label don't start
goto @main 

:NOT_DRIVING
wait 0 
0AF8: samp add_message_to_chat "ERROR: The target must be  driving" color 12451840  
SAMP.CmdRet //retrieve the command line
31@ = 0 //make it false so  the main label don't start
goto @main


some people may ask what is 31@ = 0 & 31@ = 1?
well 31@ is a random variable , we can use any like 11@ 2@ 5@ ..etc (0@ - 33@)
we use this to make the script do start the cheat if 31@ = 1

so in the very begging we declare the variable 31@ to = 0 (means all stuff is off)
the script then will wait until we type the command to active the cheat
while it is waiting it will start to loop in the MAIN label and check if 31@ = 1
so if it is = 1 than it will run the other codes under the "jf @"
but when we type the command we jump to the start label
here there is many conditions we need it to be true
so we add our conditions and if all is true we make 31@ = 1 so the label MAIN can be run and function,


so we add this:

Code:
31@ = 1    // = 1 make it active
SAMP.CmdRet
goto @main


now after we put our conditions, we say if all are true then make 31@ = 1
then we put "SAMP.CmdRet" this is to  retrieve the command line (because we work with commands and we registered the command in the first place , so we have to end it , and we do this with SAMP.CmdRet" )
then we add "goto @main" it means " jump @main"

so after all conditions are true we make 31@ = 1 // and 1 means active , 0 means inactive
and after we retrieve the command line
we jump to the main  so now the script can check if 31@ = 1 or not

here we already make it 31@ = 1 in label start
so the Label MAIN is going to run normal , and after it finished it reset 31@ to 0 to end the cheat


now:
31@ = 1 means true
31@ = 0 means false
these used to check to run the script





thanks for following my offtopic sources .

 

monday

Expert
Joined
Jun 23, 2014
Messages
1,126
Solutions
1
Reaction score
158
Re: +)read commands and do something about -TUT--open source codes

Thanks for the link, explains the on/off thing. How about any other actions when the command is typed for the second time?

For example:
/abc to store coords
/abc to go there
 

DzkAy

Well-known member
Joined
Feb 20, 2014
Messages
472
Reaction score
1
Re: +)read commands and do something about -TUT--open source codes

monday link said:
Thanks for the link, explains the on/off thing. How about any other actions when the command is typed for the second time?

For example:
/abc to store coords
/abc to go there
I haven't try it yet so i don't know
SO. Try it for urself huehuehue :p
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,126
Solutions
1
Reaction score
158
Re: +)read commands and do something about -TUT--open source codes

I found out, works well:)
Code:
:Label_3
wait 0
0B12: 8@ = 8@ XOR 1
if
8@ == 1
then
// here I put what is going to happen when the command is typed for the first time
else jump @Label_2
// Label_2 states what is going to happen when the command is typed for the second time
end
SAMP.CmdRet
jump @Label_1
 

blackHat

Expert
Joined
Jul 28, 2013
Messages
930
Reaction score
2
Re: +)read commands and do something about -TUT--open source codes

monday link said:
I found out, works well:)
Code:
:Label_3
wait 0
0B12: 8@ = 8@ XOR 1
if
8@ == 1
then
// here I put what is going to happen when the command is typed for the first time
else jump @Label_2
// Label_2 states what is going to happen when the command is typed for the second time
end
SAMP.CmdRet
jump @Label_1

the codes After "else" is the end codes
So let say you spawned object with /abc
Now when u type /abc again destroy the object and end the script too , means just before u end the cheat u can make the deactivation codes such as getting stuff to normal again
 

Rockie

New member
Joined
Aug 18, 2017
Messages
4
Reaction score
0
:start
wait 0
SAMP.IsCommandTyped(0@)
if
0AD4: 1@ = scan_string 0@ format "%d" 2@
else_jump @USAGE
if
SAMP.IsPlayerConnected(2@)
else_jump @INVLID_ID
4@ = SAMP.GetActorHandleByPlayerID(2@)
if
056D: actor 4@ defined //the target actor = 4@
else_jump @NOT_STREAMED

I don't understand this part, anyone who can explain?
 

bladero

Active member
Joined
Jan 3, 2017
Messages
73
Reaction score
0
Code:
:Start // think you know this
wait 0 //and this
SAMP.IsCommandTyped(0@)  // you put this so the script can see if you typed a command that you assign above with 0B34:
if 
0AD4: 1@ = scan_string 0@ format "%d" 2@ // Script now looks for what you typed along with command in this case its looking for a number. Here you assigned variable 2@ as integer
else_jump @USAGE
if 
SAMP.IsPlayerConnected(2@) // looks like the script want you to put players id so then it checks if player is connected
else_jump @INVLID_ID 
4@ = SAMP.GetActorHandleByPlayerID(2@) // here you get the handle of player by using the id witch you put in command as i said above
if 
056D: actor 4@ defined //the target actor = 4@
else_jump @NOT_STREAMED

{
dont be confused with %d %f %s
%d is integer its a whole number like 5 or 1 u get the point
%f is float its a decimal number like 5.1 or 1.75
%s is string its a text

These are all variable types and then you assign them as said above
}
 

Rockie

New member
Joined
Aug 18, 2017
Messages
4
Reaction score
0
Yes sir but there is just one more thing unclear here... Etc 1@ 2@ 3@ 4@... What are they representing?
 

bladero

Active member
Joined
Jan 3, 2017
Messages
73
Reaction score
0
They are variables its used in coding to store some values instead of writing them in and using them later.
 

Rockie

New member
Joined
Aug 18, 2017
Messages
4
Reaction score
0
So what is this 1@ doing here?
0AD4: 1@ = scan_string 0@ format "%d" 2@
 

bladero

Active member
Joined
Jan 3, 2017
Messages
73
Reaction score
0
I think its some result of the string scanning its not used and i just make public variable with $ and call it like empty or not used something like that.
 
Top