How can I see if target is in range?
#1

I made a /pay command but i want to see if targetid is in ranger of playerid how can i do that and what includes will i need?
Reply
#2

pawn Код:
stock IsPlayerCloseToPlayer(playerid, lookupid, Float:distance)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(lookupid, x, y, z);
    if(IsPlayerInRangeOfPoint(playerid, distance, x, y, z) && GetPlayerInterior(playerid) == GetPlayerInterior(lookupid) && \
    GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(lookupid) && GetPlayerState(playerid) != PLAYER_STATE_SPECTATING &&
    GetPlayerState(lookupid) != PLAYER_STATE_SPECTATING) return true;
    return false;
}
Reply
#3

First of all, you need a stock, like so:

Код:
stock GetDistanceBetweenPlayers(playerid, playerid2)
{
	new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
	new Float:dis;
	GetPlayerPos(playerid,x1,y1,z1);
	GetPlayerPos(playerid2,x2,y2,z2);
	dis = floatsqroot((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)+(z2-z1)*(z2-z1));
	return floatround(dis);
}
Once you have got a stock like the above, which measures the distance between one player and the other, you would do the following:

Create the command, which would be "
Код:
CMD:pay(playerid, params[])
".

Afterwards, we have to create a 1 time variable, which would hold the ID of the player who is being paid.

Example: new id;

Once you have done everything including both IDs and the initial command itself, measure the distance between both players, via the following:

if(GetDistanceBetweenPlayers(playerid, id) < 7) - You can choose whichever range you need.

That is pretty much all there is too it.
Reply
#4

Quote:
Originally Posted by IzadorO
Посмотреть сообщение
First of all, you need a stock, like so:

Код:
stock GetDistanceBetweenPlayers(playerid, playerid2)
{
	new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
	new Float:dis;
	GetPlayerPos(playerid,x1,y1,z1);
	GetPlayerPos(playerid2,x2,y2,z2);
	dis = floatsqroot((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)+(z2-z1)*(z2-z1));
	return floatround(dis);
}
Once you have got a stock like the above, which measures the distance between one player and the other, you would do the following:

Create the command, which would be "
Код:
CMD:pay(playerid, params[])
".

Afterwards, we have to create a 1 time variable, which would hold the ID of the player who is being paid.

Example: new id;

Once you have done everything including both IDs and the initial command itself, measure the distance between both players, via the following:

if(GetDistanceBetweenPlayers(playerid, id) < 7) - You can choose whichever range you need.

That is pretty much all there is too it.
Use that function in different virtual worlds or even spectating the player and see what happens (if you don't know yet).

And it's not a stock, it's a function.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)