SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 01/10/2016, 02:58 PM   #1
Eoussama
Gangsta
 
Eoussama's Avatar
 
Join Date: Jul 2016
Location: Kingdom of Morocco // Tangier
Posts: 803
Reputation: 109
Post /cuff and /uncuff Tutorial (sscanf)+(ZCMD)

Howdy, so guys this is my first tutorial here, Hope you guys enjoy,
Today I'm going to show you, in brief, how to make a very simple and accurate /cuff or /uncuff system
NOTE: I'm not going to disable the player's controllability when cuffed, It will just tie his the target's hands so he won't fire a gun
before you do anything, make sure you have sscanf2 and ZCMD available in your script folder,
if you don't have there, you can download them from here,

first of all, underneath #include <a_samp> include the zcmd and sscanf2 includes, so it would look like this
Code:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
After that, add a boolean to help you define whether the target is cuffed or not, name it whatever you see fit, for the sake of this tutorial Imma do it like the following
Code:
new bool:IsCuffed[MAX_PLAYERS];
by default, this boolean is set to false, so we need to declare which conditions that would turn it true
before we do that, we need to make sure that players won't get Cuffed automatically when they log-in, so we need to go under OnPlayerConnect Callback and set the previous boolean to false
Code:
public OnPlayerConnect(playerid)
{
      IsCuffed[playerid] = false;
      return 1;
}
that should do,
Before we start working on Commands, make sure that you already have a class system containing different classes, for example, "LSPD and Robbers/Gangsters..." and this is mandatory considering the fact that logically only cops can perform this action(cuff/uncuff)
so once you make your class system, (for this tutorial I'm using // LSPD referring to cops // and // GANG referring to outlawed persons), which means, I would have two new variables defined on my script
Code:
#define LSPD 0
#define GANG 1
Next start making the commands,

so in the first line, declare the cuff command

Code:
CMD:cuff(playerid, params[])
{
      // do something here
      return 1;
}
This creates the command, but it has no functionality yet,
so after the player enters the command, the server would check if that player is in LSPD class, then execute the command, but if he's not in LSPD class, the server would display an error, It would look like the following
Code:
CMD:cuff(playerid, params[])
{
      if(gTeam[playerid] == LSPD)
      {
            // do something here
            return 1;
      }
      else if(gTeam[playerid] != LSPD)
      {
            SendClientMessage(playerid, 0xFF0000, "[ERROR]: Only cops and use this command!");
            return 1;
      }
      return 1;
}
Ok, now we gave the permission for only LSPD member to use that command,
next, let's define the target id(the person whom we're going to cuff) and make it as if the player doesn't enter the params(if he only typed /cuff without typing any ID), the server would give him an Error
Code:
CMD:cuff(playerid, params[])
{
      if(gTeam[playerid] == LSPD)
      {
            new targetid;
            if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, 0xFF00FF, "USAGE: /cuff (PlayerID)");
            return 1;
      }
      else if(gTeam[playerid] != LSPD)
      {
            SendClientMessage(playerid, 0xFF0000, "[ERROR]: Only cops and use this command!");
            return 1;
      }
      return 1;
}
The "u" stands for the target's ID parameter,

