#2

Aca te dejo un pequeсo script con la funcion para elejir un jugador al azar.
pawn Код:
#include <a_samp>

#define COUNT_BOTS  //comentar esta linea para que el script no cuente a los bots NPC.

new pCount;

public OnPlayerConnect(playerid)
{
    #if defined COUNT_BOTS
        pCount++;
    #else
        if(!IsPlayerNPC(playerid))
            pCount++;
       
    #endif
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    #if defined COUNT_BOTS
        pCount++;
    #else
        if(!IsPlayerNPC(playerid))
            pCount++;
    #endif
    return 1;
}

stock RandomUser()
{
    if(!pCount)
        return INVALID_PLAYER_ID;
    if(pCount < 2){
        new tmp, counter;
        while(!IsPlayerConnected(tmp)){
            if(tmp == GetMaxPlayers()){
                counter++;
                if(counter>=2)
                    return INVALID_PLAYER_ID;
                tmp=0;                 
            }
            tmp++;
        }
        return tmp;
    }
    new tmp = random(GetMaxPlayers());
    while(!IsPlayerConnected{tmp})tmp = random(GetMaxPlayers());
    return tmp;
}
Reply


Messages In This Thread
Duda - by adrianxd - 08.06.2012, 19:35
Respuesta: Duda - by TheChaoz - 09.06.2012, 01:17
Respuesta: Duda - by adrianxd - 09.06.2012, 19:20
Respuesta: Duda - by TheChaoz - 09.06.2012, 19:27

Forum Jump:


Users browsing this thread: 1 Guest(s)