SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 24/08/2012, 07:54 PM   #1
TaLhA XIV
Gangsta
 
TaLhA XIV's Avatar
 
Join Date: May 2012
Posts: 508
Reputation: 19
Default How to make a /cuff and /uncuff command.

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

Okay first:
Include these files.
PHP Code:
#include <a_samp>
#include <zcmd>
#include <sscanf2> 
Okay now here are the full codes and I have explained them in the script:
PHP Code:
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 Code:
if(sscanf(params"u"targetid)) return SendClientMessage(playerid, -1"[USAGE]: /uncuff [Part of Name/Player ID]"); 
for more info about sscanf,use this.:
http://forum.sa-mp.com/showthread.php?t=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 Code:
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:
http://wiki.sa-mp.com/wiki/Format
TaLhA XIV is offline   Reply With Quote
Old 24/08/2012, 07:56 PM   #2
Landon
Huge Clucker
 
Join Date: Apr 2007
Posts: 448
Reputation: 107
Default Re: How to make a /cuff and /uncuff command.

Nice tut mate
__________________
Aswell known as David Landon

Landon is offline   Reply With Quote
Old 24/08/2012, 08:05 PM   #3
MoDee
Little Clucker
 
Join Date: Feb 2011
Posts: 36
Reputation: 0
Default Re: How to make a /cuff and /uncuff command.

Thanks mate
MoDee is offline   Reply With Quote
Old 24/08/2012, 08:27 PM   #4
TaLhA XIV
Gangsta
 
TaLhA XIV's Avatar
 
Join Date: May 2012
Posts: 508
Reputation: 19
Default Re: How to make a /cuff and /uncuff command.

Quote:
Originally Posted by Michael23 View Post
Nice tut mate
Thanks

Quote:
Originally Posted by MoDee View Post
Thanks mate
Thanks
TaLhA XIV is offline   Reply With Quote
Old 24/08/2012, 08:28 PM   #5
Mellnik
Gangsta
 
Mellnik's Avatar
 
Join Date: Dec 2011
Location: Paradise Falls, Canada
Posts: 627
Reputation: 232
Default AW: How to make a /cuff and /uncuff command.

nice tut, but change "u" to "r" by sscanf or do you want that bots can be cuffed^^
__________________
samp.nef.gs:7777 NEF, Freeroam
Mellnik is offline   Reply With Quote
Old 24/08/2012, 09:25 PM   #6
TaLhA XIV
Gangsta
 
TaLhA XIV's Avatar
 
Join Date: May 2012
Posts: 508
Reputation: 19
Default Re: AW: How to make a /cuff and /uncuff command.

Quote:
Originally Posted by Mellnik View Post
nice tut, but change "u" to "r" by sscanf or do you want that bots can be cuffed^^
nah avoid that.
TaLhA XIV is offline   Reply With Quote
Old 05/09/2012, 04:08 AM   #7
Jack_Leslie
High-roller
 
Jack_Leslie's Avatar
 
Join Date: Feb 2011
Location: Australia
Posts: 1,122
Reputation: 92
Default Re: How to make a /cuff and /uncuff command.

Instead of checking if the player has the object attached to them, I recommend you checking if their special action is cuffed, much more efficient in my opinion.
__________________
If you want to help people; don't be fucking lazy, explain what they did wrong, show them what they did wrong, and fix the error for them.
Jack_Leslie is offline   Reply With Quote
Old 05/09/2012, 05:03 AM   #8
[ABK]Antonio
High-roller
 
[ABK]Antonio's Avatar
 
Join Date: Sep 2011
Location: ID, USA
Posts: 1,173
Reputation: 163
Default Re: How to make a /cuff and /uncuff command.

Quote:
Originally Posted by TaLhA XIV View Post
pawn Code:
CMD:cuff(playerid, params[])//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:x, Float:y, Float:z;//these are the defines of your x,y and z position.
            GetPlayerPos(playerid, x, y, z);//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(targetid, 5.0, x, y, z))//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(playerid, name, sizeof(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(targetid, target, sizeof(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(str, sizeof(str), "INFO: You have cuffed %s!",target);//explained at the end of the tutorial.
                    SendClientMessage(playerid, 0xE01B1B, str);//this will send the formated message to you that you created before.
                    format(str, sizeof(str), "WARNING: You have been cuffed by %s!",name);//explained at the end of the tutorial.
                    SendClientMessage(targetid, 0xE01B1B, str);//this will send the formated message to the player you cuffed.
                    SetPlayerAttachedObject(targetid, 0, 19418, 6, -0.011000, 0.028000, -0.022000, -15.600012, -33.699977,-81.700035, 0.891999, 1.000000, 1.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;
}
Why 512 cells when we only need around 50-60?
Why two name variables when you only need one?
Why return after the special action when there's nothing else in the command and it would just return down the line?
__________________
ABKClan.com
[ABK]Antonio is offline   Reply With Quote
Old 05/09/2012, 10:59 AM   #9
TaLhA XIV
Gangsta
 
TaLhA XIV's Avatar
 
Join Date: May 2012
Posts: 508
Reputation: 19
Default Re: How to make a /cuff and /uncuff command.

Wowow thanks for the suggestions but I did not tested it so thanks for that.
TaLhA XIV is offline   Reply With Quote
Old 05/09/2012, 01:21 PM   #10
David (Sabljak)
Big Clucker
 
Join Date: Nov 2011
Posts: 176
Reputation: 7
Default Re: How to make a /cuff and /uncuff command.

Great Tutorial! Thanks

But ... maybe add this?

uncuff

RemovePlayerAttachedObject(playerid, 0);

and

When cuffed, you jump and fall

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys & KEY_JUMP && !(oldkeys & KEY_JUMP) && GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_CUFFED) ApplyAnimation(playerid, "GYMNASIUM", "gym_jog_falloff",4.1,0,1,1,0,0);
return 1;
}
David (Sabljak) is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cuff/Uncuff striker25 Help Archive 47 17/07/2010 02:23 AM
Cuff/Uncuff ScottCFR Help Archive 6 19/03/2010 03:42 PM
Help With Cuff and Uncuff Command hector_williams Help Archive 6 17/03/2010 02:24 AM
I need a /cuff and /uncuff command killdahobo99 Help Archive 45 28/07/2009 02:11 PM


All times are GMT. The time now is 11:41 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.