Get distance between players
#1

hello guys sorry for disturbing you but i need help

i need help with /suspect command

i need the cop to be in range with the target id to suspect him


thanks for help in advance
Reply
#2

simple get the cops cords and the criminal cords
then use the callback
GetDistanceBetweenPoints or something like this
and...........if you want that the criminal or cop is the range of cop/crminal get the cops/crminal range and try
this on the other one
IsPlayerInRange of point (i know the second point is a bit hard to undersant because of the way i wrote it but your topic is still not clear to me :\)
Reply
#3

Found this lying around, credits to whoever made it.
pawn Код:
forward Float:GetDistanceBetweenPlayers(p1,p2);
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
#4

pawn Код:
stock Float:GetPlayerDistanceFromPlayer(playerid, targetid)
{
    new Float:fDist[3];
    GetPlayerPos(playerid, fDist[0], fDist[1], fDist[2]);
    return GetPlayerDistanceFromPoint(targetid, fDist[0], fDist[1], fDist[2]);
}
pawn Код:
//Command
{
    if(GetPlayerDistanceFromPlayer(playerid, suspectid) < 10)
    {
        //do something
    }
}
Reply
#5

thanks for the help both of them are working
Reply
#6

ruiGY when i compile my script i get this warning 208: function with tag result used before definition, forcing reparse
Reply
#7

nvm fixed
Reply
#8

pawn Код:
CMD:suspect(playerid, params[])
{
if(gTeam[playerid] == 1)
{
new id, reason[30];
if(sscanf(params, "rs[30]", id, reason)) return SendClientMessage(playerid, COLOR_ORANGE, "/suspect [id] [reason]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_PINK2, "Error: Target Player Not connected");
new string[80], playername[25], idname[25];
GetPlayerName(playerid, playername, sizeof(playername));
GetPlayerName(id, idname, sizeof(idname));
gTeam[id] = TEAM_CRIMINAL;
format(string, sizeof(string), "Police Radio: %s(%d): has suspected %s(%d) for %s", playername, playerid, idname, id, reason);
foreach(Player, i)
{
if(gTeam[i] == 1) SendClientMessage(i, COLOR_LIGHTBLUE, string);
}
}
}
return 1;
}
RuiGy can you put your code in this command which i have given you above?

i am not much of a good scripter

thanks
Reply
#9

pawn Код:
stock Float:GetPlayerDistanceFromPlayer(playerid, targetid)
{
    new Float:fDist[3];
    GetPlayerPos(playerid, fDist[0], fDist[1], fDist[2]);
    return GetPlayerDistanceFromPoint(targetid, fDist[0], fDist[1], fDist[2]);
}

CMD:suspect(playerid, params[])
{
    if(gTeam[playerid] == 1)
    {
        new id, reason[30];
        if(sscanf(params, "rs[30]", id, reason))
            return SendClientMessage(playerid, COLOR_ORANGE, "/suspect [id] [reason]");

        if(!IsPlayerConnected(id))
            return SendClientMessage(playerid, COLOR_PINK2, "Error: Target Player Not connected");

        if(GetPlayerDistanceFromPlayer(playerid, id) > 10)
            return SendClientMessage(playerid, COLOR_PINK2, "Error: You are not near to suspect.");

        new string[80], playername[25], idname[25];
        GetPlayerName(playerid, playername, sizeof(playername));
        GetPlayerName(id, idname, sizeof(idname));
       
        gTeam[id] = TEAM_CRIMINAL;
        format(string, sizeof(string), "Police Radio: %s(%d): has suspected %s(%d) for %s", playername, playerid, idname, id, reason);
        foreach(Player, i)
        {
            if(gTeam[i] == 1) SendClientMessage(i, COLOR_LIGHTBLUE, string);
        }
    }
    return 1;
}
edit: Make an edit instead of making several posts in a short time period.
Reply
#10

i dont know why i am getting error: undefined symbol suspecitd
Reply


Forum Jump:


Users browsing this thread: 6 Guest(s)