30.07.2012, 08:18
(
Последний раз редактировалось Roko_foko; 30.07.2012 в 09:42.
)
Hi guys.
As title says I need your opinion.
Is this good way of looping all players?
Is there any way it can be improved?
Do you see a situation when this will not work?
Thank you.
Don't know if this is in right section. If not, I apologize and I would like an administrator to move the thread to right section.
Thank you for your attention.
EDIT: Please reply guys. You don't need to read first page as I see it as useless.
As title says I need your opinion.
Is this good way of looping all players?
Is there any way it can be improved?
Do you see a situation when this will not work?
Thank you.
pawn Код:
new AllPlayers[MAX_PLAYERS+1]=-1;//added after 1st reply, +1 so when there is 500 players, it still has end(-1)
#define foreach(%0) for(%0=0;AllPlayers[%0]!=-1;%0++)
public OnPlayerConnect(playerid)
{
if(IsPlayerNPC(playerid)==0)
{
for(i=0;AllPlayers[i]!=-1;i++){}//finding first cell that does not have any player id.
AllPlayers[i]=playerid;// save the playerid
AllPlayers[i+1]=-1;// make sure there is one "free" cell for next player, and -1 is also EOS(only to this array)
}
//rest of the code
}
public OnPlayerDisconnect(playerid, reason)
{
if(!IsPlayerNPC(playerid))
{
for(i=0;AllPlayers[i]!=playerid;i++){}//finding the cell where is stored playerid that has just been disconnected
while(AllPlayers[i]!=-1)AllPlayers[i]=AllPlayers[i+1];//cleaning one( playerid -disconnected) cell and every cell after it moving one place to left.
}
}
//usage:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp("/printfallids",cmdtext)==0)
{
new i;
foreach(i)printf("%d",AllPlayers[i]);
return 1;
}
}
Thank you for your attention.
EDIT: Please reply guys. You don't need to read first page as I see it as useless.