IsPlayerInRange problem
#1

I haven't coded in a while and I've became very rusty even making the most basic of scripts. This script returns no errors on Pawn but in-game, it allows me to go on duty if I'm pPD 1, but it puts me on duty no matter where I am, but also returns the error: "ERROR: Unknown command".

The below is the relevant code, I think I've only made a minor mistake. I seem to remember coding this successfully before but I've forgotten how to properly do it.

pawn Код:
if (strcmp("/duty", cmdtext, true, 5) == 0)
    {
        if(PlayerInfo[playerid][pPD] < 1)
        return SendClientMessage(playerid, COLOR_ERROR,"ERROR.");
        if(IsPlayerInRangeOfPoint(playerid, 5.0,-2500.2500,250.2500,5.2500))
        SendClientMessage(playerid, COLOR_ERROR,"ERROR.");
        else
        SendClientMessage(playerid, COLOR_WHITE, "Police duty");
        SetPlayerHealth(playerid, 100.100);
        SetPlayerArmour(playerid, 100.100);
        SetPlayerColor(playerid, COLOR_WHITE);


        return 0;
       
    }
I've tried many combinations but to no avail.

Any help would be appreciated.

Thanks.
Reply
#2

pawn Код:
if(!IsPlayerInRangeOfPoint(playerid, 5.0,-2500.2500,250.2500,5.2500))
Reply
#3

That's helped slightly, but my problem is still occurring. It still lets me go on duty but now it says the "ERROR" thing -- it still says "ERROR: Unknown command" though. Before, it said "Police duty" and the "ERROR: Unknown command" error.

I think I've messed up slightly.
Reply
#4

pawn Код:
if(strcmp("/duty", cmdtext, true, 5) == 0)
{
    if(PlayerInfo[playerid][pPD] < 1)
    return SendClientMessage(playerid, COLOR_ERROR,"ERROR.");
    if(IsPlayerInRangeOfPoint(playerid, 5.0,-2500.2500,250.2500,5.2500))
    SendClientMessage(playerid, COLOR_ERROR,"ERROR.");
    else
    SendClientMessage(playerid, COLOR_WHITE, "Police duty");
    SetPlayerHealth(playerid, 100.100);
    SetPlayerArmour(playerid, 100.100);
    SetPlayerColor(playerid, COLOR_WHITE);
    return 1;
}
Reply
#5

With the code above, it puts me on duty, says 'Police duty' and there's no unknown command error, but it now completely ignores the IsPlayerInRangeOfPoint.

Thanks for your help though, but further help is appreciated!
Reply
#6

It depends on what you want.
pawn Код:
if(IsPlayerInRangeOfPoint(playerid, 5.0,-2500.2500,250.2500,5.2500))
        SendClientMessage(playerid, COLOR_ERROR,"ERROR.");
        else
        SendClientMessage(playerid, COLOR_WHITE, "Police duty");
This code sends the message "ERROR" if you're in range of those coordinates. If you're not, then it sends the message "Police duty".

In case you want the opposite, do what Areax said at his first post.

Also, if you want the health, armour and colour when they're on police duty, you need to use it inside a block { }.
pawn Код:
else
{
    SendClientMessage(playerid, COLOR_WHITE, "Police duty");
    SetPlayerHealth(playerid, 100.100);
    SetPlayerArmour(playerid, 100.100);
    SetPlayerColor(playerid, COLOR_WHITE);
}
Reply
#7

pawn Код:
if(strcmp("/duty", cmdtext, true, 5) == 0)
{
    if(PlayerInfo[playerid][pPD] < 1)
    return SendClientMessage(playerid, COLOR_ERROR,"ERROR.");
    if(!IsPlayerInRangeOfPoint(playerid, 5.0,-2500.2500,250.2500,5.2500))
    SendClientMessage(playerid, COLOR_ERROR,"ERROR.");
    else
    SendClientMessage(playerid, COLOR_WHITE, "Police duty");
    SetPlayerHealth(playerid, 100.100);
    SetPlayerArmour(playerid, 100.100);
    SetPlayerColor(playerid, COLOR_WHITE);
    return 1;
}
My bad :P I forgot "!"
Reply
#8

We fixed it!

Thanks Areax and Konstantinos, you've both received + reps.

(Well, I approved your posts. I don't think you got a plus rep but whatever :P)
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)