What function would i use.
#1

If i wanted to measure the distance from player to player what function would i use.

Thanks in advance.
Reply
#2

IsPlayerInRangeOfPoint(playerid, distance, x, y, z)) // X,y,z = you need to get the distance from the player you want
Reply
#3

Quote:
Originally Posted by blackwave
Посмотреть сообщение
IsPlayerInRangeOfPoint(playerid, distance, x, y, z)) // X,y,z = you need to get the distance from the player you want
Ohk, i thought i might have to use that but thought there might be another function i could use, thanks anyways.
Reply
#4

pawn Код:
stock Float:GetPointAngleToPoint(Float:x2, Float:y2, Float:X, Float:Y)
{
    new Float:DX, Float:DY;
    new Float:angle;
    DX = floatabs(floatsub(x2,X));
    DY = floatabs(floatsub(y2,Y));
    if (DY == 0.0 || DX == 0.0)
    {
        if(DY == 0 && DX > 0) angle = 0.0;
        else if(DY == 0 && DX < 0) angle = 180.0;
        else if(DY > 0 && DX == 0) angle = 90.0;
        else if(DY < 0 && DX == 0) angle = 270.0;
        else if(DY == 0 && DX == 0) angle = 0.0;
    }
    else
    {
        angle = atan(DX/DY);
        if(X > x2 && Y <= y2) angle += 90.0;
        else if(X <= x2 && Y < y2) angle = floatsub(90.0, angle);
        else if(X < x2 && Y >= y2) angle -= 90.0;
        else if(X >= x2 && Y > y2) angle = floatsub(270.0, angle);
    }
    return floatadd(angle, 90.0);
}
Maybe this, a friend gave it to me.
Reply
#5

IsPlayerInRangeOfPoint is the most sufficient function for distance checking.

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
pawn Код:
stock Float:GetPointAngleToPoint(Float:x2, Float:y2, Float:X, Float:Y)
{
    new Float:DX, Float:DY;
    new Float:angle;
    DX = floatabs(floatsub(x2,X));
    DY = floatabs(floatsub(y2,Y));
    if (DY == 0.0 || DX == 0.0)
    {
        if(DY == 0 && DX > 0) angle = 0.0;
        else if(DY == 0 && DX < 0) angle = 180.0;
        else if(DY > 0 && DX == 0) angle = 90.0;
        else if(DY < 0 && DX == 0) angle = 270.0;
        else if(DY == 0 && DX == 0) angle = 0.0;
    }
    else
    {
        angle = atan(DX/DY);
        if(X > x2 && Y <= y2) angle += 90.0;
        else if(X <= x2 && Y < y2) angle = floatsub(90.0, angle);
        else if(X < x2 && Y >= y2) angle -= 90.0;
        else if(X >= x2 && Y > y2) angle = floatsub(270.0, angle);
    }
    return floatadd(angle, 90.0);
}
Maybe this, a friend gave it to me.
You realize that's for facing angles and not player positions, right?
Reply
#6

I am not sure exactly, but you may wish to give this a try:

pawn Код:
stock IsPlayerInRangeOfPlayer(playerid, otherid, Float:range)
{
    new Float:Pos[3];
    GetPlayerPos(otherid, Pos[0], Pos[1], Pos[2]);
    if(IsPlayerInRangeOfPoint(playerid, range, Pos[0], Pos[1], Pos[2])) return true;
    return false;
}
Reply
#7

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
I am not sure exactly, but you may wish to give this a try:

pawn Код:
stock IsPlayerInRangeOfPlayer(playerid, otherid, Float:range)
{
    new Float:Pos[3];
    GetPlayerPos(otherid, Pos[0], Pos[1], Pos[2]);
    if(IsPlayerInRangeOfPoint(playerid, range, Pos[0], Pos[1], Pos[2])) return true;
    return false;
}
that checks to see if you're near another player^^
Reply
#8

You all fail.

IsPlayerInRangeOfPoint checks if the player is within a certain range.

OP wants to find out what the range is.

You will need a custom stock I'm afraid, but I can't seem to find any
Reply
#9

Quote:
Originally Posted by Calgon
Посмотреть сообщение
IsPlayerInRangeOfPoint is the most sufficient function for distance checking.



You realize that's for facing angles and not player positions, right?
o.0 I fayul! Sorry about that..
Reply
#10

Maybe this?

pawn Код:
forward Float:GetDistanceBetweenPlayers(playerid,targetplayerid);

public 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


Forum Jump:


Users browsing this thread: 1 Guest(s)