Team players
Posted: 2013 Jun 13 15:53
Kaip geriausiai suskaičiuoti prisijungusiu žaidėjų skaičių, pasirinkusių komandą. Nes get_playersnum priskaičiuoja ir UNASSIGNED žaidėjus.
Code: Select all
get_players(players,num,"e","CT")get_players(players,num,"e","TERRORIST")
Code: Select all
stock GetActivePlayersCount() { new count, id, maxplayers = get_maxplayers() for (id=1; id<maxplayers; id++) if (get_user_team(id) > 0) count++ return count;}
Code: Select all
GetActivePlayerCount(){ new players[32], n, count; get_players(players, n, "ceh", "TERRORIST"); count += n; get_players(players, n, "ceh", "CT"); count += n; get_players(players, n, "ceh", "SPECTATOR"); count += n; return count;}
Code: Select all
GetActivePlayerCount(){ new players[32], all, uns get_players(players, all, "ch") get_players(players, uns, "ceh", "UNASSIGNED") return all - uns}
get_players ne stock'as.InvIs wrote: Kartais get_players stock'as nenaudoja to paties "for" ir neina per visus žaidėjus? Jei taip, tai arno būdas optimaliausias.
Code: Select all
static cell AMX_NATIVE_CALL get_players(AMX *amx, cell *params) /* 4 param */{ int iNum = 0; int ilen; char* sptemp = get_amxstring(amx, params[3], 0, ilen); int flags = UTIL_ReadFlags(sptemp); cell *aPlayers = get_amxaddr(amx, params[1]); cell *iMax = get_amxaddr(amx, params[2]); int team = 0; if (flags & 48) { sptemp = get_amxstring(amx, params[4], 0, ilen); if (flags & 16) { if (flags & 64) team = g_teamsIds.findTeamId(sptemp); else team = g_teamsIds.findTeamIdCase(sptemp); } } for (int i = 1; i <= gpGlobals->maxClients; ++i) { CPlayer* pPlayer = GET_PLAYER_POINTER_I(i); if (pPlayer->ingame) { if (pPlayer->IsAlive() ? (flags & 2) : (flags & 1)) continue; if (pPlayer->IsBot() ? (flags & 4) : (flags & 8)) continue; if ((flags & 16) && (pPlayer->teamId != team)) continue; if ((flags & 128) && (pPlayer->pEdict->v.flags & FL_PROXY)) continue; if (flags & 32) { if (flags & 64) { if (stristr(pPlayer->name.c_str(), sptemp) == NULL) continue; } else if (strstr(pPlayer->name.c_str(), sptemp) == NULL) continue; } aPlayers[iNum++] = i; } } *iMax = iNum; return 1;}
Code: Select all
static cell AMX_NATIVE_CALL get_user_team(AMX *amx, cell *params) /* 3 param */{ int index = params[1]; if (index < 1 || index > gpGlobals->maxClients) return -1; CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); if (pPlayer->ingame) { // SidLuke, DoD fix if (g_bmod_dod) { int iTeam = pPlayer->pEdict->v.team; if (params[3]) { const char *szTeam = ""; switch (iTeam) { case 1: szTeam = "Allies"; break; case 2: szTeam = "Axis"; break; } set_amxstring(amx, params[2], szTeam, params[3]); } return iTeam; } // if (params[3]) { set_amxstring(amx, params[2], pPlayer->team.c_str(), params[3]); } return pPlayer->teamId; } return -1;}
Code: Select all
static cell AMX_NATIVE_CALL is_user_connected(AMX *amx, cell *params) /* 1 param */{ int index = params[1]; if (index < 1 || index > gpGlobals->maxClients) return 0; CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); return (pPlayer->ingame ? 1 : 0);}
Code: Select all
stock GetActivePlayersCount() { new count, id, maxplayers = get_maxplayers() for (id=1; id<maxplayers; id++) if (get_user_team(id) > 0) count++ return count;}
Code: Select all
static cell AMX_NATIVE_CALL get_playersnum(AMX *amx, cell *params){ if (!params[1]) return g_players_num; int a = 0; for (int i = 1; i <= gpGlobals->maxClients; ++i) { CPlayer* pPlayer = GET_PLAYER_POINTER_I(i); if (pPlayer->initialized && (GETPLAYERUSERID(pPlayer->pEdict) > 0)) ++a; } return a;}
Menuodas159 wrote:Who will win?