public DerbyCountdown()
{
if(DI[STATUS] != DERBY_WAIT) return KillTimer(DI[COUNTDOWN_TIMER]);
if(DI[PLAYERS] <= 0) return CloseDerby();
if(DI[PLAYERS] == 1)
{
DI[COUNTDOWN_COUNTER] = DERBY_TIME_COUNTDOWN + 1;
GameTextForPlayer(playerid, "~g~Waiting for players", 500, 3); //<--------------
return 1;
}
DI[COUNTDOWN_COUNTER] --;
if(DI[COUNTDOWN_COUNTER] <= 0)
{
KillTimer(DI[COUNTDOWN_TIMER]);
if(DI[PLAYERS] == 0) return CloseDerby();
else if(DI[PLAYERS] == 1)
{
GameTextForPlayer(playerid, "~g~Waiting for players", 500, 3); //<--------------
DI[COUNTDOWN_COUNTER] = DERBY_TIME_COUNTDOWN + 1;
KillTimer(DI[COUNTDOWN_TIMER]);
DI[COUNTDOWN_TIMER] = SetTimer("DerbyCountdown", 900, true); //<--------------
}
else StartDerby();
}
return 1;
}
public DerbyCountdown()
{
if(DI[STATUS] != DERBY_WAIT) return KillTimer(DI[COUNTDOWN_TIMER]);
if(DI[PLAYERS] <= 0) return CloseDerby();
if(DI[PLAYERS] == 1)
{
DI[COUNTDOWN_COUNTER] = DERBY_TIME_COUNTDOWN + 1;
for(new playerid = 0, j = GetPlayerPoolSize(); playerid <= j; playerid++)
{
if(IsPlayerConnected(playerid))
{
if(Player[playerid][Mode] == GAME_DERBY)
{
GameTextForPlayer(playerid, "~g~Waiting for players", 500, 3);
}
}
}
return 1;
}
DI[COUNTDOWN_COUNTER] --;
for(new playerid = 0, j = GetPlayerPoolSize(); playerid <= j; playerid++)
{
if(IsPlayerConnected(playerid))
{
if(Player[playerid][Mode] == GAME_DERBY)
{
new str[10]; format(str, 10, "~r~%d_minutes_to_start", DI[COUNTDOWN_COUNTER]);
GameTextForPlayer(playerid, str, 1000, 3);
}
}
}
if(DI[COUNTDOWN_COUNTER] <= 0)
{
KillTimer(DI[COUNTDOWN_TIMER]);
if(DI[PLAYERS] == 0) return CloseDerby();
else if(DI[PLAYERS] == 1)
{
for(new playerid = 0, j = GetPlayerPoolSize(); playerid <= j; playerid++)
{
if(IsPlayerConnected(playerid))
{
if(Player[playerid][Mode] == GAME_DERBY)
{
GameTextForPlayer(playerid, "~g~Waiting for players", 500, 3);
}
}
}
DI[COUNTDOWN_COUNTER] = DERBY_TIME_COUNTDOWN + 1;
KillTimer(DI[COUNTDOWN_TIMER]);
DI[COUNTDOWN_TIMER] = SetTimer("DerbyCountdown", 900, true);
}
else StartDerby();
}
return 1;
}
When you're handling playerid, your procedure should have at minimum 1 parameter, being playerid.
You do not need any loops for that procedure. "playerid" does not need to have a loop in order to use it. You only ever need to use custom playerids when you want to produce a target ID. Even then, you'd use sscanf to evaluate the specific ID you want. Top tip: Design your functionality before you implement it. |
So what should I do exactly, add "for(new playerid = 0, j = GetPlayerPoolSize(); playerid <= j; playerid++) "?
|
for(new xx = 0; xx < MAX_PLAYERS; xx++)
public DerbyCountdown() { for(new xx = 0; xx < MAX_PLAYERS; xx++) { if(Inderby[xx] == 1) // Check the players who all are in derby. { //=== codes } } return 1; }
This callback isn't called per-player. It's the countdown callback which gets called for everyone, thus there must be a loop iterating through all players that are inside the derby.
Just adding playerid as parameter will do nothing. This code isn't meant to be called for every player. |
public DerbyCountdown()
{
if(DI[STATUS] != DERBY_WAIT) return KillTimer(DI[COUNTDOWN_TIMER]);
if(DI[PLAYERS] <= 0) return CloseDerby();
if(DI[PLAYERS] == 1)
{
DI[COUNTDOWN_COUNTER] = DERBY_TIME_COUNTDOWN + 1;
for(new playerid = 0, j = GetPlayerPoolSize(); playerid <= j; playerid++)
{
if(IsPlayerConnected(playerid))
{
if(Player[playerid][Mode] == GAME_DERBY)
{
GameTextForPlayer(playerid, "~g~Waiting for players", 500, 3);
}
}
}
return 1;
}
DI[COUNTDOWN_COUNTER] --;
for(new playerid = 0, j = GetPlayerPoolSize(); playerid <= j; playerid++)
{
if(IsPlayerConnected(playerid))
{
if(Player[playerid][Mode] == GAME_DERBY)
{
new str[10]; format(str, 10, "~r~%d_minutes_to_start", DI[COUNTDOWN_COUNTER]);
GameTextForPlayer(playerid, str, 1000, 3);
}
}
}
if(DI[COUNTDOWN_COUNTER] <= 0)
{
KillTimer(DI[COUNTDOWN_TIMER]);
if(DI[PLAYERS] == 0) return CloseDerby();
else if(DI[PLAYERS] == 1)
{
for(new playerid = 0, j = GetPlayerPoolSize(); playerid <= j; playerid++)
{
if(IsPlayerConnected(playerid))
{
if(Player[playerid][Mode] == GAME_DERBY)
{
GameTextForPlayer(playerid, "~g~Waiting for players", 500, 3);
}
}
}
DI[COUNTDOWN_COUNTER] = DERBY_TIME_COUNTDOWN + 1;
KillTimer(DI[COUNTDOWN_TIMER]);
DI[COUNTDOWN_TIMER] = SetTimer("DerbyCountdown", 900, true);
}
else StartDerby();
}
return 1;
}
public DerbyCountdown()
{
if(DI[STATUS] != DERBY_WAIT) return KillTimer(DI[COUNTDOWN_TIMER]);
if(DI[PLAYERS] <= 0) return CloseDerby();
if(DI[PLAYERS] == 1)
{
DI[COUNTDOWN_COUNTER] = DERBY_TIME_COUNTDOWN + 1;
for(new playerid = 0, j = GetPlayerPoolSize(); playerid <= j; playerid++)
{
if(IsPlayerConnected(playerid))
{
if(Player[playerid][Mode] == GAME_DERBY)
{
GameTextForPlayer(playerid, "~g~Waiting for players", 500, 3);
}
}
}
return 1;
}
DI[COUNTDOWN_COUNTER] --;
for(new playerid = 0, j = GetPlayerPoolSize(); playerid <= j; playerid++)
{
if(IsPlayerConnected(playerid))
{
if(Player[playerid][Mode] == GAME_DERBY)
{
new str[10]; format(str, 10, "~r~%d_minutes_to_start", DI[COUNTDOWN_COUNTER]);
GameTextForPlayer(playerid, str, 1000, 3);
}
}
}
if(DI[COUNTDOWN_COUNTER] <= 0)
{
KillTimer(DI[COUNTDOWN_TIMER]);
if(DI[PLAYERS] == 0) return CloseDerby();
else if(DI[PLAYERS] == 1)
{
for(new playerid = 0, j = GetPlayerPoolSize(); playerid <= j; playerid++)
{
if(IsPlayerConnected(playerid))
{
if(Player[playerid][Mode] == GAME_DERBY)
{
GameTextForPlayer(playerid, "~g~Waiting for players", 500, 3);
}
}
}
DI[COUNTDOWN_COUNTER] = DERBY_TIME_COUNTDOWN + 1;
KillTimer(DI[COUNTDOWN_TIMER]);
DI[COUNTDOWN_TIMER] = SetTimer("DerbyCountdown", 900, true);
}
else StartDerby();
}
return 1;
}
That is, I must use three times "for (new i = 0, j = GetPlayerPoolSize (); i <= j; i ++)"?
PHP код:
|
foreach (new i : Player) if (Player[i][Mode] == GAME_DERBY) GameTextForPlayer(playerid, "~g~Waiting for players", 500, 3);
No, foreach is not widely used and I do not like it, besides "GetPlayerPoolSize" only travels through the connected players.
|
No sir. GetPlayerPoolSize give you the hightest id of connected players. You need to loop through ID 0 to this ID and check is every id is a bot nor is connected.
Foreach (Player - which is an iterator ; it exists Actor and NPC) doesn't do that. It loop through all connected players only. y_iterate allows you to use iterator. You can take look here if you are interested: https://sampforum.blast.hk/showthread.php?tid=570937 |
That is, I must use three times "for (new i = 0, j = GetPlayerPoolSize (); i <= j; i ++)"?
Please, I need a quick help. |
public DerbyCountdown()
{
if(DI[STATUS] != DERBY_WAIT) return KillTimer(DI[COUNTDOWN_TIMER]);
if(DI[PLAYERS] <= 0) return CloseDerby();
if(DI[PLAYERS] == 1)
{
DI[COUNTDOWN_COUNTER] = DERBY_TIME_COUNTDOWN + 1;
for(new playerid = 0, j = GetPlayerPoolSize(); playerid <= j; playerid++)
{
if(IsPlayerConnected(playerid))
{
if(Player[playerid][Mode] == GAME_DERBY)
{
GameTextForPlayer(playerid, "~g~Waiting for players", 500, 3);
}
}
}
return 1;
}
DI[COUNTDOWN_COUNTER] --;
if(DI[COUNTDOWN_COUNTER] > 0)
{
for(new playerid = 0, j = GetPlayerPoolSize(); playerid <= j; playerid++)
{
if(IsPlayerConnected(playerid))
{
if(Player[playerid][Mode] == GAME_DERBY)
{
new str[10]; format(str, 10, "~r~%d_minutes_to_start", DI[COUNTDOWN_COUNTER]);
GameTextForPlayer(playerid, str, 1000, 3);
}
}
}
}
else
{
KillTimer(DI[COUNTDOWN_TIMER]);
if(DI[PLAYERS] == 0) return CloseDerby();
else if(DI[PLAYERS] == 1)
{
for(new playerid = 0, j = GetPlayerPoolSize(); playerid <= j; playerid++)
{
if(IsPlayerConnected(playerid))
{
if(Player[playerid][Mode] == GAME_DERBY)
{
GameTextForPlayer(playerid, "~g~Waiting for players", 500, 3);
}
}
}
DI[COUNTDOWN_COUNTER] = DERBY_TIME_COUNTDOWN + 1;
KillTimer(DI[COUNTDOWN_TIMER]);
DI[COUNTDOWN_TIMER] = SetTimer("DerbyCountdown", 900, true);
}
else StartDerby();
}
return 1;
}