23.12.2010, 10:18
Can someone give me that function? i searched but no results
stock GetClosestPlayer(playerid,Float:limit)
{
new Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2;
GetPlayerPos(playerid,x1,y1,z1);
new Float:Range = 999.9;
new id = -1;
foreach(Player,i)
{
if(playerid != i)
{
GetPlayerPos(i,x2,y2,z2);
new Float:Dist = GetDistanceBetweenPoints(x1,y1,z1,x2,y2,z2);
if(floatcmp(Range,Dist) == 1 && floatcmp(limit,Range) == 1)
{
Range = Dist;
id = i;
}
}
}
return id;
}
stock Float:GetDistanceBetweenPoints(Float:rx1,Float:ry1,Float:rz1,Float:rx2,Float:ry2,Float:rz2)
{
return floatadd(floatadd(floatsqroot(floatpower(floatsub(rx1,rx2),2)),floatsqroot(floatpower(floatsub(ry1,ry2),2))),floatsqroot(floatpower(floatsub(rz1,rz2),2)));
}
stock ProxDetectorS(Float:radi, playerid, targetid) //[GameMode] The GodFather Function
{
if(IsPlayerConnected(playerid)&&IsPlayerConnected(targetid))
{
new Float:posx, Float:posy, Float:posz;
new Float:oldposx, Float:oldposy, Float:oldposz;
new Float:tempposx, Float:tempposy, Float:tempposz;
GetPlayerPos(playerid, oldposx, oldposy, oldposz);
GetPlayerPos(targetid, posx, posy, posz);
tempposx = (oldposx -posx);
tempposy = (oldposy -posy);
tempposz = (oldposz -posz);
if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
{
return 1;
}
}
return 0;
}
this is from someone else, I think lucirado or something like it.
pawn Код:
|
public GetClosestPlayer(p1)
{
new Float:dis,Float:dis2,player;
player = -1;
dis = 99999.99;
foreach(Player,x)
{
if(x != p1)
{
dis2 = GetDistanceBetweenPlayers(x,p1);
if(dis2 < dis && dis2 != -1.00)
{
dis = dis2;
player = x;
}
}
}
return player;
}
new closest = GetClosestPlayer(playerid);
if(closest == -1 || GetDistanceBetweenPlayers(playerid,closest) > 7) return SendClientMessage(playerid,COLOR_RED,"There are no players closes enough");