IsTeamFull
#1

Hello,

Recently i've been working on a small function that check if the team which's ID is passed as parameter is full (has more members then others?), but i literally failed as i am really bad at maths, would anyone mind giving me a hand?

This the function that i made which i dont think is good / accurate:
PHP код:
IsTeamFull(TeamID)
{
    new 
Teams[MAX_TEAMS], bool:rt;
    for(new 
=0iMAX_PLAYERSi++)
    {
        for(new 
0MAX_TEAMSk++)
        {
             if((
GetPlayerTeam(i) == k)
             {
                
Teams[k]++;
             }
        }
    }
    for(new 
0iMAX_TEAMSi++)
    {
        if(
Teams[i] < Teams[TeamID])
        {
            
rt true;
        }
        else
        {
            
rt false;
        }
    }
    return 
rt;

Reply
#2

can u explain it bit more. I'm confused whether you want to check the number of members in that team reached maximum or has highest number of members or check it against anyother team's member count.
Reply
#3

PHP код:
if the team which's ID is passed as parameter is full 
you means full team check if it's full ( places on it are full )
or
the largest team on server ( who got the most players on server )
Reply
#4

Simple, got some teams, but sometimes they get overloaded, which means some teams have alot of players in it while other a few, so i was trying to make a function to check if the team is "full" (has more players then others?), so i can prevent them from selecting that team.
Reply
#5

He wants to make a team balance to be more clear lol.
Reply
#6

PHP код:
IsTeamFull(TeamID

    new 
Teams[MAX_TEAMS],i,k
    for(
=0iMAX_PLAYERSi++) 
            for(
0MAX_TEAMSk++) 
                    if((
GetPlayerTeam(i) == k
                             
Teams[k]++; 
        
    for(
0iMAX_TEAMSi++) 
            if(
Teams[i] < Teams[TeamID]) 
                    return 
true
               
    return 
false

More effiicient will be storing count upon joining instead of looping and do the last check.
Reply
#7

PHP код:
#define MAX_PLAYERS_IN_TEAM 15
IsTeamFull(TeamID

    new 
Countbool:rt
    for(new 
=0iMAX_PLAYERSi++) 
    { 
        if(
GetPlayerTeam(i) == TeamID
        { 
            
Count++; 
        } 
    } 
    if(
Count == MAX_PLAYERS_IN_TEAM)
    { 
        return 
true;  
    }
    else return 
false;
}  
IsHightestTeam(TeamID)
{
    new 
idoutput = -1Teams[MAX_TEAMS], bool:rt;
    for(new 
=0iMAX_PLAYERSi++)
    {
        for(new 
0MAX_TEAMSk++)
        {
            if(
GetPlayerTeam(i) == k)
            {
                
Teams[k]++;
            }
        }
    }
    for (new 
htht != sizeof(Teams); ++ht)
    {
        if (
Teams[ht] > outputoutput Teams[ht], id ht;
    }
    
    if(
id == TeamID && id != -1)
    {
        return 
true;
    }
    else return 
false;

something like that ?
Reply
#8

Quote:
Originally Posted by TitanX
Посмотреть сообщение
PHP код:
#define MAX_PLAYERS_IN_TEAM 15
IsTeamFull(TeamID

    static 
Countbool:rt
    for(new 
=0iMAX_PLAYERSi++) 
    { 
        if(
GetPlayerTeam(i) == TeamID
        { 
            
Count++; 
        } 
    } 
    if(
Count == MAX_PLAYERS_IN_TEAM)
    { 
        return 
true;  
    }
    else return 
false;

something like that ?
Don't unnecessarily put static key word to every declaration if you actually don't know what it does. Your code wont work as the variable count being a static variable will be stored on data section and will be remembered on each overhead. That means the count variable never be reset.
Reply
#9

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
Don't unnecessarily put static key word to every declaration if you actually don't know what it does. Your code wont work as the variable count being a static variable will be stored on data section and will be remembered on each overhead. That means the count variable never be reset.
forgot dat thing, thanks :P
Reply
#10

Quote:
Originally Posted by iLearner
Посмотреть сообщение
Simple, got some teams, but sometimes they get overloaded, which means some teams have alot of players in it while other a few, so i was trying to make a function to check if the team is "full" (has more players then others?), so i can prevent them from selecting that team.
make a variable for each team or array e.g
Код:
new g_TeamCount[MAX_TEAMS];
each time a person joins
Код:
++g_TeamCount
and each time a person leaves it, do the opposite.

then u can fix ur IsTeamFull easily
Код:
IsTeamFull(teamid)
{
    if ( g_TeamCount[teamid] >= MAX_TEAM_MEMBERS )
	return true;
		
    return false;	
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)