Arrest command doesn't work
#6

Instead of being asked "why does it not work" in a thread that clearly states you don't know why it does not work, I decided to restructure the command and explain each step(in the process) with comments so you can get your head around it.

Let me know if you have anymore issues. Here is the command:

pawn Код:
command(arrest, playerid,params[])
{
    new ID, time, string[90];
    if(sscanf(params, "ud", ID, time))//If the playerid did NOT enter the correct parameters..
    {
        //If the playerid did NOT enter the correct parameters..
        if(Factions[Player[playerid][Faction]][CommandTypes] == 1 || Factions[Player[playerid][Faction]][CommandTypes] == 3)//If player PASSES Faction check..
        {
            SendClientMessage(playerid, COLOR_GREY, "SYNTAX: /arrest [playerid/name] [minutes]");//Send the playerid a usage message, as they did NOT enter the correct parameters..
        }
        else//Else if the player FAILED Faction check..
        {
            //Do this..
            RemoveTextMessage(playerid);
            TextDrawShowForPlayer(playerid, Text:CantCommand);
            SetTimerEx("RemoveTextMessage", 3500, false, "d", playerid);
        }
        return 1;//This is CRITICAL. You need to tell the server to STOP here as the process is now done. Otherwise the server will just keep going(down the script)..
    }
    else//Else the playerid DID enter the correct parameters..
    {
        if(!IsPlayerConnected(ID) || ID == INVALID_PLAYER_ID)//If you have NPC's, I suggest you use !IsPlayerNPC(playerid) on this line..
        {
            return SendClientMessage(playerid, -1, "That player does not exist.");//Notify the playerid that the targetid does NOT exist..
        }
       
        if(GetDistanceBetweenPlayers(playerid, ID) > 4.0)//If the playerid EXISTS(online) and is MORE THAN 4 Metres away(or too far away)..
        {
            format(string, sizeof(string), "%s(%d) is too far away. You cannot reach him to arrest him.", RPName(ID), ID);//Notify the playerid..
            SendClientMessage(playerid, -1, string);
            return 1;//AGAIN this is CRITICAL(and was missing) as you need to tell the server when to STOP, otherwise it will CONTINUE(down the script)..
        }
        else//Else the playerid IS WITHIN or EQUAL TO 4 Metres from the targetid(ID)...
        {
            //Execute the arrest..
            ResetPlayerWeapons(ID);
            Player[ID][Arrest] = 1;
            Player[ID][PrisonTime] = time * 60;
            SetPlayerSpecialAction(ID, SPECIAL_ACTION_NONE);
            format(string, sizeof(string), "> You've arrested %s for %d days at San Andreas Prison.", RPName(ID), time);
            SendClientMessage(playerid, SPECIALORANGE, string);
            format(string, sizeof(string), "> %s has arrested you for %d days at San Andreas Prison.", RPName(playerid), time);
            SendClientMessage(ID, SPECIALORANGE, string);
            //I don't see a function that SENDS the player to Prison.. you may need to add this(unless Player[ID][Arrest] is checked somewhere else and THEN sends the targetid to Prison)
        }
    }
    return 1;
}
Reply


Messages In This Thread
Arrest command doesn't work - by lulo356 - 21.01.2016, 00:52
Re: Arrest command doesn't work - by Sew_Sumi - 21.01.2016, 00:57
Re: Arrest command doesn't work - by lulo356 - 21.01.2016, 01:18
Re: Arrest command doesn't work - by Sew_Sumi - 21.01.2016, 02:44
Re: Arrest command doesn't work - by Threshold - 21.01.2016, 02:50
Re: Arrest command doesn't work - by Weponz - 21.01.2016, 05:49
Re: Arrest command doesn't work - by lulo356 - 21.01.2016, 13:40
Re: Arrest command doesn't work - by Sew_Sumi - 21.01.2016, 22:40
Re: Arrest command doesn't work - by lulo356 - 21.01.2016, 23:58
Re: Arrest command doesn't work - by Sew_Sumi - 22.01.2016, 05:17

Forum Jump:


Users browsing this thread: 2 Guest(s)