Arrest command issues
#1

So i made a arrest command and i made it that you dont have to use /ar id to arrest someone but just using /ar so the problem is that it always shows that i am too far from the player when i am near him here is my code


pawn Код:
CMD:ar(playerid,params[])
{
    new id, string[128], pwl = GetPlayerWantedLevel(id);
    if(GetPlayerTeam(playerid) != Cops)
    {
        SendClientMessage(playerid, COLOR_RED,"Only law enforcement can arrest wanted suspects.");
        return 1;
    }
    if(!IsPlayerConnected(id))
    {
        format(string,sizeof(string),"The player ID (%d) is not connected to the server. You cannot arrest them.",id);
        SendClientMessage(playerid, COLOR_RED,string);
        return 1;
    }
    if(Jailed[id] == 1)
    {
       SendClientMessage(playerid, COLOR_RED, "You cannot arrest players that are already jailed.");
       return 1;
    }
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
    {
        SendClientMessage(playerid,COLOR_RED,"You cannot arrest a suspect while in a vehicle. Exit the vehicle first.");
        return 1;
    }
    if(GetPlayerState(id) == PLAYER_STATE_DRIVER || GetPlayerState(id) == PLAYER_STATE_PASSENGER)
    {
        SendClientMessage(playerid,COLOR_RED,"You cannot arrest a suspect they are in a vehicle. Get them to exit the vehicle first.");
        return 1;
    }
    if(Civilian[id] == 1)
    {
       if(Cuffed[id] == 1)
       {
           if(GetDistanceBetweenPlayers(playerid, id) <= 2)
           {
              if(pwl >= 4)
              {
                  GivePlayerMoney(playerid, 3000);
                  IncreaseScore(playerid, 1);
                  IncreaseCoprank(playerid, 1);
                  Jailed[id] = 1;
                  JailTime[id] = 60;
                  Cuffed[id] = 0;
                  SetPlayerInterior(id, 6);
                  SetPlayerPos(id, 264.29999, 77.4, 1001);
                  SendClientMessage(id, COLOR_LIGHTBLUE, "**LOS SANTOS PRISON**");
                  SendClientMessage(id, COLOR_LIGHTBLUE, "[PRISON] You have been sent to prison, you will be out of prison in 60 seconds");
                  SetPlayerWantedLevel(id, 0);
                  SetPlayerHealth(id,99999);
                  SetPlayerSpecialAction(id,SPECIAL_ACTION_NONE);
                  ResetPlayerWeapons(id);
                  format(string,sizeof(string),"Police Officer %s(%d) Has arrested wanted suspect %s(%d) and was given $3000 for arresting him.",GetName(playerid),playerid,GetName(id),id);
                  SendClientMessageToAll(COLOR_ORANGE,string);
                  return 1;
              }
           }
           else return SendClientMessage(playerid,COLOR_RED,"There is no player near you that you can arrest, please search for cuffed players and make sure to be near them to be able to arrest them.");
       }
    }
    return 1;
}

pawn Код:
else return SendClientMessage(playerid,COLOR_RED,"There is no player near you that you can arrest, please search for cuffed players and make sure to be near them to be able to arrest them.");
Reply
#2

GetDistanceBetweenPlayers is not a native so you'll have to post it here.
Reply
#3

pawn Код:
GetDistanceBetweenPlayers(playerid, id)
Seems to me like this is the problem. Paste the function here and we can look at it.

Or, use something like this:
pawn Код:
IsPlayerInRangeOfPlayer(playerid, id, Float:range)
{
    new Float:pX, Float:pY, Float: pZ;
    GetPlayerPos(id, pX, pY, pZ);
    if(IsPlayerInRangeOfPoint(playerid, range, pX, pY, pZ))
        return 1;
    else
        return 0;
}
Reply
#4

