AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Optimized way of grouping players between the teams (https://forums.alliedmods.net/showthread.php?t=272182)

Al3 09-25-2015 14:16

Optimized way of grouping players between the teams
 
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_nPlayersglobal_nTerroristsglobal_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_iTerroristsglobal_nTerrorists"ae""TERRORIST");
    
get_players(global_iHumansglobal_nHumans"ae""CT");
    
    if(
iTeam == CS_TEAM_CT && global_nTerrorists global_nHumans 2)
    {
        
cs_set_user_team(idCS_TEAM_T);
        return 
0;
    }
    if(
iTeam == CS_TEAM_T && global_nTerrorists global_nHumans 2// else
    
{
        
cs_set_user_team(idCS_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?

wickedd 09-25-2015 19:16

Re: Optimized way of grouping players between the teams
 
Look at Team Ratio even better just use it. It does what you want.

Al3 09-25-2015 19:27

Re: Optimized way of grouping players between the teams
 
I feel awful.


All times are GMT -4. The time now is 22:12.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.