Auto balance
#1

Can anyone help me build an auto balance system, I already tried to build one for my self but fail! I took a look at the samp forums, no tutorials. I saw some other topics but useless.
Well the basic function will be that OnPlayerRequestClass check, so that if a player for example selects TEAM_COPS and there are already 4>5 cops so that it gives an error. It must check to see if there are more players in one team than the other and if its equal then it should allow to spawn in any team. I am using gTeams.
Other I want it to check after 3 minutes too see if there are more players in a team than the other, probably should check for TEAM_COPS>TEAM_TERRORISTS-2 (so that it doesn't get bugged just changing players) and then it picks a random player and changes his skin, team, color.
If you can't do both of them, its ok, even one of them is appreciated!
Reply
#2

Try this

On top
pawn Код:
new players, cop, terrorist;
pawn Код:
public OnPlayerConnect(playerid)
{
    players++;
    return 1;
}  

public OnPlayerDisconnect(playerid)
{
    players--;
    if(GetPlayerTeam(playerid) == TEAM_COPS)
    {
        cop--;
    }
    else if(GetPlayerTeam(playerid) == TEAM_TERRORISTS)
    {
        terrorist--;
    }
    return 1;
}
pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
    new _limit = (players/2), bool:limit;
    if(terrorist > _limit || cop > _limit)
    {
        limit = true;
    }
    else
    {
        limit = false;
    }
    if(classid == TEAM_COPS && limit == true) return SendClientMessage(playerid, 0xFF0000, "That team is full!");
    else
    {
        cop++;
    }
    if(classid == TEAM_TERRORISTS && limit == true) return SendClientMessage(playerid, 0xFF0000, "That team is full!");
    else
    {
        terrorist++;
    }
    return 1;
}
Reply
#3

Well, i can't test it on my local server because i don't have enough (only one (me)) players
so if the code is a tested one that would be great!

Another question, do i have to include an include to call the function GetPlayerTeam(playerid) or it is there already in an include?
Reply
#4

Quote:
Originally Posted by suhrab_mujeeb
Посмотреть сообщение
Well, i can't test it on my local server because i don't have enough (only one (me)) players
so if the code is a tested one that would be great!

Another question, do i have to include an include to call the function GetPlayerTeam(playerid) or it is there already in an include?
Make fake player...call public's...
pawn Код:
OnGameModeInit()
{
    OnPlayerConnect(1);
    //Or you can use CallLocalFunction
    return 1;
}
By the way it will work i think
Reply
#5

Quote:
Originally Posted by suhrab_mujeeb
Посмотреть сообщение
Well, i can't test it on my local server because i don't have enough (only one (me)) players
so if the code is a tested one that would be great!

Another question, do i have to include an include to call the function GetPlayerTeam(playerid) or it is there already in an include?
EDIT: I think you have to replace > with >=

It is already in an include

When a player spawns as cop:
pawn Код:
SetPlayerTeam(playerid, TEAM_COP);
When a player spawns as terrorist:
pawn Код:
SetPlayerTeam(playerid, TEAM_TERRORIST);
In case you haven't define yet:

pawn Код:
#define TEAM_COP 1
#define TEAM_TERRORIST 2
Reply
#6

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
Make fake player...call public's...
pawn Код:
OnGameModeInit()
{
    OnPlayerConnect(1);
    //Or you can use CallLocalFunction
    return 1;
}
By the way it will work i think
@ Drift_Hunter sorry can u explain more? what if i want more than 5 fake players? and btw how then could i control the fake players?
@Pinguinn tnx for continued help, i have already defined the teams, can u please also tell help me with the player checker? i mean during game the gm checks for players and autobalances teams by changing random players' teams
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)