19.06.2014, 14:28
(
Последний раз редактировалось RedFusion; 23.06.2014 в 18:08.
)
Loop through the connected players only, instead of looping through every playerid with this tiny script.
Example usage:
pawn Код:
/******************************************************************************/
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
/******************************************************************************/
pawn Код:
for(new i = 0; i < GetConnectedPlayers; i ++)
{
new playerid = GetIndexPlayerID(i);
printf("playerid %i is connected", playerid);
}