SA-MP Forums Archive
Cuffs.inc cuff cmd help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Cuffs.inc cuff cmd help (/showthread.php?tid=609796)



Cuffs.inc cuff cmd help - iSkate - 16.06.2016

When I do /cuff, sometimes it shows the message "The player is already cuffed" and sometimes when I use a random ID in /cuff (ID), it still cuffs the person near me. Help?
pawn Код:
CMD:cuff(playerid, params[])
{
    new id;
    if(sscanf(params,"f",id)) return SendClientMessage(playerid,COLOR_RED,"[USAGE]"COL_WHITE" /cuff (ID)");
    if(id == playerid) return SendClientMessage(playerid, COLOR_RED, "[ERROR]"COL_WHITE" You cannot cuff yourself.");
    if(IsPlayerInAnyVehicle(id)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]"COL_WHITE" The player is in a vehicle.");
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]"COL_WHITE" You are in a vehicle. Please get out to cuff a player.");
    if(!IsPlayerSpawned(id)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]"COL_WHITE" The player hasn't spawned yet.");
    if(IsPlayerConnected(id))
    {
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        if(IsPlayerInRangeOfPoint(id, 5.0, x, y, z))
        {
            if(IsPlayerCuffed(id))
            {
                SendClientMessage(playerid, COLOR_RED, "[ERROR]"COL_WHITE" The player is already cuffed!");
                return 1;
            }
            if(!IsPlayerCuffed(id))
            {
                if(IsPlayerRunning(id))
                {
                    new crand = random(100);
                    if(crand <= 70)
                    {
                        SendClientMessage(playerid, COLOR_BLUE, "[CUFFED]"COL_WHITE" The player has been cuffed successfully.");
                        SendClientMessage(id, COLOR_BLUE, "[CUFFED]"COL_WHITE" You have been cuffed.");
                        SetPlayerCuffed(id, true);
                        return 1;
                    }
                    else
                    {
                        SendClientMessage(playerid, COLOR_RED, "[FAIL]"COL_WHITE" You have failed to cuff the player.");
                        SendClientMessage(id, COLOR_YELLOW, "[INFO]"COL_WHITE" A Cop has tried to cuff you.");
                        return 1;
                    }
                }
                SendClientMessage(playerid, COLOR_BLUE, "[CUFFED]"COL_WHITE" The player has been cuffed successfully.");
                SendClientMessage(id, COLOR_BLUE, "[CUFFED]"COL_WHITE" You have been cuffed.");
                SetPlayerCuffed(id, true);
                return 1;
            }
        }
        SendClientMessage(playerid, COLOR_RED, "[ERROR]"COL_WHITE" The player is not close enough.");
        return 1;
    }
    SendClientMessage(playerid, COLOR_RED, "[ERROR]"COL_WHITE" The player ID is not connected.");
    return 1;
}

CMD:uncuff(playerid, params[])
{
    new id,skin;
    skin = GetPlayerSkin(playerid);
    if(sscanf(params,"f",id)) return SendClientMessage(playerid,COLOR_RED,"[USAGE]"COL_WHITE" /uncuff (ID)");
    if(id == playerid) return SendClientMessage(playerid, COLOR_RED, "[ERROR]"COL_WHITE" You cannot uncuff yourself.");
    if(!IsPlayerSpawned(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]"COL_WHITE" You need to spawn first, in order to use this command.");
    //if(skin != 280 || 281 || 282 || 283 || 284 || 285 || 286 || 287) return SendClientMessage(playerid, COLOR_RED, "[ERROR]"COL_WHITE" You need to be a cop in order to use this command.");
    if(!IsPlayerSpawned(id)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]"COL_WHITE" The player hasn't spawned yet.");
    if(IsPlayerInAnyVehicle(id)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]"COL_WHITE" The player is in a vehicle.");
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]"COL_WHITE" You are in a vehicle. Please get out to uncuff a player.");
    if(IsPlayerConnected(id))
    {
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        if(IsPlayerInRangeOfPoint(id, 5.0, x, y, z))
        {
            if(!IsPlayerCuffed(id))
            {
                SendClientMessage(playerid, COLOR_RED, "[ERROR]"COL_WHITE" The player is not cuffed!");
                return 1;
            }
            if(IsPlayerCuffed(id))
            {
                SendClientMessage(playerid, COLOR_BLUE, "[UNCUFFED]"COL_WHITE" The player has been uncuffed successfully.");
                SendClientMessage(id, COLOR_BLUE, "[UNCUFFED]"COL_WHITE" You have been uncuffed.");
                SetPlayerCuffed(id, false);
                return 1;
            }
        }
        SendClientMessage(playerid, COLOR_RED, "[ERROR]"COL_WHITE" The player is not close enough.");
        return 1;
    }
    SendClientMessage(playerid, COLOR_RED, "[ERROR]"COL_WHITE" The player ID is not connected.");
    return 1;
}

IsPlayerSpawned(playerid){
    new statex = GetPlayerState(playerid);
    if(statex != PLAYER_STATE_NONE && statex != PLAYER_STATE_WASTED && statex != PLAYER_STATE_SPAWNED) return true;
    return false;
}
stock IsPlayerRunning(playerid)
{
    if(!IsPlayerConnected(playerid)) return 0;
    if(IsPlayerInAnyVehicle(playerid)) return 0;
    new keys, updown, leftright;
    GetPlayerKeys(playerid, keys, updown, leftright);
    if(keys & KEY_SPRINT) return 1;
    return 0;
}



Re: Cuffs.inc cuff cmd help - Konstantinos - 16.06.2016

"f" specifier is used for floats.
For integers use "i" or "d".
For ID or part of name use "r" or "u" (+ NPCs).

First check if the player is not connected (checking if "id" is INVALID_PLAYER_ID is much better than calling a function for it) and then do the rest of the checks for vehicles, spawned etc.


Re: Cuffs.inc cuff cmd help - iSkate - 16.06.2016

The random ID problem still persists.


Re: Cuffs.inc cuff cmd help - iSkate - 17.06.2016

Bump

EDIT: Kind of fixed. For more info: http://forum.sa-mp.com/showthread.ph...38#post3718238


Re: Cuffs.inc cuff cmd help - Sew_Sumi - 17.06.2016

It's not "kind of fixed", it's simply not showing the same symptom.


Re: Cuffs.inc cuff cmd help - iSkate - 18.06.2016

I used the words "kind of fixed" in a way that my problem was fixed. There was a bug in sscanf, not my script.