[Help]: Range Arrest Command
#1

Hi, Im trying to make a /ar command that detects wanted players in range to remove the need for a /ar [id]..

Its works fine but my usages and else statements flood..Im sure im not doing the MAX_PLAYERS properly..

May someone kindly take a look at it and explain my mistakes please..

pawn Код:
CMD:ar(playerid, params[])
{
    for(new i=0;i<MAX_PLAYERS;i++)//Is this in the correct position?
    {
        if(HasBeenTied[playerid] == false)
        {
            if(!IsPlayerInAnyVehicle(i) && !IsPlayerInAnyVehicle(playerid))
            {
                if(GetPlayerWantedLevel(i) >= 4 && IsPlayerNearPlayer(playerid, i, 5))
                {
                    if(gTeam[playerid] == CLASS_COPS)
                    {
                        new aName[64], pName[64], string[256];
                        PlayerInfo[playerid][pTakedowns] ++;
                        PlayerInfo[i][pArrests] ++;
                        GetPlayerName(i, aName, sizeof(aName));
                        GetPlayerName(playerid, pName, sizeof(pName));
                        TogglePlayerControllable(i,false);
                        GameTextForPlayer(playerid,"~w~Suspect ~g~Arrested!",3000,5);
                        GameTextForPlayer(i,"~r~Arrested!",3000,5);
                        format(string, sizeof(string), "Officer %s [%d] Has Just Arrested You!",pName,playerid);
                        SendClientMessage(i, RED, string);
                        format(string, sizeof(string), "Well Done! Suspect %s [%d] Has Been Arrested!",aName,i);
                        SendClientMessage(playerid, YELLOW,string);
                        new fstring[128];
                        format(fstring, sizeof(fstring), "Suspect %s [%d] Has Been Arrested By Officer %s [%d]!",aName,i,pName,playerid);
                        SendClientMessageToAll(LIGHTGREEN,fstring);
                        printf(fstring);
                        SetPlayerScore(i, GetPlayerScore(i)-1);
                        SetPlayerScore(playerid, GetPlayerScore(playerid)+1);
                        GivePlayerCash(playerid, 10000);
                        SetPlayerSpecialAction(i, SPECIAL_ACTION_HANDSUP);
                        ApplyAnimation(playerid,"ped","ARRESTgun",4.1,0,1,1,1,1);
                        SetTimerEx("StopAnim", 3000, false, "d", playerid);
                        SetTimerEx("SendToJail", 3000, false, "d", i);
                        HasBeenCuffed[i] = false;
                    }
                    else if(gTeam[playerid] == CLASS_CIA)
                    {
                        new aName[64], pName[64], string[256];
                        PlayerInfo[playerid][pTakedowns] ++;
                        PlayerInfo[i][pArrests] ++;
                        GetPlayerName(i, aName, sizeof(aName));
                        GetPlayerName(playerid, pName, sizeof(pName));
                        TogglePlayerControllable(i,false);
                        GameTextForPlayer(playerid,"~w~Suspect ~g~Arrested!",3000,5);
                        GameTextForPlayer(i,"~r~Arrested!",3000,5);
                        SendClientMessage(i,RED, "You Have Been Arrested By An Undercover CIA Agent!");
                        format(string, sizeof(string), "Well Done! Suspect %s [%d] Has Been Arrested! [$10,000]",aName,i);
                        SendClientMessage(playerid, YELLOW,string);
                        new fstring[128];
                        format(fstring, sizeof(fstring), "Suspect %s [%d] Has Been Arrested By An Undercover CIA Agent!",aName,i);
                        SendClientMessageToAll(LIGHTGREEN,fstring);
                        printf(fstring);
                        SetPlayerScore(i, GetPlayerScore(i)-1);
                        SetPlayerScore(playerid, GetPlayerScore(playerid)+1);
                        GivePlayerCash(playerid, 10000);
                        SetPlayerHealth(i, 99999);
                        SetPlayerSpecialAction(i, SPECIAL_ACTION_HANDSUP);
                        SetTimerEx("SendToJail", 3000, false, "d", i);
                        HasBeenCuffed[i] = false;
                    }
                    else if(gTeam[playerid] != CLASS_ARMY)
                    {
                        new aName[64], pName[64], string[256];
                        PlayerInfo[playerid][pTakedowns] ++;
                        PlayerInfo[i][pArrests] ++;
                        GetPlayerName(i, aName, sizeof(aName));
                        GetPlayerName(playerid, pName, sizeof(pName));
                        TogglePlayerControllable(i,false);
                        GameTextForPlayer(playerid,"~w~Suspect ~g~Arrested!",3000,5);
                        GameTextForPlayer(i,"~r~Arrested!",3000,5);
                        SendClientMessage(i,RED, "You Have Been Arrested By A Army Soldier!");
                        format(string, sizeof(string), "Well Done! Suspect %s [%d] Has Been Arrested! [$10,000]",aName,i);
                        SendClientMessage(playerid, YELLOW,string);
                        new fstring[128];
                        format(fstring, sizeof(fstring), "Suspect %s [%d] Has Been Arrested By A Army Soldier!",aName,i);
                        SendClientMessageToAll(LIGHTGREEN,fstring);
                        printf(fstring);
                        SetPlayerScore(i, GetPlayerScore(i)-1);
                        SetPlayerScore(playerid, GetPlayerScore(i)+1);
                        GivePlayerCash(playerid, 10000);
                        SetPlayerHealth(i, 99999);
                        SetPlayerSpecialAction(i, SPECIAL_ACTION_HANDSUP);
                        SetTimerEx("SendToJail", 3000, false, "d", i);
                        HasBeenCuffed[i] = false;
                    }// These else statements below flood...I think it shows then 500 times..MAX_PLAYERS..
                    //else
                   // {
                        //SendClientMessage(playerid,RED, "Only Law Enforment Can Arrest People!");
                    //}
                }
               // else
               // {
                    //SendClientMessage(playerid,RED, "No Wanted Players In Range!");
               // }
            }
            //else
            //{
                //SendClientMessage(playerid,RED, "You Cant Arrest Players Through Vehicles!");
           // }
        }
    //  else
        //{
            //SendClientMessage(playerid, RED, "You Cant Arrest Players While Your Tied Up!");
    //  }
    }
    return true;
}
Thanks in advanced!

EDIT:

This is the stock i use(Found on net,Credits unknown)

pawn Код:
forward IsPlayerNearPlayer(playerid, n_playerid, Float:radius);
IsPlayerNearPlayer(playerid, n_playerid, Float:radius)
{
    new Float:npx, Float:npy, Float:npz;
    GetPlayerPos(n_playerid, npx, npy, npz);
    if(IsPlayerInRangeOfPoint(playerid, radius, npx, npy, npz))
    {
        return true;
    }
    return false;
}
Reply
#2

It is in the correct place, though you could move it down under if(hasbeentied , but it doesn't really matter, as the loop will be killed if it returns hasbeentied true.
Reply
#3

Quote:
Originally Posted by Mike Garber
Посмотреть сообщение
It is in the correct place, though you could move it down under if(hasbeentied , but it doesn't really matter, as the loop will be killed if it returns hasbeentied true.
Sorry?

Are you saying "if" statements that dont posses "i" after it kills the "for(new i; i<MAX_PLAYERS; i++)" function??
Reply
#4

No..
-> You run the loop
-> You check if the player who does the command /ar is tied (hasbeentied)
-> If it returns false, the loop will continue
-> If it returns true (that the player IS tied), the loop will be killed

With other words, your code is alright.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)