[Tutorial] How to make a /cuff and /uncuff command.
#1

Okay in this tutorial you will learn that how to make a /cuff and a /uncuff command.

Okay first:
Include these files.
PHP код:
#include <a_samp>
#include <zcmd>
#include <sscanf2> 
Okay now here are the full codes and I have explained them in the script:
PHP код:
CMD:cuff(playeridparams[])//This is will create you cmd so you can continue your codes.
{
    new 
targetid;//this defines the id of the player you want to cuff((playerid id your id and the target id that I defined it the id of the player you want to cuff))
    
if(sscanf(params"u"targetid)) return SendClientMessage(playerid, -1"[USAGE]: /cuff [Part of Name/Player ID]");
    if(
IsPlayerConnected(targetid))//this will check that if the player you want to cuff is connected to the server or not.
        
{
            new 
Float:xFloat:yFloat:z;//these are the defines of your x,y and z position.
               
GetPlayerPos(playeridxyz);//this will store your position to be used in the following codes.((this stores the your x,y, and z position in to the variables we created.))
               
if(IsPlayerInRangeOfPoint(targetid5.0xyz))//this will check that if the player you want to cuff is near you or not.
                   
{
                    new 
str[512];//this it the define for the string you will format further.((str means string.You can also change it to string but this seems to be easy.))
                      
new name[MAX_PLAYER_NAME];//this is the variable you created to store the your name.
                    
GetPlayerName(playeridnamesizeof(name));//this will get your name and store it in the variable you defines as name.
                    
new target[MAX_PLAYER_NAME];//this is the variable you created to store the name of the player you want to cuff.
                       
GetPlayerName(targetidtargetsizeof(target));//this will get the name of the person you want to cuff and will store it into a variable we defined as target.
                       
format(strsizeof(str), "INFO: You have cuffed %s!",target);//explained at the end of the tutorial.
                       
SendClientMessage(playerid0xE01B1Bstr);//this will send the formated message to you that you created before.
                       
format(strsizeof(str), "WARNING: You have been cuffed by %s!",name);//explained at the end of the tutorial.
                       
SendClientMessage(targetid0xE01B1Bstr);//this will send the formated message to the player you cuffed.
                    
SetPlayerAttachedObject(targetid0194186, -0.0110000.028000, -0.022000, -15.600012, -33.699977,-81.7000350.8919991.0000001.168000);//this will set the object cuffs at the hand of the player you want to cuff.
                      
SetPlayerSpecialAction(targetid,SPECIAL_ACTION_CUFFED);//this will set players hand backwards.
                      
return 1;
                }
        }
    return 
1;
}
CMD:uncuff(playeridparams[])//sfcs cmd.
{
        new 
targetid;//this defines the id of the player you want to cuff((playerid id your id and the target id that I defined it the id of the player you want to cuff))
        
if(sscanf(params"u"targetid)) return SendClientMessage(playerid, -1"[USAGE]: /uncuff [Part of Name/Player ID]");
        if(
IsPlayerConnected(targetid))//this will check that if the player you want to cuff is connected to the server or not.
        
{
            new 
Float:xFloat:yFloat:z;//these are the defines of your x,y and z position.
               
GetPlayerPos(playeridxyz);//this will store your position to be used in the following codes.((this stores the your x,y, and z position in to the variables we created.))
               
if(IsPlayerInRangeOfPoint(targetid5.0xyz))//this will check that if the player you want to cuff is near you or not.
                   
{
                    if(!
SetPlayerAttachedObject(targetid0194186, -0.0110000.028000, -0.022000, -15.600012, -33.699977,-81.7000350.8919991.0000001.168000))return SendClientMessage(playerid,-1,"ERROR: The player is not cuffed!");//this will check that if the player is not cuffed and you are trying to apply this cmd,this will send him a error message.
                      
SetPlayerSpecialAction(targetid,SPECIAL_ACTION_NONE);//this will remove the players cuffs and his arms will go normal.
                    
new str[512];//this it the define for the string you will format further.((str means string.You can also change it to string but this seems to be easy.))
                      
new name[MAX_PLAYER_NAME];//this is the variable you created to store the your name.
                    
GetPlayerName(playeridnamesizeof(name));//this will get your name and store it in the variable you defines as name.
                    
new target[MAX_PLAYER_NAME];//this is the variable you created to store the name of the player you want to cuff.
                       
GetPlayerName(targetidtargetsizeof(target));//this will get the name of the person you want to cuff and will store it into a variable we defined as target.
                       
format(strsizeof(str), "INFO: You have uncuffed %s!",target);//explained at the end of the tutorial.
                       
SendClientMessage(playerid0xE01B1Bstr);//will send the formated message to you that you created above.
                       
format(strsizeof(str), "WARNING: You have been uncuffed by %s!",name);//explained bellow.
                       
SendClientMessage(targetid0xE01B1Bstr);//will send the formated message to the player you want to cuff that you created above.
                      
return 1;
                }
        }
        return 
1;

Now the lines I haven't explained in the script.
PHP код:
if(sscanf(params"u"targetid)) return SendClientMessage(playerid, -1"[USAGE]: /uncuff [Part of Name/Player ID]"); 
for more info about sscanf,use this.:
https://sampforum.blast.hk/showthread.php?tid=120356

This will check that if a player enter a invalid information,if it is a invalid information,it will send him an error message.

PHP код:
format(strsizeof(str), "INFO: You have cuffed %s!",target);//explained at the end of the tutorial. 
format is used for formatting messages that you want to send to other people or to yourself.
for more info go here:
https://sampwiki.blast.hk/wiki/Format
Reply


Messages In This Thread
How to make a /cuff and /uncuff command. - by TaLhA XIV - 24.08.2012, 19:54
Re: How to make a /cuff and /uncuff command. - by Landon - 24.08.2012, 19:56
Re: How to make a /cuff and /uncuff command. - by MoDee - 24.08.2012, 20:05
Re: How to make a /cuff and /uncuff command. - by TaLhA XIV - 24.08.2012, 20:27
AW: How to make a /cuff and /uncuff command. - by Mellnik - 24.08.2012, 20:28
Re: AW: How to make a /cuff and /uncuff command. - by TaLhA XIV - 24.08.2012, 21:25
Re: How to make a /cuff and /uncuff command. - by Jack_Leslie - 05.09.2012, 04:08
Re: How to make a /cuff and /uncuff command. - by [ABK]Antonio - 05.09.2012, 05:03
Re: How to make a /cuff and /uncuff command. - by TaLhA XIV - 05.09.2012, 10:59
Re: How to make a /cuff and /uncuff command. - by David (Sabljak) - 05.09.2012, 13:21
Re: How to make a /cuff and /uncuff command. - by TaLhA XIV - 05.09.2012, 13:25
Re: How to make a /cuff and /uncuff command. - by Uberanwar - 09.10.2012, 06:51
Re: How to make a /cuff and /uncuff command. - by Maniek - 09.10.2012, 07:11
Re: How to make a /cuff and /uncuff command. - by Pk93 - 17.07.2013, 00:10
Re: How to make a /cuff and /uncuff command. - by Lebo - 17.07.2013, 03:07
Re: How to make a /cuff and /uncuff command. - by NealPeteros - 04.01.2016, 12:51
Re: How to make a /cuff and /uncuff command. - by saffierr - 04.01.2016, 13:09
Re: How to make a /cuff and /uncuff command. - by NealPeteros - 04.01.2016, 13:44
Re: How to make a /cuff and /uncuff command. - by NealPeteros - 05.01.2016, 10:29
Re: How to make a /cuff and /uncuff command. - by MicroKyrr - 06.01.2016, 03:21
Re: How to make a /cuff and /uncuff command. - by NealPeteros - 06.01.2016, 08:50
Re: How to make a /cuff and /uncuff command. - by NealPeteros - 06.01.2016, 09:00
Re: How to make a /cuff and /uncuff command. - by Joron - 20.01.2016, 02:01

Forum Jump:


Users browsing this thread: 2 Guest(s)