/******************************************************************************/
new pl_Players[MAX_PLAYERS] = {INVALID_PLAYER_ID, ...},
pl_Connected,
pl_MaxPlayers;
/******************************************************************************/
#define GetIndexPlayerID(%0) pl_Players[%0]
#define GetConnectedPlayers pl_Connected
/******************************************************************************/
public OnFilterScriptInit()
{
pl_MaxPlayers = GetMaxPlayers();
for(new playerid; playerid < pl_MaxPlayers; playerid ++)
{
if(IsPlayerConnected(playerid))
{
pl_Players[pl_Connected] = playerid;
pl_Connected ++;
}
}
#if defined pl_OnFilterScriptInit
return pl_OnFilterScriptInit();
#else
return 1;
#endif
}
#if defined pl_OnFilterScriptInit
forward pl_OnFilterScriptInit();
#endif
#if defined _ALS_OnFilterScriptInit
#undef OnFilterScriptInit
#else
#define _ALS_OnFilterScriptInit
#endif
#define OnFilterScriptInit pl_OnFilterScriptInit
/******************************************************************************/
public OnGameModeInit()
{
pl_MaxPlayers = GetMaxPlayers();
#if defined pl_OnGameModeInit
return pl_OnGameModeInit();
#else
return 1;
#endif
}
#if defined pl_OnGameModeInit
forward pl_OnGameModeInit();
#endif
#if defined _ALS_OnGameModeInit
#undef OnGameModeInit
#else
#define _ALS_OnGameModeInit
#endif
#define OnGameModeInit pl_OnGameModeInit
/******************************************************************************/
public OnPlayerConnect(playerid)
{
pl_Players[pl_Connected] = playerid;
pl_Connected ++;
#if defined pl_OnPlayerConnect
return pl_OnPlayerConnect(playerid);
#else
return 1;
#endif
}
#if defined pl_OnPlayerConnect
forward pl_OnPlayerConnect(playerid);
#endif
#if defined _ALS_OnPlayerConnect
#undef OnPlayerConnect
#else
#define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect pl_OnPlayerConnect
/******************************************************************************/
public OnPlayerDisconnect(playerid, reason)
{
pl_Connected = 0;
for(new id; id < pl_MaxPlayers; id ++)
{
if(IsPlayerConnected(id) && playerid != id)
{
pl_Players[pl_Connected] = id;
pl_Connected ++;
}
}
for(new index = pl_Connected; index < pl_MaxPlayers; index ++)
pl_Players[index] = INVALID_PLAYER_ID;
#if defined pl_OnPlayerDisconnect
return pl_OnPlayerDisconnect(playerid, reason);
#else
return 1;
#endif
}
#if defined pl_OnPlayerDisconnect
forward pl_OnPlayerDisconnect(playerid, reason);
#endif
#if defined _ALS_OnPlayerDisconnect
#undef OnPlayerDisconnect
#else
#define _ALS_OnPlayerDisconnect
#endif
#define OnPlayerDisconnect pl_OnPlayerDisconnect
/******************************************************************************/
for(new i = 0; i < GetConnectedPlayers; i ++)
{
new playerid = GetIndexPlayerID(i);
printf("playerid %i is connected", playerid);
}
What happens if, let's say server has 10 players,
5 quit. Online: 0,1,5,6,9 |
for(new id = 0; id < pl_MaxPlayers; id ++)
{
if(IsPlayerConnected(id) && playerid != id)
pl_Players[pl_Connected++] = id;
else
pl_Players[id] = INVALID_PLAYER_ID;
}
pawn Код:
|
Playerid 0 Connected, pl_Players[0] = 0 Playerid 1 Not connected, pl_Players[1] = INVALID_PLAYER_ID Playerid 2 Connected, pl_Players[1] = 2 Playerid 3 Connected, pl_Players[2] = 3 Playerid 4 Not connected, pl_Players[4] = INVALID_PLAYER_ID ... And the rest of the players are disconnected.
why and? y_iterate and foreach are the same. y_iterate is just a name to go with YSI.
|