IsPlayerInRangeOfPoint Question
#1

How do I detect if a player is in range of IsACop (cops in my GM). I would like to make a police radar detector, I just need to know how I would set it up...

Thanks:
jakejohnsonusa
Reply
#2

Like this?

pawn Код:
if (strcmp("/radar", cmdtext, true, 10) == 0)
{
    if(!IsACop(playerid)) return SendClientMessage(playerid, 0xFF0000FF, "You aren't a cop.");
    new counter = 0, string[268], player[268];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInRangeOfPoint(i, 30.0, x, y, z) && i != playerid && IsPlayerConnected(i))
        {
            counter++;
        }
    }
    if(counter == 0) return SendClientMessage(playerid, 0xFF0000FF, "No one is in your range.");
    strdel(string, 0, strlen(string));
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInRangeOfPoint(i, 30.0, x, y, z) && i != playerid && IsPlayerConnected(i))
        {
            format(player, sizeof(player), "%s (%d)\n", Nick(i), i);
            strins(string, player, strlen(string), sizeof(string));
        }
    }
    ShowPlayerDialog(playerid, DIALOG_RADAR, DIALOG_STYLE_MSGBOX, "Radar", string, "Okay", "");
    strdel(string, 0, strlen(string));
    return 1;
}
Reply
#3

It will detect if a Police is near the player that uses /detector
Reply
#4

Here

pawn Код:
if (strcmp("/radar", cmdtext, true, 10) == 0)
{
    new counter = 0, string[268], player[268];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInRangeOfPoint(i, 30.0, x, y, z) && i != playerid && IsPlayerConnected(i) && IsACop(i))
        {
            counter++;
        }
    }
    if(counter == 0) return SendClientMessage(playerid, 0xFF0000FF, "No one is in your range.");
    strdel(string, 0, strlen(string));
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInRangeOfPoint(i, 30.0, x, y, z) && i != playerid && IsPlayerConnected(i) && IsACop(i))
        {
            format(player, sizeof(player), "%s (%d)\n", Nick(i), i);
            strins(string, player, strlen(string), sizeof(string));
        }
    }
    ShowPlayerDialog(playerid, DIALOG_RADAR, DIALOG_STYLE_MSGBOX, "Radar", string, "Okay", "");
    strdel(string, 0, strlen(string));
    return 1;
}
Reply
#5

This will alert the player that a Police Officer is nearby? I would like it to constantly check for officers (so while they are driving if an officer starts to drive in the area around them they will get a message "Law Enforcment Detected"

How would I do that with the script you gave me... Also +1 Rep.

Thanks: jakejohnsonusa
Reply
#6

Yes, and it will show the name of the cops.

I forgot to post the stock function for getting players name. Copy this anywhere in your script.
pawn Код:
stock Nick(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    return name;
}
Reply
#7

Would you mind //the part that does that, tells the cops name... Please and thanks
Reply
#8

It works now or? If yes no problem
Reply
#9

I get these errors with the script:

Код:
C:\Users\Michael Fagel\Desktop\larp.pwn(38418) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\Michael\Desktop\larp.pwn(38419) : warning 217: loose indentation
C:\Users\Michael\Desktop\larp.pwn(38421) : error 017: undefined symbol "x"
C:\Users\Michael\Desktop\larp.pwn(38430) : error 017: undefined symbol "x"
C:\Users\Michael\Desktop\larp.pwn(38436) : error 017: undefined symbol "DIALOG_RADAR"
Reply
#10

Try this

pawn Код:
if (strcmp("/radar", cmdtext, true, 10) == 0)
{
    new counter = 0, player[268];
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInRangeOfPoint(i, 30.0, x, y, z) && i != playerid && IsPlayerConnected(i) && IsACop(i))
        {
            counter++;
        }
    }
    if(counter == 0) return SendClientMessage(playerid, 0xFF0000FF, "No one is in your range.");
    strdel(string, 0, strlen(string));
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInRangeOfPoint(i, 30.0, x, y, z) && i != playerid && IsPlayerConnected(i) && IsACop(i))
        {
            format(player, sizeof(player), "%s (%d)\n", Nick(i), i);
            strins(string, player, strlen(string), sizeof(string));
        }
    }
    ShowPlayerDialog(playerid, 1592, DIALOG_STYLE_MSGBOX, "Radar", string, "Okay", "");
    strdel(string, 0, strlen(string));
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)