next, let's and see if that player is online or not,
Code:
CMD:cuff(playerid, params[])
{
      if(gTeam[playerid] == LSPD)
      {
            new targetid;
            if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, 0xFF00FF, "USAGE: /cuff (PlayerID)");
             if(IsPlayerConnected(targetid))
            {
                   // do something here
                   return 1;
            }
            else if(!IsPlayerConnected(targetid))
           {
                   SendClientMessage(playerid, 0xFF0000, "[ERROR]: Invalid ID!");
                   return 1!
           }
            return 1;
      }
      else if(gTeam[playerid] != LSPD)
      {
            SendClientMessage(playerid, 0xFF0000, "[ERROR]: Only cops and use this command!");
            return 1;
      }
      return 1;
}
Ok here is a problem, if we don't add any other conditions, and just executed the command, the target would be cuffed whatever the distance between the player and the target is, so let's limit the use of this in a specific distance,
Code:
CMD:cuff(playerid, params[])
{
      if(gTeam[playerid] == LSPD)
      {
            new targetid;
            if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, 0xFF00FF, "USAGE: /cuff (PlayerID)");
             if(IsPlayerConnected(targetid))
            {
                   new Float:x, Float:y, Float:z;
                   GetPlayerPos(targetid, x, y, z);
                   if(IsPlayerInRangeOfPoint(playerid, 5, x, y, z))
                   {
                          // do something here
                          return 1;
                   }
                   else if(!IsPlayerInRangeOfPoint(playerid, 5, x, y, z))
                   {
                          SendClientMessage(playerid, 0xFF0000, "[ERROR]: That player is too far away from you!");
                          return 1;
                   }
                   return 1;
            }
            else if(!IsPlayerConnected(targetid))
           {
                   SendClientMessage(playerid, 0xFF0000, "[ERROR]: Invalid ID!");
                   return 1!
           }
            return 1;
      }
      else if(gTeam[playerid] != LSPD)
      {
            SendClientMessage(playerid, 0xFF0000, "[ERROR]: Only cops and use this command!");
            return 1;
      }
      return 1;
}
So the last part was all about the distance between the two players, so I created 3 floats "x, y, z" then I assigned them to the target's position, after that I used them to specify the position of the limit distance range between the player and the target,
and now, we need to check if the target belongs to the LSPD class himself too, so he won't be cuffed, (it makes sense actually )
Code:
CMD:cuff(playerid, params[])
{
      if(gTeam[playerid] == LSPD)
      {
            new targetid;
            if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, 0xFF00FF, "USAGE: /cuff (PlayerID)");
             if(IsPlayerConnected(targetid))
            {
                   new Float:x, Float:y, Float:z;
                   GetPlayerPos(targetid, x, y, z);
                   if(IsPlayerInRangeOfPoint(playerid, 5, x, y, z))
                   {
                          if(gTeam[playerid] != LSPD)
                          {
                                 // do something here
                                 return 1;
                          }
                          else if(gTeam[playerid] == LSPD)
                          {
                                  SendClientMessage(playerid, 0xFF0000, "[ERROR]: you can't cuff a law enforcer!");
                                  return 1;
                          {
                          return 1;
                   }
                   else if(!IsPlayerInRangeOfPoint(playerid, 5, x, y, z))
                   {
                          SendClientMessage(playerid, 0xFF0000, "[ERROR]: That player is too far away from you!");
                          return 1;
                   }
                   return 1;
            }
            else if(!IsPlayerConnected(targetid))
           {
                   SendClientMessage(playerid, 0xFF0000, "[ERROR]: Invalid ID!");
                   return 1!
           }
            return 1;
      }
      else if(gTeam[playerid] != LSPD)
      {
            SendClientMessage(playerid, 0xFF0000, "[ERROR]: Only cops and use this command!");
            return 1;
      }
      return 1;
}
So what we've done so far is, making it impossible to cuff an LSPD member, so the "gTeam[playerid] != LSPD"
checks if the target is NOT a LSPD member, then if it's true, the command will execute, but if it's false(which's declared on gTeam[playerid] == LSPD) the command would give an error message,

and now, the last step before executing the command, is to check if the target is already cuffed or not,
Code:
CMD:cuff(playerid, params[])
{
      if(gTeam[playerid] == LSPD)
      {
            new targetid;
            if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, 0xFF00FF, "USAGE: /cuff (PlayerID)");
             if(IsPlayerConnected(targetid))
            {
                   new Float:x, Float:y, Float:z;
                   GetPlayerPos(targetid, x, y, z);
                   if(IsPlayerInRangeOfPoint(playerid, 5, x, y, z))
                   {
                          if(gTeam[playerid] != LSPD)
                          {
                                 if(IsCuffed == false)
                                 {
                                        // do something here
                                        return 1;
                                 }
                                 else if(IsCuffed[targetid] == true)
                                 {
                                        SendClientMessage(playerid, 0xFF0000, "[ERROR]: This player is already cuffed!");
                                        return 1;
                                 }                            
                                 return 1;
                          }
                          else if(gTeam[playerid] == LSPD)
                          {
                                  SendClientMessage(playerid, 0xFF0000, "[ERROR]: you can't cuff a law enforcer!");
                                  return 1;
                          {
                          return 1;
                   }
                   else if(!IsPlayerInRangeOfPoint(playerid, 5, x, y, z))
                   {
                          SendClientMessage(playerid, 0xFF0000, "[ERROR]: That player is too far away from you!");
                          return 1;
                   }
                   return 1;
            }
            else if(!IsPlayerConnected(targetid))
           {
                   SendClientMessage(playerid, 0xFF0000, "[ERROR]: Invalid ID!");
                   return 1!
           }
            return 1;
      }
      else if(gTeam[playerid] != LSPD)
      {
            SendClientMessage(playerid, 0xFF0000, "[ERROR]: Only cops and use this command!");
            return 1;
      }
      return 1;
}
and here we have made use of that boolean which we've created at the beginning, so we made it as if the target is cuffed already, the command would fail and give an error message, but in case the target isn't cuffed, the command would execute just fine,
and now, let's add some functionality to the command,
Code:
CMD:cuff(playerid, params[])
{
      if(gTeam[playerid] == LSPD)
      {
            new targetid;
            if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, 0xFF00FF, "USAGE: /cuff (PlayerID)");
             if(IsPlayerConnected(targetid))
            {
                   new Float:x, Float:y, Float:z;
                   GetPlayerPos(targetid, x, y, z);
                   if(IsPlayerInRangeOfPoint(playerid, 5, x, y, z))
                   {
                          if(gTeam[playerid] != LSPD)
                          {
                                 if(IsCuffed[targetid] == false)
                                 {
                                        new string[64+MAX_PLAYER_NAME]
                                        new targetname[MAX_PLAYER_NAME]
                                        new playername[MAX_PLAYER_NAME]
                                        GetPlayerName(playerid, playername, sizeof(playername)
                                        format(string, sizeof(string), "You have been cuffed by officer %s",playername));
                                        SendClientMessage(targetid, 0x0000FF, string);
                                        GetPlayerName(targetid, targetname, sizeof(targetname))
                                        format(string, sizeof(string), "You have cuffed %s ", targetname))
                                        SendClientMessage(playerid, 0xCCFF00, string));                                      SetPlayerAttachedObject(targetid,8,19418,6,-0.031999,0.024000,-0.024000,-7.900000,-32.000011,-72.299987,1.115998,1.322000,1.406000);
    	 				SetPlayerSpecialAction(targetid, SPECIAL_ACTION_CUFFED);
                                        IsCuffed = true;
                                        return 1;
                                 }
                                 else if(IsCuffed == true)
                                 {
                                        SendClientMessage(playerid, 0xFF0000, "[ERROR]: This player is already cuffed!");
                                        return 1;
                                 }                            
                                 return 1;
                          }
                          else if(gTeam[playerid] == LSPD)
                          {
                                  SendClientMessage(playerid, 0xFF0000, "[ERROR]: you can't cuff a law enforcer!");
                                  return 1;
                          {
                          return 1;
                   }
                   else if(!IsPlayerInRangeOfPoint(playerid, 5, x, y, z))
                   {
                          SendClientMessage(playerid, 0xFF0000, "[ERROR]: That player is too far away from you!");
                          return 1;
                   }
                   return 1;
            }
            else if(!IsPlayerConnected(targetid))
           {
                   SendClientMessage(playerid, 0xFF0000, "[ERROR]: Invalid ID!");
                   return 1!
           }
            return 1;
      }
      else if(gTeam[playerid] != LSPD)
      {
            SendClientMessage(playerid, 0xFF0000, "[ERROR]: Only cops and use this command!");
            return 1;
      }
      return 1;
}
so basically, we have set the target's animation to SPECIAL_ACTION_CUFFED which makes him unable to shoot with a gun, and to make it more realistic we attached a cuffs object to his hands,

I want you to make attention to this, I stated on the command lines, this "IsCuffed = true;" that part looked very casual, but it holds a very important value for the command to work properly, so as in the beginning I set the the boolean's value to false whenever someone connects to the server, and when this command is used on him, the boolean would be turned to true, this part is very mandatory for the uncuff command as well,
So, to make the uncuff command, It's pretty much the same, just do everything exactly as the cuff command, but you have to change some parts, exactly like the following
Code:
CMD:uncuff(playerid, params[])
{
      if(gTeam[playerid] == LSPD)
      {
            new targetid;
            if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, 0xFF00FF, "USAGE: /uncuff (PlayerID)");
             if(IsPlayerConnected(targetid))
            {
                   new Float:x, Float:y, Float:z;
                   GetPlayerPos(targetid, x, y, z);
                   if(IsPlayerInRangeOfPoint(playerid, 5, x, y, z))
                   {
                          if(gTeam[playerid] != LSPD)
                          {
                                 if(IsCuffed[targetid] == true)
                                 {
                                        new string[64+MAX_PLAYER_NAME]
                                        new targetname[MAX_PLAYER_NAME]
                                        new playername[MAX_PLAYER_NAME]
                                        GetPlayerName(playerid, playername, sizeof(playername)
                                        format(string, sizeof(string), "You have been uncuffed by officer %s",playername));
                                        SendClientMessage(targetid, 0x0000FF, string);
                                        GetPlayerName(targetid, targetname, sizeof(targetname))
                                        format(string, sizeof(string), "You have uncuffed %s ", targetname))
                                        SendClientMessage(playerid, 0xCCFF00, string));
                                        if(IsPlayerAttachedObjectSlotUsed(targetid, 8)) 
                                        {
				                 RemovePlayerAttachedObject(targetid, 8);
                                                 return 1;
					}
			         	SetPlayerSpecialAction(targetid, SPECIAL_ACTION_NONE);
                                        IsCuffed = false;
                                        return 1;
                                 }
                                 else if(IsCuffed == true)
                                 {
                                        SendClientMessage(playerid, 0xFF0000, "[ERROR]: This player is not cuffed!");
                                        return 1;
                                 }                            
                                 return 1;
                          }
                          else if(gTeam[playerid] == LSPD)
                          {
                                  SendClientMessage(playerid, 0xFF0000, "[ERROR]: you can't use this on a law enforcer!");
                                  return 1;
                          {
                          return 1;
                   }
                   else if(!IsPlayerInRangeOfPoint(playerid, 5, x, y, z))
                   {
                          SendClientMessage(playerid, 0xFF0000, "[ERROR]: That player is too far away from you!");
                          return 1;
                   }
                   return 1;
            }
            else if(!IsPlayerConnected(targetid))
           {
                   SendClientMessage(playerid, 0xFF0000, "[ERROR]: Invalid ID!");
                   return 1!
           }
            return 1;
      }
      else if(gTeam[playerid] != LSPD)
      {
            SendClientMessage(playerid, 0xFF0000, "[ERROR]: Only cops and use this command!");
            return 1;
      }
      return 1;
}
Ok, those parts that must be changed from the uncuff command are few, I highlighted them in green to label them so you can notice them clearly, but the reason why labeled "IsCuffed = false" with a different color, is to emphasise how important it is to do that is the right place, also, the orange parts must remain as they are, so the command would work smoothly and as it should,


so that was it, I hope you guys found this very helpful, and caught your eyes, if I had suppoort and possitive responds, I would make more tutorials in the very soon,
stay smiley stay happy, and hoipe for the best, so long

Last edited by Eoussama; 08/12/2016 at 10:21 AM.
Eoussama is online now   Reply With Quote
Old 01/10/2016, 03:11 PM   #2
Kruno88
Huge Clucker
 
Kruno88's Avatar
 
Join Date: Apr 2014
Posts: 349
Reputation: 56
Default Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD)

