Checking who's near you. -
Shockey HD - 11.05.2012
How am i able to check to see who is near the person that type's /near and it displays there name in a format?
For an example, Lets say Tim is 10 feet away from me, I type /near and it says, "Tim is near you."?
Re: Checking who's near you. -
JaKe Elite - 11.05.2012
use GetPlayerPos and IsPlayerInRangeOfPoint with Float:Distance 10 if thats what you want?
Re: Checking who's near you. -
Yuryfury - 11.05.2012
Use a Get Distance function:
pawn Код:
stock Float: GetDistanceToPoint(playerid,Float: X2,Float:Y2 ,Float: Z2)
{
new Float:X,Float:Y,Float:Z;
GetPlayerPos(playerid,X,Y,Z);
return floatsqroot ( floatpower ( floatabs ( floatsub ( X , X2 ) ) , 2 ) + floatpower ( floatabs ( floatsub ( Y , Y2 ) ) , 2 ) + floatpower ( floatabs ( floatsub ( Z , Z2 ) ) , 2 ) );
}
================================================== ==================================
There are better distance functions (you can try IsPlayerInRangeOfPoint but I personally had issues with it. There are other distance functions around if you search a little), this is the one I had at hand.
In the command, create a loop through all the players and get the distance. If the distance is less than 10, Get the player name and format a message.
================================================== ==================================
A quick example I made up:
pawn Код:
stock Float: GetDistanceToPoint(playerid,Float: X2,Float:Y2 ,Float: Z2)
{
new Float:X,Float:Y,Float:Z;
GetPlayerPos(playerid,X,Y,Z);
return floatsqroot ( floatpower ( floatabs ( floatsub ( X , X2 ) ) , 2 ) + floatpower ( floatabs ( floatsub ( Y , Y2 ) ) , 2 ) + floatpower ( floatabs ( floatsub ( Z , Z2 ) ) , 2 ) );
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/nearme", cmdtext, true, 10) == 0)
{
new Float:pos[3];
GetPlayerPos(playerid,ppos[0],ppos[1],ppos[2]);
for (new i = 0; i<MAX_PLAYERS; i++)
{
if(GetDistanceToPoint(i,pos[0],pos[1],pos[2])<10)
{
new pname[MAX_PLAYER_NAME];
GetPlayerName(i,pname,MAX_PLAYER_NAME);
new string[64];
format(string,sizeof(string),"%s(%i) is near you!",pname,i);
SendClientMessage(playerid,0xFFFF00AA,string);
}
}
return 1;
}
return 0;
}
Re: Checking who's near you. -
ReneG - 11.05.2012
You don't need GetDistance.
Using
foreach.
pawn Код:
CMD:near(playerid, params[])
{
new
Float:x, // floats for the playerid's position
Float:y,
Float:z,
name[24] // a new string for the all the names
;
SendClientMessage(playerid, -1, "-------[ Players Near You ]-------");
GetPlayerPos(playerid, x, y, z); // We get the position of the player and store them into the floats
foreach(Player, i) // we loop through all the players
{
// and if all the players are within 10 feet of the playerid who typed this command's position.
if(IsPlayerInRangeOfPoint(i, 10.0 ,x, y, z))
{
// then it will get their name and send it to who ever typed the command
GetPlayerName(i, name, 24);
SendClientMessage(playerid, -1, name);
// since this is a loop
// this code will be repeated
// for EVERY player that is near whoever typed the command
}
}
return 1;
}
Re: Checking who's near you. -
Shockey HD - 11.05.2012
Thank you very much.