Raised This Month: $ Target: $400
 0% 

Optimized way of grouping players between the teams


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Al3
Member
Join Date: Sep 2015
Location: Bulgaria
Old 09-25-2015 , 14:16   Optimized way of grouping players between the teams
Reply With Quote #1

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?

Last edited by Al3; 09-25-2015 at 14:22.
Al3 is offline
Send a message via Skype™ to Al3
wickedd
Veteran Member
Join Date: Nov 2009
Old 09-25-2015 , 19:16   Re: Optimized way of grouping players between the teams
Reply With Quote #2

Look at Team Ratio even better just use it. It does what you want.
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd is offline
Al3
Member
Join Date: Sep 2015
Location: Bulgaria
Old 09-25-2015 , 19:27   Re: Optimized way of grouping players between the teams
Reply With Quote #3

I feel awful.
Al3 is offline
Send a message via Skype™ to Al3
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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