Quote:
Originally Posted by Natsheh
you could....
PHP Code:
RespawnAll(id) { if(get_user_flags(id) & PLUGIN_ADMIN_LEVEL2) { new iPlayers[32], iNum; get_players( iPlayers, iNum, "bh"); for(new i; i < iNum; i++) { fm_respawnplayer(iPlayers[i]); } client_print(id, print_chat, "%s %s", Prefix, iNum ? ("You have just revived %d player%s", iNum, iNum > 1 ? "s" : ""):"All players are alive!") } }
|
His code looks better than yours.
In your code there are some problems:
1. It will alloc 'i' on stack and reset it even if iNum is 0, so there is no reason to move this condition in another place. Your code will check this condition two times too (in loop and in print). If you don't like repeating print_chat and Prefix you can create a separate PrintToChat(player, format, ...) function/macro that would include print_chat arg and Prefix.
2. Better explicitly reset 'i' than implicitly.
3. We should exclude not only HLTV, but all spectators and UNA. We should include only dead CT and dead TR. There is no flag for this, so we can't do it via get_players directly.
So:
PHP Code:
new iPlayers[32], iNum;
get_players(iPlayers, iNum, "bh");
new excludedCount = 0;
for(new i = 0; i < iNum; i++)
{
new CsTeams:team = cs_get_user_team(iPlayers[i]);
if (team == CS_TEAM_SPECTATOR || team == CS_TEAM_UNASSIGNED) {
excludedCount++;
continue;
}
fm_respawnplayer(iPlayers[i]);
}
iNum -= excludedCount;
HLTV flag is not necessary now, but it excludes HLTV right away (some optimization, but this is function not frequently called, so optimizations make no sense here).
__________________