For all honesty, I don't really enjoy my current approach of grouping players.
I want to group them so that terrorists will be always twice as much as the CTs.
For instance we have 10 players. CTs would be 3, terrorists would be 7 (the additional one deducts to the terrorists team).
My first idea was something like that:
PHP Code:
new nCount = get_playersnum(0);
new ctCount = floatround(nCount / 2.5);
new tCount = floatround(nCount / 1.5);
new difference = tCount - ctCount;
tCount += difference;
Even though it is relatively fast, it still can be better by say, using the modulo operator for the residue, not a bunch of redundant arithmetic computations.
_____________________________________________ _____________________________________________ _______________________________
Anyway, my current approach that works is terrifying. I am using the
Ham_Spawn
to hook earliest player spawn (including for bots) in order to apply
cs_set_user_team
The callback function looks like:
PHP Code:
new global_nPlayers, global_nTerrorists, global_nHumans;
new global_iPlayers [32];
new global_iTerrorists [32];
new global_iHumans [32];
public entity_created (id) // once per user must it be
{
new CsTeams:iTeam = cs_get_user_team(id);
global_nPlayers = get_playersnum(0);
get_players(global_iTerrorists, global_nTerrorists, "ae", "TERRORIST");
get_players(global_iHumans, global_nHumans, "ae", "CT");
if(iTeam == CS_TEAM_CT && global_nTerrorists < global_nHumans * 2)
{
cs_set_user_team(id, CS_TEAM_T);
return 0;
}
if(iTeam == CS_TEAM_T && global_nTerrorists > global_nHumans * 2) // else
{
cs_set_user_team(id, CS_TEAM_CT);
return 0;
}
return 1;
}
_____________________________________________ _____________________________________________ _______________________________
As you can see it clearly sucks. Not only the "create entity ham" seems not to be the appropriate one.. but also the intervention of
get_players bothers me like a lot.
Can anyone help me create/fix another/this approach by maybe applying a formula close to the one I got and the correct working hook?