How to detect if a player is in range of another player? -
rangerxxll - 10.03.2014
Hello. I've tried looping through all players, detecting if I'm in-range of anyone. But upon doing that, it gives EVERYONE a fish. I'm currently creating a "give" option via dialog, and want it to give the nearest-player a fish.
How do I detect if a player is near another player? Is there a function out there somewhere similar to this:
pawn Код:
IsPlayerInRangeOfPlayer(playerid, Float:distance, player2)
Thanks for any help.
Respuesta: How to detect if a player is in range of another player? -
angelxeneize - 10.03.2014
You want this?
Quote:
new Float:X, Float:Y, Float:Z;
GetPlayerPos(otherplayerid,X,Y,Z);
if(IsPlayerInRangePoint(playerid,10,X,Y,Z);
{
your code
}
|
Re: How to detect if a player is in range of another player? -
rangerxxll - 10.03.2014
Whatever works, yes.
Thank you. Would also be cool if you could explain the code to me so i could learn.
Re : How to detect if a player is in range of another player? -
Golimad - 10.03.2014
if(GetDistanceBetweenPlayers(playerid,otherplayer) < x) // x should be something like 10 ; 10 meters ..
Re: How to detect if a player is in range of another player? -
Abagail - 10.03.2014
Okay, so you could make a stock for this if you want to do it like this:
Код:
stock IsPlayerInRangeOfPlayer(playerid, Float: range, player2)
{
if(!IsPlayerConnected(player2)) return 0;
new Float: x, Float: y, Float: z;
GetPlayerPos(playerid, x, y, z);
if(IsPlayerInRangeOfPoint(player2, range, x, y, z) return 1;
else if(!IsPlayerInRangeOfPoint(player2, range, x, y, z) return 0;
}
So what it does is use x, y, z to detect the first player's position. Then if they are in range of that position you'll return 1 if not just return 0.
An example of how you can use this is:
Detecting if they ARE in range: if(IsPlayerInRangeOfPlayer(playerid, 25.0, player2);
if they're not... if(!IsPlayerInRangeOfPlayer... Bla bla bla
Hope I explained this throughly enough!
Re: How to detect if a player is in range of another player? -
Jefff - 10.03.2014
Quote:
Originally Posted by Abagail
Код:
if(IsPlayerInRangeOfPoint(player2, range, x, y, z) return 1;
else if(!IsPlayerInRangeOfPoint(player2, range, x, y, z) return 0;
|
You can use just
pawn Код:
return IsPlayerInRangeOfPoint(player2, range, x, y, z);
Re: How to detect if a player is in range of another player? -
Abagail - 10.03.2014
@Jeff, so true. Thanks for informing me about it. Wasn't thinkin' bout' that.
Re: How to detect if a player is in range of another player? -
rangerxxll - 10.03.2014
Thanks for the help. I modified the stock in order to remove a few errors. But upon using it, i get a error saying "player2" isn't defined.
EDIT: I'm trying to make it automatically detect the closest player.
pawn Код:
stock IsPlayerInRangeOfPlayer(playerid, Float: range, player2)
{
if(!IsPlayerConnected(player2)) return 0;
new Float: x, Float: y, Float: z;
GetPlayerPos(playerid, x, y, z);
if(IsPlayerInRangeOfPoint(player2, range, x, y, z)) return 1;
else if(!IsPlayerInRangeOfPoint(player2, range, x, y, z)) return 0;
return 1;
}