Player near another player -
SumX - 14.08.2012
Hello!
How can I check if a player is very close/near to another player?
Example: Player1 can use command /givemoney to give some money to Player2,only if they are very close.
Thank you!
Re: Player near another player -
BigAl - 14.08.2012
I'm sure there's loads of things around the forums that basically tell you either how to do this... or have it right there in front of you? Check the forums, I'm sure you can find something
Re: Player near another player -
IceMeteor - 14.08.2012
You can combine GetPlayerPos with IsPlayerInRangeOfPoint, like this
pawn Код:
CMD:givemoney(playerid, params[])
{
new amount, Float:Pos[3];
if(sscanf(params, "ui", targetid, amount)) return SendClientMessage(playerid, -1, "[USAGE] /givemoney <playerid> <amount>");
GetPlayerPos(targetid, Pos[0], Pos[1], Pos[2]);
if(IsPlayerInRangeOfPoint(playerid, 5, Pos[0], Pos[1], Pos[2])
{
GivePlayerMoney(targetid, amount);
GivePlayerMoney(playerid, -amount);
}
return 1;
}
Re: Player near another player -
SumX - 14.08.2012
Thank you guys,and I'm sorry my behavior.I had a stupid problem with my Pawn,every time when I was compiling: "Program has stopped working!".I was angry,now this is solved.Thank you for answers,I will apply them.
Re: Player near another player -
Kindred - 14.08.2012
pawn Код:
stock PlayerToPlayer(playerid,targetid,Float:distance)
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid,x,y,z);
if(IsPlayerInRangeOfPoint(targetid,distance,x,y,z))
{
return true;
}
return false;
}
I also suggest using something like this so you do not need to use a crap ton of lines, and it is also faster.
I made this myself, after seeing as the old PlayerToPlayer function I had I lost. Although, I am practicly CERTAIN this is the exact same as it.
Use it like so:
pawn Код:
if(PlayerToPlayer(playerid,i,7)) //Playerid is the playerid, i is a looped amount of players, and 7 is distance
{
//Something to do if they are in range of 7
Try something like that if you want to make it easier on yourself.