help | Some question
#1

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!
Reply
#2

someone?
Reply
#3

Yes.

if i remember it loops through all player.

I don't remember.
Reply
#4

i really need help.. please someone can give me that stock?
Reply
#5

Just made this, compiles fine and should be working.

PHP код:
stock closestplayer(playerid,&Float:distance 9999999.0)
{
    static 
playerFloat:,Float:,Float:Float:olddistance closestid;
    for(
player GetMaxPlayers(); player > -1; --player)
    {
        if(!
IsPlayerConnected(player)) continue;
        
GetPlayerPos(player,x,y,z);
        if((
olddistance GetPlayerDistanceFromPoint(playeridxyz)) < 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); 
Reply
#6

PHP код:
    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 
iiMAX_PLAYERSi++)
{
    if(
IsPlayerConnected(i))
{
    new 
Float:range;
    
=  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;
}
}

look at this code, i tried to check the closest player, and to his pos the object will move, it create too many objects, and then crash the game
Reply
#7

Quote:
Originally Posted by Bufige
Посмотреть сообщение
Just made this, compiles fine and should be working.

PHP код:
// CODE 
That code always returns 0!, if you use it like in your example....
pawn Код:
#define INFINITY (Float: 0x7F800000)
pawn Код:
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;
}
Quote:
Originally Posted by tomsalmon
Посмотреть сообщение
PHP код:
// CODE 
look at this code, i tried to check the closest player, and to his pos the object will move, it create too many objects, and then crash the game
Remove the loop... you only need to call the function once
Reply
#8

You can bring me a loop to check each server except playerid players, because it check the closest of playerid to playerid...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)