[Tutorial] /cuff and /uncuff Tutorial (sscanf)+(ZCMD)
#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


Messages In This Thread
/cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Eoussama - 01.10.2016, 14:58
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Kruno88 - 01.10.2016, 15:11
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by SyS - 01.10.2016, 15:14
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by AndySedeyn - 01.10.2016, 15:53
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Eoussama - 01.10.2016, 16:11
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Eoussama - 08.12.2016, 10:24
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Dayrion - 09.12.2016, 00:12
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by XxFiGhteRXx - 31.12.2016, 10:36
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Stinged - 31.12.2016, 10:51
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Triggerz - 22.01.2017, 18:57
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by RyderX - 22.01.2017, 19:29
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by PaRking - 22.01.2017, 19:35
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by RyderX - 22.01.2017, 19:36
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by PaRking - 22.01.2017, 19:38
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by RyderX - 22.01.2017, 19:39
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Eoussama - 22.01.2017, 19:40
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Triggerz - 22.01.2017, 19:43
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Triggerz - 22.01.2017, 19:45
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by RyderX - 22.01.2017, 19:49
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Eoussama - 22.01.2017, 19:50
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Triggerz - 22.01.2017, 19:54
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by JohnFlores - 24.07.2017, 14:22
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by coool - 24.07.2017, 15:16

Forum Jump:


Users browsing this thread: 2 Guest(s)