AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   getting max number of teams? (https://forums.alliedmods.net/showthread.php?t=131517)

HLM 07-06-2010 00:56

getting max number of teams?
 
im trying to make a plugin that will generically balance teams for all game mods, but some games have more than two teams, is there some way to check how many max teams there are?

fysiks 07-06-2010 02:31

Re: getting max number of teams?
 
Quote:

Originally Posted by HLM (Post 1229567)
im trying to make a plugin that will generically balance teams for all game mods, but some games have more than two teams, is there some way to check how many max teams there are?

Not exactly an easy feat to attempt maybe not very logical either. Why would you need a single plugin for "all game mods"?

HLM 07-06-2010 03:52

Re: getting max number of teams?
 
I dont, I just want to make AND release a plugin for once, lol

Alucard^ 07-06-2010 07:43

Re: getting max number of teams?
 
Why don't you use http://www.amxmodx.org/funcwiki.php?go=func&id=248 ?

fysiks 07-06-2010 20:57

Re: getting max number of teams?
 
Quote:

Originally Posted by Alucard^ (Post 1229728)

Because he wants it to be dynamic. Your suggestion requires hard coding the info for each mod.

HLM 07-06-2010 21:16

Re: getting max number of teams?
 
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <hamsandwich>

#define PLUGIN "Team Balance"
#define VERSION "1.0"
#define AUTHOR "Master"

/*new team1 = 0;
new team2 = 0;
new team3 = 0;
new team4 = 0;
new spectators = 0;*/

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
//RegisterHam(Ham_Spawn, "player", "user_spawn" 1)
    
register_clcmd("say !teams""check_teams", -1"checks how balanced the teams are.")
}

public 
check_teams()
{
    new 
team1team2team3team4spec
    
for(new i=0;i<33;i++)
    {
        new 
team get_user_team(i)
        switch(
team)
        {
            case 
1team1++
            case 
2team2++
            case 
3team3++
            case 
4team4++
            case 
0spec++
        }
    }
    if((
team3 == 0) && (team4 == 0))
    {
        if((
team1 team2) && (team1 team2+1))
        {
            
//team1 has too many people, do something about it.
        
}
        else if((
team2 team1) && (team2 team1+1))
        {
            
//team2 has too many people, do something about it.
        
}
    }
    else
    {
        if((
team1 team2) && (team1 team3) && (team1 team4) && (team1-team2) && (team1-team3) && (team1-team4)) // there HAS to be an easier way...
        
{
            
//team1 has too many people, damn, three more teams to do...
        
}
        else if((
team2 team1) && (team2 team3) && (team2 team4) && (team2-team1) && (team2-team3) && (team2-team4))
        {
            
//do stuff
        
}
        else if((
team3 team1) && (team3 team2) && (team3 team4) && (team3-team1) && (team3-team2) && (team3-team4))
        {
            
//do something cool
        
}
        else if((
team4 team1) && (team4 team2) && (team4 team3) && (team4-team1) && (team4-team2) && (team4-team3))
        {
            
//blah
        
}
    }


will this work as intended? I am assuming no, since there is the possibility that team1 could have 4 peopls team2 4 team3 5 team4 6 and it will probably be wrong..

RedRobster 07-06-2010 23:43

Re: getting max number of teams?
 
Well, when looping through the players, make sure to do
PHP Code:

new players[32], pnum
get_players
(playerspnum)
for(new 
ipnumi++)
{
        new 
tempid players[i]


The way you are doing it, it will loop through 33 times instead of just 32 as well.

Also, when doing this:
PHP Code:

        if((team1 team2) && (team1 team2+1))
        {
            
//team1 has too many people, do something about it.
        


There is no need for the first check because if the second one is true, the first one has to be true.

fysiks 07-07-2010 00:51

Re: getting max number of teams?
 
Quote:

Originally Posted by HLM (Post 1230452)
PHP Code:

// there HAS to be an easier way... 

will this work as intended? I am assuming no, since there is the possibility that team1 could have 4 peopls team2 4 team3 5 team4 6 and it will probably be wrong..

I'm sure there is a more dynamic way but it probably won't be easy. First of all, what mod has more than two team? And, I have a hard time believing that get_user_team() will return 0 for spectator on any mod. CS and DOD both have spec that are non-zero IIRC.

Quote:

Originally Posted by RedRobster (Post 1230570)
Well, when looping through the players, make sure to do
PHP Code:

new players[32], pnum
get_players
(playerspnum)
for(new 
ipnumi++)
{
        new 
tempid players[i]


The way you are doing it, it will loop through 33 times instead of just 32 as well.

Note: You don't need to cache the player id if it is only used once. He could just as easily do switch(get_user_team(players[i])).

RedRobster 07-07-2010 00:59

Re: getting max number of teams?
 
Quote:

Originally Posted by fysiks (Post 1230597)
Note: You don't need to cache the player id if it is only used once. He could just as easily do switch(get_user_team(i)).

Did not know that. Cool.

fysiks 07-07-2010 02:11

Re: getting max number of teams?
 
Quote:

Originally Posted by RedRobster (Post 1230602)
Did not know that. Cool.

Oops, typo. It should be: switch(get_user_team(players[i]))


All times are GMT -4. The time now is 07:10.

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