pawn Код:
CMD:ar(playerid,params[])
{
    new id, string[128], pwl = GetPlayerWantedLevel(id);
    if(GetPlayerTeam(playerid) != Cops)
    {
        SendClientMessage(playerid, COLOR_RED,"Only law enforcement can arrest wanted suspects.");
        return 1;
    }
    if(!IsPlayerConnected(id))
    {
        format(string,sizeof(string),"The player ID (%d) is not connected to the server. You cannot arrest them.",id);
        SendClientMessage(playerid, COLOR_RED,string);
        return 1;
    }
    if(Jailed[id] == 1)
    {
       SendClientMessage(playerid, COLOR_RED, "You cannot arrest players that are already jailed.");
       return 1;
    }
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
    {
        SendClientMessage(playerid,COLOR_RED,"You cannot arrest a suspect while in a vehicle. Exit the vehicle first.");
        return 1;
    }
    if(GetPlayerState(id) == PLAYER_STATE_DRIVER || GetPlayerState(id) == PLAYER_STATE_PASSENGER)
    {
        SendClientMessage(playerid,COLOR_RED,"You cannot arrest a suspect they are in a vehicle. Get them to exit the vehicle first.");
        return 1;
    }
    if(Civilian[id] == 1)
    {
       if(Cuffed[id] == 1)
       {
           if(GetDistanceBetweenPlayers(playerid, id, 2)
           //not if(GetDistanceBetweenPlayers(playerid, id) <= 2)
           {
              if(pwl >= 4)
              {
                  GivePlayerMoney(playerid, 3000);
                  IncreaseScore(playerid, 1);
                  IncreaseCoprank(playerid, 1);
                  Jailed[id] = 1;
                  JailTime[id] = 60;
                  Cuffed[id] = 0;
                  SetPlayerInterior(id, 6);
                  SetPlayerPos(id, 264.29999, 77.4, 1001);
                  SendClientMessage(id, COLOR_LIGHTBLUE, "**LOS SANTOS PRISON**");
                  SendClientMessage(id, COLOR_LIGHTBLUE, "[PRISON] You have been sent to prison, you will be out of prison in 60 seconds");
                  SetPlayerWantedLevel(id, 0);
                  SetPlayerHealth(id,99999);
                  SetPlayerSpecialAction(id,SPECIAL_ACTION_NONE);
                  ResetPlayerWeapons(id);
                  format(string,sizeof(string),"Police Officer %s(%d) Has arrested wanted suspect %s(%d) and was given $3000 for arresting him.",GetName(playerid),playerid,GetName(id),id);
                  SendClientMessageToAll(COLOR_ORANGE,string);
                  return 1;
              }
           }
           else return SendClientMessage(playerid,COLOR_RED,"There is no player near you that you can arrest, please search for cuffed players and make sure to be near them to be able to arrest them.");
       }
    }
    return 1;
}
Reply
#5

Here is the call back that i am using for it and sorry for late reply i was sleeping at the time

pawn Код:
public Float:GetDistanceBetweenPlayers(p1,p2)
{
   new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
   if (!IsPlayerConnected(p1) || !IsPlayerConnected(p2)){
   return -1.00;
}
   GetPlayerPos(p1,x1,y1,z1);
   GetPlayerPos(p2,x2,y2,z2);
   return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));

}
Reply
#6

Quote:
Originally Posted by DarkLored
Посмотреть сообщение
Here is the call back that i am using for it and sorry for late reply i was sleeping at the time

pawn Код:
public Float:GetDistanceBetweenPlayers(p1,p2)
{
   new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
   if (!IsPlayerConnected(p1) || !IsPlayerConnected(p2)){
   return -1.00;
}
   GetPlayerPos(p1,x1,y1,z1);
   GetPlayerPos(p2,x2,y2,z2);
   return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));

}
I have created this simple function, this is easier than the one you have, I have created this function when I was developing my own CnR server but I lost interest but I still have the script in case someone needs some snippet.

pawn Код:
GetDistanceBetweenPlayers(playerid, otherid, Float:dist)
{
    new
        Float:Pos[3]
    ;
    if( IsPlayerConnected( targetid ) && IsPlayerConnected( otherid ) )
    {
        GetPlayerPos( otherid, Pos[ 0 ], Pos[ 1 ], Pos[ 2 ] );
        IsPlayerInRangeOfPoint( playerid, dist, Pos[ 0 ], Pos[ 1 ], Pos[ 2 ] );
        return true;
    }
    return false;
}
pawn Код:
if( !GetDistanceBetweenPlayers(playerid, otherid, Float:dist) ) //if the player is not near.
if( GetDistanceBetweenPlayers(playerid, otherid, Float:dist) ) //if the player is near.
Reply
#7

But mine works i have checked it with other commands but the problem is that it somehow not working with the ar command
Reply
#8

Any ideas whats the problem in my command cause what i see that you only offer a different call back
which dosent change anything
Reply
#9

Can i get some help please ? i really need help guys
Reply
#10

Oh I saw your mistake.

You're never getting the ID of the other player... you just created the variable "id" but you don't assign any value into it, there for you will always be arresting id 0
Reply
#11

So how do i assign it to everyone ? cause that was my point

will it work if i put insted of id MAX_PLAYERS?
Reply
#12

If you wish to make it check if any player at all is close to the player, you should run a for loop
pawn Code:
for(new i = 0; i < MAX_PLAYERS; i++)
{
     // Put code here
}
Reply
#13

Thanks that answered my question +REPED
and others too for sharing their time with helping me
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)