12.10.2012, 13:29
There is any stock to check out all players on the server who the player closest to playerid?
i'm really need that stock.. thanks for helpers!
i'm really need that stock.. thanks for helpers!
stock closestplayer(playerid,&Float:distance = 9999999.0)
{
static player, Float:x ,Float:y ,Float:z , Float:olddistance , closestid;
for(player = GetMaxPlayers(); player > -1; --player)
{
if(!IsPlayerConnected(player)) continue;
GetPlayerPos(player,x,y,z);
if((olddistance = GetPlayerDistanceFromPoint(playerid, x, y, z)) < distance)
{
distance = olddistance;
closestid = player;
}
}
return closestid;
}
// usage:
new id,Float:dis;
id = closestplayer(playerid,dis);
printf("Player ID - %d, Player Distance %f",id,dis);
if(IsKeyJustDown(KEY_CTRL_BACK,newkeys,oldkeys) && NeonFire[playerid] == 1)
{
if(BlockNeon[playerid] == 1) return 0;
new Float:v_x,Float:v_y,Float:v_z,
Float:x,Float:y,Float:z,
Float:pX,Float:pY,Float:pZ,
Float:iX,Float:iY,Float:iZ;
for(new i; i< MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new Float:range;
i = closestplayer(playerid,range);
GetPlayerCameraFrontVector(playerid,v_x,v_y,v_z);
GetPlayerCameraPos(playerid,x,y,z);
GetPlayerPos(playerid,pX,pY,pZ);
GetPlayerPos(i,iX,iY,iZ);
T_SetPlayerLookAt(playerid,v_x*500.0+x,v_y*500.0+y);
NeonObj = CreateObject(18648,pX,pY,pZ,0,0,0,200);
MoveObject(NeonObj,iX*500.0+iX,iY*500.0+y,iZ,3,0.0,0.0,0.0);
NeonTimer = SetTimerEx("CheckPos",5000,0,"i",i);
BlockNeon[playerid] = 1;
}
}
}
Just made this, compiles fine and should be working.
PHP код:
|
#define INFINITY (Float: 0x7F800000)
stock GetClosestPlayer(playerid, & Float: distance) {
new
Float: X,
Float: Y,
Float: Z
;
if(GetPlayerPos(playerid, X, Y, Z)) {
new
i,
Float: dis,
closest = INVALID_PLAYER_ID
;
for(distance = INFINITY; i != MAX_PLAYERS; ++i) {
if(0.0 < (dis = GetPlayerDistanceFromPoint(i, X, Y, Z)) < distance) {
distance = dis;
closest = i;
}
}
return closestid;
}
return INVALID_PLAYER_ID;
}