30.01.2012, 09:44
Title says it, how can I do this? To check if a player is in certain range to another player?
CMD:pay(playerid, params[])
{
new id;
new money2;
new Float:XX1, Float:YY1, Float:ZZ1;
if(!sscanf(params, "ud", id, money2))
{
new string[128];
GetPlayerPos(id, XX1, YY1, ZZ1);
if(IsPlayerInRangeOfPoint(playerid, 5.0, XX1, YY1, ZZ1))
{
if(GetPlayerMoney(playerid) >= money2 + 50)
{
new name[MAX_PLAYER_NAME], pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
GetPlayerName(id, pname, sizeof(pname));
GivePlayerMinusCash(playerid, money2);
GivePlayerCash(id, money2);
format(string, sizeof(string), "**%s Takes out some money and gives it to %s ((%d))", name, pname, money2);
ProxDetector(15.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
return 1;
}
else return SendClientMessage(playerid, COLOR_GREY, "Not enough money! You must have at least $50 at the end of the transaction!");
}
else return SendClientMessage(playerid, COLOR_GREY, " You are not near the other player! ");
}
else return SendClientMessage(playerid, COLOR_GREY, " UASGE: /pay [Player ID/ PlayerName] [Ammount] ");
}
Title says it, how can I do this? To check if a player is in certain range to another player?
|
forward GetClosestPlayerToPlayer(playerid);
public GetClosestPlayerToPlayer(playerid)
{
new Float:dist = 1000.0;
new targetid = INVALID_PLAYER_ID;
new Float:x1,Float:y1,Float:z1;
new Float:x2,Float:y2,Float:z2;
new Float:tmpdis;
GetPlayerPos(playerid,x1,y1,z1);
for(new i=0;i<MAX_PLAYERS;i++)
{
if(i == playerid) continue;
GetPlayerPos(i,x2,y2,z2);
tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
if(tmpdis < dist)
{
dist = tmpdis;
targetid = i;
}
}
return targetid;
}
OK
First set use GetPos on both players by making 6 new floats Then use IsInRangeOfPoint(playerid, [amount], Other Player float1, Other Player float2, Other Player float3 very simple example: pawn Code:
|
stock 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));
}
Pay command? He asked about distance
Here you are. pawn Code:
|
GetPlayerDistanceFromPoint(playerid, Float:x, Float:y, Float:z);
new Float:x,Float:y,Float:z;
GetPlayerPos(playerid,x,y,z);
x = GetPlayerDistanceFromPoint(playerid,x,y,z);
//X is the distance