[Help] Cuff command
#1

Ok , so i made this command . But i have a problem . If you tipe /cuff you cuff yourself , and i want to cuff a player that is in that radius . How to fix that ?

Command :
pawn Код:
if(strcmp(cmd, "/cuff", true) == 0)
    {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_GREY, "USAGE: /cuff [playerid]");
        }
        giveplayerid = strval(tmp);
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        if(gTeam[playerid] == TEAM_COP && PlayerInfo[playerid][pRank] == 1 || gTeam[playerid] == TEAM_ARMY && PlayerInfo[playerid][pRank] == 2)
        {
            if(PlayerToPoint(7.5, giveplayerid, x , y, z))
            {
                if(gTeam[playerid] == TEAM_COP && PlayerInfo[playerid][pRank] == 1 || gTeam[playerid] == TEAM_ARMY && PlayerInfo[playerid][pRank] == 2 && IsPlayerAdmin(playerid) || PlayerInfo[playerid][pAdmin] >= 104)
                {
                    format(string, sizeof(string), "Officer %s has cuffed (suspect) %s", PlayerName[playerid], PlayerName[giveplayerid]);
                    SendClientMessageToAll(COLOR_BLUE, string);
                    TogglePlayerControllable(giveplayerid, false);
                    return 1;
                }

                else
                {
                    SendClientMessage(playerid, COLOR_RED, "You could not cuff an officer that follows the law to.");
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_RED, "That playerid is not close (enough) to you!");
            }

        }
        else
        {
            SendClientMessage(playerid, COLOR_RED,"You are not a part of the cops team.");
        }
        return 1;
    }
Reply
#2

Well try using sscanf atleast, it's simple and much better (tip: zcmd and sscanf).
Reply
#3

I don't want to use that . I just want to edit the line that cuffs me instead of other player !
Reply
#4

pawn Код:
if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_GREY, "USAGE: /cuff [playerid]");
        }
        else
{
        giveplayerid = strval(tmp);
        // etc.
Try
Reply
#5

No ! It isn't working . You made something wrong here . It gave loads of errors . More help please !
Reply
#6

what are those errors?
Reply
#7

pawn Код:
if(strcmp(cmd, "/cuff", true) == 0)
    {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_GREY, "USAGE: /cuff [playerid]");
        }
        giveplayerid = strval(tmp);
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        if(gTeam[playerid] == TEAM_COP && PlayerInfo[playerid][pRank] == 1 || gTeam[playerid] == TEAM_ARMY && PlayerInfo[playerid][pRank] == 2)
        {
            if(giveplayerid == playerid)
            {
              SendClientMessage(playerid, COLOR_RED, "You cannot cuff yourself!");
              return 1;
            }
            if (ProxDetectorS(7.5, playerid, giveplayerid))
            {
                if(gTeam[playerid] == TEAM_COP && PlayerInfo[playerid][pRank] == 1 || gTeam[playerid] == TEAM_ARMY && PlayerInfo[playerid][pRank] == 2 && IsPlayerAdmin(playerid) || PlayerInfo[playerid][pAdmin] >= 104)
                {
                    format(string, sizeof(string), "Officer %s has cuffed (suspect) %s", PlayerName[playerid], PlayerName[giveplayerid]);
                    SendClientMessageToAll(COLOR_BLUE, string);
                    TogglePlayerControllable(giveplayerid, false);
                    return 1;
                }
                else
                {
                    SendClientMessage(playerid, COLOR_RED, "You could not cuff an officer that follows the law to.");
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_RED, "That playerid is not close (enough) to you!");
            }

        }
        else
        {
            SendClientMessage(playerid, COLOR_RED,"You are not a part of the cops team.");
        }
        return 1;
    }
If you dont have ProxDetectorS yet add:
pawn Код:
forward ProxDetectorS(Float:radi, playerid, targetid);
pawn Код:
public ProxDetectorS(Float:radi, playerid, targetid)
{
    if(IsPlayerConnected(playerid)&&IsPlayerConnected(targetid))
    {
        new Float:posx, Float:posy, Float:posz;
        new Float:oldposx, Float:oldposy, Float:oldposz;
        new Float:tempposx, Float:tempposy, Float:tempposz;
        GetPlayerPos(playerid, oldposx, oldposy, oldposz);
        GetPlayerPos(targetid, posx, posy, posz);
        tempposx = (oldposx -posx);
        tempposy = (oldposy -posy);
        tempposz = (oldposz -posz);
        if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
        {
            return 1;
        }
    }
    return 0;
}
Reply
#8

Ty a lot ! It worked
Reply
#9

Quote:
Originally Posted by [Aka]Dragonu
Посмотреть сообщение
Ty a lot ! It worked
Your welcome.
Reply
#10

This script is using IsPlayerInRange of point,you can always do that with proxdetector too
Just replace the IsPlayerInRangeOfPoint with:
pawn Код:
if (ProxDetectorS(8.0, playerid, giveplayerid))

pawn Код:
if(strcmp(cmd, "/cuff", true) == 0 || strcmp(cmd, "/cu", true) == 0)
    {
                  new Float:x,Float:y,Float:z;
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp))
                       {
                    SendClientMessage(playerid, COLOR_WHITE, "USAGE: /cuff [Playerid/PartOfName]");
                    return 1;
                }
                giveplayerid = ReturnUser(tmp);
                                                 GetPlayerPos(giveplayerid, x, y, z);
                        if (IsPlayerInRangeOfPoint(playerid, 8.0 ,x,y,z)
                        {
                            if(giveplayerid == playerid) return SendClientMessage(playerid, COLOR_GREY, "You cannot cuff yourself!");
                            SendClientMessage(giveplayerid, COLOR_WHITE, "You are cuffed");
                            SendClientMessage(playerid, COLOR_WHITE, "You have cuffed a suspect!");
                            GameTextForPlayer(giveplayerid, "~r~Cuffed", 2500, 3);
                            TogglePlayerControllable(giveplayerid, 1);
                        }
                        else
                        {
                            SendClientMessage(playerid, COLOR_GREY, "* That player is not near you !");
                            return 1;
                        }
        return 1;
    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)