SA-MP Forums Archive
Get distance between players - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Get distance between players (/showthread.php?tid=358574)



Get distance between players - ZBits - 11.07.2012

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


Re: Get distance between players - Abhi - 11.07.2012

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 :\)


Re: Get distance between players - ReneG - 11.07.2012

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));
}



Re: Get distance between players - Larceny - 11.07.2012

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
    }
}



Re: Get distance between players - ZBits - 11.07.2012

thanks for the help both of them are working


Re: Get distance between players - ZBits - 11.07.2012

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


Re: Get distance between players - ZBits - 11.07.2012

nvm fixed


Re: Get distance between players - ZBits - 11.07.2012

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


Re: Get distance between players - Larceny - 11.07.2012

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.


Re: Get distance between players - ZBits - 11.07.2012

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