Getting distance between player to player
#1

Title says it, how can I do this? To check if a player is in certain range to another player?
Reply
#2

OK

First set use GetPos on both players by making 6 new floats

Then use IsInRangeOfPoint(playerid, [amount], Other Player float1, Other Player float2, Other Player float3

very simple

example:

pawn Code:
CMD:pay(playerid, params[])
{
    new id;
    new money2;
    new Float:XX1, Float:YY1, Float:ZZ1;
    if(!sscanf(params, "ud", id, money2))
    {
        new string[128];
        GetPlayerPos(id, XX1, YY1, ZZ1);
        if(IsPlayerInRangeOfPoint(playerid, 5.0, XX1, YY1, ZZ1))
        {
            if(GetPlayerMoney(playerid) >= money2 + 50)
            {
                new name[MAX_PLAYER_NAME], pname[MAX_PLAYER_NAME];
                GetPlayerName(playerid, name, sizeof(name));
                GetPlayerName(id, pname, sizeof(pname));
                GivePlayerMinusCash(playerid, money2);
                GivePlayerCash(id, money2);
                format(string, sizeof(string), "**%s Takes out some money and gives it to %s ((%d))", name, pname, money2);
                ProxDetector(15.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                return 1;
            }
            else return SendClientMessage(playerid, COLOR_GREY, "Not enough money! You must have at least $50 at the end of the transaction!");
        }
        else return SendClientMessage(playerid, COLOR_GREY, " You are not near the other player! ");
    }
    else return SendClientMessage(playerid, COLOR_GREY, " UASGE: /pay [Player ID/ PlayerName] [Ammount] ");
}
Reply
#3

Quote:
Originally Posted by Azzeto
View Post
Title says it, how can I do this? To check if a player is in certain range to another player?
Try something like:

pawn Code:
forward GetClosestPlayerToPlayer(playerid);
public GetClosestPlayerToPlayer(playerid)
{
    new Float:dist = 1000.0;
    new targetid = INVALID_PLAYER_ID;
    new Float:x1,Float:y1,Float:z1;
    new Float:x2,Float:y2,Float:z2;
    new Float:tmpdis;
    GetPlayerPos(playerid,x1,y1,z1);
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(i == playerid) continue;
        GetPlayerPos(i,x2,y2,z2);
        tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
        if(tmpdis < dist)
        {
            dist = tmpdis;
            targetid = i;
        }
    }
    return targetid;
}
Reply
#4

Quote:
Originally Posted by milanosie
View Post
OK

First set use GetPos on both players by making 6 new floats

Then use IsInRangeOfPoint(playerid, [amount], Other Player float1, Other Player float2, Other Player float3

very simple

example:

pawn Code:
CMD:pay(playerid, params[])
{
    new id;
    new money2;
    new Float:XX1, Float:YY1, Float:ZZ1;
    if(!sscanf(params, "ud", id, money2))
    {
        new string[128];
        GetPlayerPos(id, XX1, YY1, ZZ1);
        if(IsPlayerInRangeOfPoint(playerid, 5.0, XX1, YY1, ZZ1))
        {
            if(GetPlayerMoney(playerid) >= money2 + 50)
            {
                new name[MAX_PLAYER_NAME], pname[MAX_PLAYER_NAME];
                GetPlayerName(playerid, name, sizeof(name));
                GetPlayerName(id, pname, sizeof(pname));
                GivePlayerMinusCash(playerid, money2);
                GivePlayerCash(id, money2);
                format(string, sizeof(string), "**%s Takes out some money and gives it to %s ((%d))", name, pname, money2);
                ProxDetector(15.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                return 1;
            }
            else return SendClientMessage(playerid, COLOR_GREY, "Not enough money! You must have at least $50 at the end of the transaction!");
        }
        else return SendClientMessage(playerid, COLOR_GREY, " You are not near the other player! ");
    }
    else return SendClientMessage(playerid, COLOR_GREY, " UASGE: /pay [Player ID/ PlayerName] [Ammount] ");
}
Pay command? He asked about distance

Here you are.
pawn Code:
stock Float:GetDistanceBetweenPlayers(playerid,targetplayerid)
{
    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetplayerid)) {
        return -1.00;
    }
    GetPlayerPos(playerid,x1,y1,z1);
    GetPlayerPos(targetplayerid,x2,y2,z2);
    return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
Reply
#5

Quote:
Originally Posted by Dwane
View Post
Pay command? He asked about distance

Here you are.
pawn Code:
stock Float:GetDistanceBetweenPlayers(playerid,targetplayerid)
{
    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetplayerid)) {
        return -1.00;
    }
    GetPlayerPos(playerid,x1,y1,z1);
    GetPlayerPos(targetplayerid,x2,y2,z2);
    return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
If you look closely You see that the distance is in there,.

As I said its an example of how to use it.
Reply
#6

Dude, you could make an example without mix another command. He might confused with some of the functions.
It's like I request a kick command and give me a /setlevel command with Kick( id ); in it!
Reply
#7

pawn Code:
GetPlayerDistanceFromPoint(playerid, Float:x, Float:y, Float:z);
Reply
#8

pawn Code:
new Float:x,Float:y,Float:z;
GetPlayerPos(playerid,x,y,z);
x = GetPlayerDistanceFromPoint(playerid,x,y,z);
//X is the distance
https://sampwiki.blast.hk/wiki/GetPlayerDistanceFromPoint
Reply
#9

Thanks everyone..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)