/arrest
#1

Hey guys! i have /arrest [playerid] command
how to make "playerid" optional and the command arrests the closest wanted player of the cop if the cop doesn't type the playerid that he want to arrest??!!
Reply
#2

pawn Код:
CMD:arrest(playerid, params[])
{
    if(PlayerInfo[playerid][PoliceMan] == >1)
    {
          new pID;
          if(sscanf(params, "u", pID))return SendClientMessage(playerid, -1, "Syntax:/arrest [playerid]");
          if(pID == INVALID_PLAYER_ID)return SendClientMessage(playerid, -1, "Player Not Found.");
          if(GetPlayerWantedLevel(pID) >= 1)return SendClientMessage(playerid, -1, "Play has not an Wanted Level");
          SetPlayerPos(pID, x, y, z); //The Cordinates x, y, z replace with your jail pos.
          SetPlayerWantedLevel(pID, 0);
          GameTextForPlayer(pID, "You are jailed for 10 seconds.", 3000, 3); //Replace 10 seconds with you time.
          SetTimerEx("Jail", 10000, "i", pID);  //Seting an Timer for Jail 10sec.= 10000milisec.
          return 1;
}

forward Jail(pID);
public Jail(pID)
{
         GameTextForPlayer(pID, "You are not jailed any more", 3000, 3);
         SetPlayerPos(pID, 0, 0, 0);
         return 1;
}
//NOT TESTED YET.
Reply
#3

Instead of the sscanf above use something like this (not tested either, made up just now so it might be wrong):

pawn Код:
if(sscanf(params, "u", pid))
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
   
    for(new i = 0; i <= MAX_PLAYERS; i++)
    {
        if(IsPlayerInRangeOfPoint(i, 3.0, x, y, z)) //3.0 is the range, change this to whatever you want.
        {
            SetPlayerPos(i, 0.0, 0.0, 0.0);
            break; //or just return 1, it will stop the loop (I think return 1 will do it as well);
        }
    }
    return 1;
}
else
{
    //Code for SetPlayerPos(pid...)
        return 1;
}
Explaination: if(sscanf… checks if the player did not type in "u" (an ID, part of name), if he DID NOT it will do what is said in the brackets, otherwise it will go to "else".
Reply
#4

Quote:
Originally Posted by Hansrutger
Посмотреть сообщение
Instead of the sscanf above use something like this (not tested either, made up just now so it might be wrong):

pawn Код:
if(sscanf(params, "u", pid))
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
   
    for(new i = 0; i <= MAX_PLAYERS; i++)
    {
        if(IsPlayerInRangeOfPoint(i, 3.0, x, y, z))
        {
            SetPlayerPos(i, 0.0, 0.0, 0.0);
            break;
        }
    }
   
}
else
{
    //Code for SetPlayerPos(pid...)

}
Explaination: if(sscanf… checks if the player did not type in "u" (an ID, part of name), if he DID NOT it will do what is said in the brackets, otherwise it will go to "else".
Yup you are right
Reply
#5

If you really want the EXACT nearest person to be jailed, aka meaning even if the person is across the other side of the map, then do a for loop outside that for loop:

pawn Код:
for(new a = 0; a <= 10000; a++)
{
    for(new i = 0; i <= MAX_PLAYERS; i++)
    {
        new Float:range; //make new float
        range = float(a); //convert the integer first for loop variable a into range
       
        if(IsPlayerInRangeOfPoint(i, range, x, y, z))
        {
            SetPlayerPos(i, 0.0, 0.0, 0.0);
            break;
        }
    }
}
Not recommended by me because I don't know the maximum x, y or z -axis in San Andreas, maybe it will affect the virtual worlds as well.

Improvements on first attempt:
pawn Код:
if(sscanf(params, "u", pid))
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    new vw = GetPlayerVirtualWorld(playerid);
   
    for(new i = 0; i <= MAX_PLAYERS; i++)
    {
        vwI = GetPlayerVirtualWorld(i);
        if((IsPlayerInRangeOfPoint(i, 3.0, x, y, z)) && (vwI == vw)) //3.0 is the range, change this to whatever you want.
        {
            SetPlayerPos(i, 0.0, 0.0, 0.0);
            break; //or just return 1, it will stop the loop (I think return 1 will do it as well);
        }
    }
    return 1;
}
else
{
    //Code for SetPlayerPos(pid...)
        return 1;
}
You can also add GetPlayerInterior and check if they are same as well!
Reply
#6

So all i have to do is changing this:
pawn Код:
if(sscanf(params, "u", pID))return SendClientMessage(playerid, -1, "Usage: /arrest [playerid]");
To:
pawn Код:
if(sscanf(params, "u", pID)) return "The Loops");
Reply
#7

No, that should not work. The first one you stated should work out.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)