Page 1 of 2

Team players

Posted: 2013 Jun 13 15:53
by xedga
Kaip geriausiai suskaičiuoti prisijungusiu žaidėjų skaičių, pasirinkusių komandą. Nes get_playersnum priskaičiuoja ir UNASSIGNED žaidėjus.

Re: Team players

Posted: 2013 Jun 13 16:34
by newb

Code: Select all

get_players(players,num,"e","CT")get_players(players,num,"e","TERRORIST")
Ar tau reikia visus kartu ?

Re: Team players

Posted: 2013 Jun 13 17:46
by aaarnas

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;}

Re: Team players

Posted: 2013 Jun 13 19:29
by hleV

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;}

Re: Team players

Posted: 2013 Jun 13 20:15
by beast

Code: Select all

GetActivePlayerCount(){    new players[32], all, uns        get_players(players, all, "ch")    get_players(players, uns, "ceh", "UNASSIGNED")        return all - uns}
:je:

Re: Team players

Posted: 2013 Jun 13 20:51
by nuodas159
Who will win? :D

Re: Team players

Posted: 2013 Jun 13 21:42
by xedga
beast man jau į skype parašė savo būda, tai jį ir bandysiu naudoti. Ačiū visiems už pagalba

Re: Team players

Posted: 2013 Jun 13 22:21
by InvIs
Šiaip, nelabai nusimanau, bet...

Beast'o ir Hlev'o būdai, su get_players.

Kartais get_players stock'as nenaudoja to paties "for" ir neina per visus žaidėjus? Jei taip, tai arno būdas optimaliausias.

Re: Team players

Posted: 2013 Jun 13 22:27
by hleV
InvIs wrote: Kartais get_players stock'as nenaudoja to paties "for" ir neina per visus žaidėjus? Jei taip, tai arno būdas optimaliausias.
get_players ne stock'as.

Re: Team players

Posted: 2013 Jun 13 23:21
by aaarnas
get_players realizacija:

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;}
get_user_team realizacija:

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;}
Tai nėra tikslo šioje vietoje apskritai get_players naudoti.

Šiaip įdomų dalyką radau:
is_user_connected:

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);}
Tiek is_user_connected tiek get_user_team:
1. Gauna duomenis iš GET_PLAYER_POINTER_I
2. Tikrina: pPlayer->ingame

Tad lieku prie šio varianto:

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;}
-- 2013 Bir 13 23:27 --

Dėl įdomumo get_playersnum realizacija:

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;}
-- 2013 Bir 13 23:28 --
nuodas159 wrote:Who will win? :D
Me