This makes no sense.
#1

Making an /arrest command, and if you type no parameters it will arrest the closest suspect, which works fine, but if I try and do /arrest [id] it keeps telling me the player is too far away.

pawn Код:
#define ARREST_RADIUS 10.0

printf("DIST: %f   RADIUS: %f", GetDistanceBetweenPlayers(playerid, id), ARREST_RADIUS);
if(GetDistanceBetweenPlayers(playerid, id) > ARREST_RADIUS) return SendClientMessage(playerid, COLOR_RED, "Suspect is too far away.");
Console output:
[19:39:52] DIST: 3.827519 RADIUS: 10.000000

pawn Код:
forward Float:GetDistanceBetweenPlayers(player1, player2);
Float:GetDistanceBetweenPlayers(player1, player2)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(player2, x, y, z);
    return GetPlayerDistanceFromPoint(player1, x, y, z);
}
What the fuck is going on -_-
Clearly 3.827519 is not > 10 so why on earth am I getting that message? :/
Reply
#2

Any other client messages that say "Suspect is too far away."?
Reply
#3

I would try to convert the two compared floats into integers just to see if it would be the same but yeah, it does not make sense.
Reply
#4

Quote:
Originally Posted by Kar
Посмотреть сообщение
Any other client messages that say "Suspect is too far away."?
No, it's practically a blank GM.
Reply
#5

Try with
Quote:

IsPlayerInRangeOfPoint()

Reply
#6

Well I didn't post the whole code as it's irrelevant IMO, but okay.

pawn Код:
#define ARREST_RADIUS 10.0

CMD:arrest(playerid, params[])
{
    if(!IsCop(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not a police officer.");

    new id = -1;
   
    if(isnull(params)) // Closest suspect
    {
        new closest_player = -1;
        new Float:dist = FLOAT_INFINITY;
        new Float:this_dist;
       
        foreach(new i : Player)
        {
            this_dist = GetDistanceBetweenPlayers(playerid, i);
            if(this_dist < dist && GetPlayerSuspectLevel(i) >= SUSPECT_ARREST)
            {
                closest_player = i;
                dist = this_dist;
            }
        }
        if(closest_player == -1) return SendClientMessage(playerid, COLOR_RED, "No arrestable suspects near-by.");
        id = closest_player;
    }
    else // Specified ID
    {
        id = GetPlayerFromParams(playerid, params);
        if(id < 0) return 1;
       
        if(GetPlayerSuspectLevel(id) < SUSPECT_ARREST) return SendClientMessage(playerid, COLOR_RED, "Player is not arrestable.");

        printf("DIST: %f   RADIUS: %f", GetDistanceBetweenPlayers(playerid, id), ARREST_RADIUS);
        if(GetDistanceBetweenPlayers(playerid, id) > ARREST_RADIUS) return SendClientMessage(playerid, COLOR_RED, "Suspect is too far away.");
    }
   
    new szString[144];
    format(szString, sizeof(szString), "Arrested by officer %s (%i).", pName[playerid], playerid);
    SendClientMessage(id, COLOR_RED, szString);
    GameTextForPlayer(id, "~R~Busted", 3000, 3);
   
    format(szString, sizeof(szString), "Arrested suspect %s (%i).", pName[id], id);
    SendClientMessage(playerid, COLOR_RED, szString);
   
    SetPlayerFacePlayer(playerid, id);
    ApplyAnimation(playerid, "PED", "ARRESTgun",4.1,0,1,1,1,1);
   
    SetPlayerWantedLevel(id, 0);
    SetPlayerHealth(id, 0); // Temporary :P
    return 1;
}

forward Float:GetDistanceBetweenPlayers(player1, player2);
Float:GetDistanceBetweenPlayers(player1, player2)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(player2, x, y, z);
    return GetPlayerDistanceFromPoint(player1, x, y, z);
}
Reply
#7

Eh fuck it, not going to arse around for an hour trying to fix a simple thing, this works fine:

pawn Код:
new Float:x, Float:y, Float:z;
GetPlayerPos(id, x, y, z);
if(!IsPlayerInRangeOfPoint(playerid, ARREST_RADIUS, x, y, z)) return SendClientMessage(playerid, COLOR_RED, "Suspect is too far away.");
Thanks for your attempted help :/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)