Nice tutorial,wish it was here when I was scripting a CnR script

+1.
Kruno88 is offline   Reply With Quote
Old 01/10/2016, 03:14 PM   #3
SyS
High-roller
 
SyS's Avatar
 
Join Date: Oct 2015
Posts: 1,973
Reputation: 419
Default Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD)

Code:
else if(gTeam[playerid] == LSPD)
                          {
                                  SendClientMessage(playerid, 0xFF0000, "[ERROR]: you can't use this on a law enforcer!");
                                  return 1;
                          {
                          return 1;
Code:
 else if(!IsPlayerConnected(targetid))
           {
                   SendClientMessage(playerid, 0xFF0000, "[ERROR]: Invalid ID!");
                   return 1!
           }
fix that ^^ i didnt look much ahead and i wont raise hand to much use of else if s
__________________

SyS is online now   Reply With Quote
Old 01/10/2016, 03:53 PM   #4
AndySedeyn
High-roller
 
AndySedeyn's Avatar
 
Join Date: Feb 2014
Location: Belgium
Posts: 1,346
Reputation: 681
Default Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD)

Quote:
Originally Posted by Sreyas View Post
Code:
else if(gTeam[playerid] == LSPD)
                          {
                                  SendClientMessage(playerid, 0xFF0000, "[ERROR]: you can't use this on a law enforcer!");
                                  return 1;
                          {
                          return 1;
Code:
 else if(!IsPlayerConnected(targetid))
           {
                   SendClientMessage(playerid, 0xFF0000, "[ERROR]: Invalid ID!");
                   return 1!
           }
fix that ^^ i didnt look much ahead and i wont raise hand to much use of else if s
While I usually don't complain about the excessive use of unnecessary else if statements, I do get annoyed by it. A lot of people find it reasonable to use them in a situation where the given condition can only be maximum two states and thus making an else if statement pointless and may even become "ineffective":
PHP Code:
if(IsPlayerConnected(playerid))
{
    
// Some code ...
}
else
{
    if(!
IsPlayerConnected(playerid))
    {
        
// Some other code ...
    
}

Given that, it seems like the OP has a bad habit of doing just that. I see the following reoccur more than a few times throughout the tutorial:
PHP Code:
if(IsPlayerConnected(playerid))
{
    
// Some code ...
    
return 1;
}
else if(!
IsPlayerConnected(playerid))
{
    
// Some other code ...
    
return 1;

A player is either connected or not. In this case, a simple else statement is the best way to go.

To drop the whole else statement altogether, the function would have to return a value in the if statement above that:
PHP Code:
if(condition)
{
    
// Some code...
    
return someValue;
}
// Code under this if statement is automatically the else statement, that is without explicitely using the else keyword.
return someOtherValue
Not explicitly using the else statement may reduce readability for programmers who are used to using it in such cases. I tend to not use it, but I'm fine with either.

Here's another mistake I came across:
Quote:
Originally Posted by Eoussama View Post
PHP Code:
if(IsCuffed == true)
{
    return 
1;
}
else if(
IsCuffed == true)
{
    return 
1;

EDIT: Your boolean variable 'isCuffed' will only work when nobody is cuffed. Once 1 player on the server is cuffed, nobody else can get cuffed.
AndySedeyn is offline   Reply With Quote
Old 01/10/2016, 04:11 PM   #5
Eoussama
Gangsta
 
Eoussama's Avatar
 
Join Date: Jul 2016
Location: Kingdom of Morocco // Tangier
Posts: 803
Reputation: 109
Default Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD)

Quote:
Originally Posted by AndySedeyn View Post
While I usually don't complain about the excessive use of unnecessary else if statements, I do get annoyed by it. A lot of people find it reasonable to use them in a situation where the given condition can only be maximum two states and thus making an else if statement pointless and may even become "ineffective":
PHP Code:
if(IsPlayerConnected(playerid))
{
    
// Some code ...
}
else
{
    if(!
IsPlayerConnected(playerid))
    {
        
// Some other code ...
    
}

Given that, it seems like the OP has a bad habit of doing just that. I see the following reoccur more than a few times throughout the tutorial:
PHP Code:
if(IsPlayerConnected(playerid))
{
    
// Some code ...
    
return 1;
}
else if(!
IsPlayerConnected(playerid))
{
    
// Some other code ...
    
return 1;

A player is either connected or not. In this case, a simple else statement is the best way to go.

To drop the whole else statement altogether, the function would have to return a value in the if statement above that:
PHP Code:
if(condition)
{
    
// Some code...
    
return someValue;
}
// Code under this if statement is automatically the else statement, that is without explicitely using the else keyword.
return someOtherValue
Not explicitly using the else statement may reduce readability for programmers who are used to using it in such cases. I tend to not use it, but I'm fine with either.

Here's another mistake I came across:


EDIT: Your boolean variable 'isCuffed' will only work when nobody is cuffed. Once 1 player on the server is cuffed, nobody else can get cuffed.
OMG thank you, I actually admire replies like that, where people criticise my work so I can improve,

thanks all for the feedbacks, this is my first tuto, so It's normal

Last edited by Eoussama; 08/12/2016 at 10:23 AM.
Eoussama is online now   Reply With Quote
Old 08/12/2016, 10:24 AM   #6
Eoussama
Gangsta
 
Eoussama's Avatar
 
Join Date: Jul 2016
Location: Kingdom of Morocco // Tangier
Posts: 803
Reputation: 109
Default Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD)

Tutorial updated, fixed some minor mistakes
Eoussama is online now   Reply With Quote
Old 08/12/2016, 06:22 PM   #7
RIDE2DAY
Big Clucker
 
RIDE2DAY's Avatar
 
Join Date: Jul 2015
Location: Italy
Posts: 179
Reputation: 166
Default Respuesta: /cuff and /uncuff Tutorial (sscanf)+(ZCMD)

This might help.
RIDE2DAY is offline   Reply With Quote
Old 09/12/2016, 12:12 AM   #8
Dayrion
High-roller
 
Dayrion's Avatar
 
Join Date: Jan 2016
Posts: 1,332
Reputation: 106
Default Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD)

There is some errors plus I don't like at all (it's personal) a code which is interlinked.
PHP Code:
CMD:uncuff(playeridparams[])
{
    if(
gTeam[playerid] != LSPD)
        return 
SendClientMessage(playerid0xFF0000"[ERROR]: Only cops and use this command!");

    new 
targetid// To store the player id which is the target.
    
if(sscanf(params"u"targetid))
        return 
SendClientMessage(playerid0xFF00FF"USAGE: /uncuff (PlayerID)"); // Store an ID (or INVALID_PLAYER_id if the playerid is wrong)

    
if(!IsPlayerConnected(targetid)) // The player is NOT ('!' mean NOT) connected so we return an error message
        
return SendClientMessage(playerid0xFF0000"[ERROR]: Invalid ID!");

    new 
// 3 variables to store x, y, z, target's coord. 
        
Float:x,
        
Float:y,
        
Float:z;

    
GetPlayerPos(targetidxyz); // Get these coord'
    
if(!IsPlayerInRangeOfPoint(playerid5xyz)) // Check if the player is in the range of the target.
        
return SendClientMessage(playerid0xFF0000"[ERROR]: That player is too far away from you!");

    if(
gTeam[targetid] == LSPD// if the target is law enforcer
        
return SendClientMessage(playerid0xFF0000"[ERROR]: you can't use this on a law enforcer!");

    if(!
IsCuffed[targetid]) // if the player is NOT cuffed so we can't uncuff him
        
return SendClientMessage(playerid0xFF0000"[ERROR]: This player is not cuffed!");

    new
        
string[35+MAX_PLAYER_NAME],     // the string to send a message
        
targetname[MAX_PLAYER_NAME],    // string to store the target's name
        
playername[MAX_PLAYER_NAME];    // string to store the player's name

    
GetPlayerName(playeridplayernamesizeof(playername); // Store the player name
    
format(stringsizeof(string), "You have been uncuffed by officer %s"playername)); // Send a formated message which %s is remplaced by player's name
    
SendClientMessage(targetid0x0000FFstring);

    
GetPlayerName(targetidtargetnamesizeof(targetname));
    
format(stringsizeof(string), "You have uncuffed %s "targetname))
    
SendClientMessage(playerid0xCCFF00string));

    if(
IsPlayerAttachedObjectSlotUsed(targetid8)) // If the player have an object (handcuff) » we check it
        
RemovePlayerAttachedObject(targetid8); // So remove the object

    
SetPlayerSpecialAction(targetidSPECIAL_ACTION_NONE); // Remove any special action
    
IsCuffed false;
    
    return 
1;

Dayrion is offline   Reply With Quote
Old 31/12/2016, 10:36 AM   #9
XxFiGhteRXx
Little Clucker
 
Join Date: Dec 2016
Location: Grave
Posts: 13
Reputation: 0
Default Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD)

nice i need it
XxFiGhteRXx is offline   Reply With Quote
Old 31/12/2016, 10:51 AM   #10
Stinged
High-roller
 
Join Date: Feb 2013
Posts: 1,604
Reputation: 187
Default Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD)

Quote:
Originally Posted by Dayrion View Post
There is some errors plus I don't like at all (it's personal) a code which is interlinked.
PHP Code:
CMD:uncuff(playeridparams[])
{
    if(
gTeam[playerid] != LSPD)
        return 
SendClientMessage(playerid0xFF0000"[ERROR]: Only cops and use this command!");

    new 
targetid// To store the player id which is the target.
    
if(sscanf(params"u"targetid))
        return 
SendClientMessage(playerid0xFF00FF"USAGE: /uncuff (PlayerID)"); // Store an ID (or INVALID_PLAYER_id if the playerid is wrong)

    
if(!IsPlayerConnected(targetid)) // The player is NOT ('!' mean NOT) connected so we return an error message
        
return SendClientMessage(playerid0xFF0000"[ERROR]: Invalid ID!");

    new 
// 3 variables to store x, y, z, target's coord. 
        
Float:x,
        
Float:y,
        
Float:z;

    
GetPlayerPos(targetidxyz); // Get these coord'
    
if(!IsPlayerInRangeOfPoint(playerid5xyz)) // Check if the player is in the range of the target.
        
return SendClientMessage(playerid0xFF0000"[ERROR]: That player is too far away from you!");

    if(
gTeam[targetid] == LSPD// if the target is law enforcer
        
return SendClientMessage(playerid0xFF0000"[ERROR]: you can't use this on a law enforcer!");

    if(!
IsCuffed[targetid]) // if the player is NOT cuffed so we can't uncuff him
        
return SendClientMessage(playerid0xFF0000"[ERROR]: This player is not cuffed!");

    new
        
string[35+MAX_PLAYER_NAME],     // the string to send a message
        
targetname[MAX_PLAYER_NAME],    // string to store the target's name
        
playername[MAX_PLAYER_NAME];    // string to store the player's name

    
GetPlayerName(playeridplayernamesizeof(playername); // Store the player name
    
format(stringsizeof(string), "You have been uncuffed by officer %s"playername)); // Send a formated message which %s is remplaced by player's name
    
SendClientMessage(targetid0x0000FFstring);

    
GetPlayerName(targetidtargetnamesizeof(targetname));
    
format(stringsizeof(string), "You have uncuffed %s "targetname))
    
SendClientMessage(playerid0xCCFF00string));

    if(
IsPlayerAttachedObjectSlotUsed(targetid8)) // If the player have an object (handcuff) » we check it
        
RemovePlayerAttachedObject(targetid8); // So remove the object

    
SetPlayerSpecialAction(targetidSPECIAL_ACTION_NONE); // Remove any special action
    
IsCuffed false;
    
    return 
1;

Here's an even better version: (Plus some mistakes were fixes)
PHP Code:
CMD:uncuff(playeridparams[])
{
    if(
gTeam[playerid] != LSPD)
        return 
SendClientMessage(playerid0xFF0000FF"[ERROR]: Only cops and use this command!");

    new 
targetid;
    if(
sscanf(params"u"targetid))
        return 
SendClientMessage(playerid0xFF00FFFF"USAGE: /uncuff (PlayerID)");

    if (
targetid == INVALID_PLAYER_ID// No need to call IsPlayerConnected
        
return SendClientMessage(playerid0xFF0000FF"[ERROR]: Invalid ID!");

    new
        
Float:x,
        
Float:y,
        
Float:z;

    
GetPlayerPos(targetidxyz);
    if(!
IsPlayerInRangeOfPoint(playerid5xyz))
        return 
SendClientMessage(playerid0xFF0000FF"[ERROR]: That player is too far away from you!");

    if(
gTeam[targetid] == LSPD)
        return 
SendClientMessage(playerid0xFF0000FF"[ERROR]: you can't use this on a law enforcer!");

    if(
IsCuffed[targetid] == false)
        return 
SendClientMessage(playerid0xFF0000FF"[ERROR]: This player is not cuffed!");

    new
        
string[59]; // One string is enough, you can just reuse it.

    
GetPlayerName(playeridstring25);
    
format(stringsizeof (string), "You have been uncuffed by officer %s"string);
    
SendClientMessage(targetid0x0000FFFFstring);

    
GetPlayerName(targetidstring25);
    
format(stringsizeof (string), "You have uncuffed %s"string);
    
SendClientMessage(playerid0xCCFF00FFstring));

    
// No need to check if slot8 is used. If it is, it will remove the object, if it's not, the native will fail
    
RemovePlayerAttachedObject(targetid8);

    
SetPlayerSpecialAction(targetidSPECIAL_ACTION_NONE);
    
IsCuffed[targetid] = false// You didn't add [targetid]
    
return 1;

Eoussama, fix your colours.
You're not including the alpha (0xRRGGBBAA).
Yes, it's not used for anything in SendClientMessage, but if you don't put something there, 00 will be added to the left. Which makes it a completely different number.

0xFF0000 = 0x00FF0000 = Green
0xFF000000 = Red
Stinged 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
need help with cuff and uncuff cmd with sscanf+zcmd. mittukuttan Scripting Help 1 31/01/2013 02:06 PM
Cuff si uncuff IuLyAnBoSs Romānă/Romanian 10 04/07/2012 12:32 PM
Cuff/Uncuff striker25 Help Archive 47 17/07/2010 02:23 AM
Cuff/Uncuff ScottCFR Help Archive 6 19/03/2010 03:42 PM


All times are GMT. The time now is 04:18 PM.


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