[Tutorial] /cuff and /uncuff Tutorial (sscanf)+(ZCMD)
#1

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
Reply
#2

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

+1.
Reply
#3

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
Reply
#4

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.
Reply
#5

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
Reply
#6

Tutorial updated, fixed some minor mistakes
Reply
#7

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;

Reply
#8

nice i need it
Reply
#9

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
Reply
#10

Where do I put the 'CMD:cuff' and 'CMD:uncuff' ?
Reply
#11

Quote:
Originally Posted by Triggerz
Посмотреть сообщение
Where do I put the 'CMD:cuff' and 'CMD:uncuff' ?
First of all you have to download ZCMD - include from here: https://sampforum.blast.hk/showthread.php?tid=91354

Then you have to include in your script:
PHP код:
#include <zcmd> 
to let COMMAND and CMD Works, if you didn't include zcmd.inc so it'd get errors.

by the way if you downloaded the zcmd and putted it in Pawno>includes>zcmd.inc folder so just include it in your script as i have gave an example up, then when you gonna make a command so it would be like that:


PHP код:
CMD:kill(playerid,params[])
{
       
SetPlayerHealth(playerid0.0);
       return 
1;

it's more easire than strcmp,

NOTE: You can use:
PHP код:
CMD:123(playerid,params[])
{
     
//do something here
     
return 1;
}
//And you can use COMMAD like this:
COMMAND:123(playerid,params[])
{
      
//do something here
      
return 1;

Hope that i helped you
Reply
#12

see here
https://sampforum.blast.hk/showthread.php?tid=618127
and add it in gm
Код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
Код:
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;
}
Код:
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;
}
Reply
#13

Quote:
Originally Posted by PaRking
Посмотреть сообщение
see here
https://sampforum.blast.hk/showthread.php?tid=618127
and add it in gm
Код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
Код:
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;
}
Код:
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;
}
Nice explaining sir
Reply
#14

he will not understand whit ur cmd: 123 -__________-
Reply
#15

Quote:
Originally Posted by PaRking
Посмотреть сообщение
he will not understand whit ur cmd: 123 -__________-
Why he wouldn't? he isn't a scripts copier like you

and it's With not wtih
Reply
#16

Quote:
Originally Posted by PaRking
Посмотреть сообщение
he will not understand whit ur cmd: 123 -__________-
tutorials are meant to be understood, not to copy code snippets from,
Reply
#17

Quote:
Originally Posted by PaRking
Посмотреть сообщение
he will not understand whit ur cmd: 123 -__________-
For your information I wasn't copying at all. I was just trying to learn from it. I was analyzing it and learning from it and how to use <zcmd> and sscanf.
Reply
#18

Quote:
Originally Posted by RyderX
Посмотреть сообщение
First of all you have to download ZCMD - include from here: https://sampforum.blast.hk/showthread.php?tid=91354

Then you have to include in your script:
PHP код:
#include <zcmd> 
to let COMMAND and CMD Works, if you didn't include zcmd.inc so it'd get errors.

by the way if you downloaded the zcmd and putted it in Pawno>includes>zcmd.inc folder so just include it in your script as i have gave an example up, then when you gonna make a command so it would be like that:


PHP код:
CMD:kill(playerid,params[])
{
       
SetPlayerHealth(playerid0.0);
       return 
1;

it's more easire than strcmp,

NOTE: You can use:
PHP код:
CMD:123(playerid,params[])
{
     
//do something here
     
return 1;
}
//And you can use COMMAD like this:
COMMAND:123(playerid,params[])
{
      
//do something here
      
return 1;

Hope that i helped you
thanks,

also, if I were to use 'IsPlayerAdmin' and else/if statements, how would I put it in 'CMD://cmd' is it the same way as 'OnPlayerCommand'?
Reply
#19

Quote:
Originally Posted by Triggerz
Посмотреть сообщение
thanks,

also, if I were to use 'IsPlayerAdmin' and else/if statements, how would I put it in 'CMD://cmd' is it the same way as 'OnPlayerCommand'?
Ye so it'll be like this:

PHP код:
CMD:admin(playerid,params[])
{
      if(
IsPlayerAdmin(playerid)
      {
          
SendClientMessageToAll(0xf8f8f8fff,"he is an admin");
      }
      else
      {
       
SendClientMessage(playerid,0xf8f8f8888,"You aren't an RCON Admin to access to this shit");
      }
      return 
1;

Reply
#20

Quote:
Originally Posted by Triggerz
Посмотреть сообщение
thanks,

also, if I were to use 'IsPlayerAdmin' and else/if statements, how would I put it in 'CMD://cmd' is it the same way as 'OnPlayerCommand'?
Here is a simple example of closing a sevrer,

PHP код:
//layout 1
CMD:exit(playerid){
      if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playerid0xFF0000"[ERROR]: You are not authorized to use this command");
      
SendRconCommand("exit");
      return 
1;
}
//layout 2
CMD:exit(playerid){
      if(
IsPlayerAdmin(playerid)){
             
SendRconCommand("exit");
      }
      else 
SendClientMessage(playerid0xFF0000"[ERROR]: You are not authorized to use this command");
      return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)