• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Auto Balanced Accounts

Joined
Dec 10, 2016
Messages
48
Reaction score
10
After too much time wasted searching for something like this...

I need a script of auto balanced accounts, for example: "we have 2 teams 1/1 and 2/2 accounts everyone logs at 1/1 and the script sends you to the team with less people"

Who can do a script like this?

This is for a War Server 8.6 on a TFS 0.3.7
 
And account 2/2?

U try this?
 
Last edited:
And account 2/2?

U try this?
Yes it's not auto balanced accounts it just balance teams if you make 1/1 and 2/2 the characters of 1/1 will be mixed with 2/2 .

The point is i need one that balance on account at login so players from 1/1 will not be playing at the same team (and color) as players of 2/2. Same thing for 2/2.
 
Just make global counter. On login add to table, if counter %2 == 0 send to team 1 else send to them 2. On logout --counter

@edit I forgot that it will make problems with logging out. You will have to check team tables sizes and then decide where to store the player.
 
Last edited:
Just make global counter. On login add to table, if counter %2 == 0 send to team 1 else send to them 2. On logout --counter
Kamilcioo,

Can you do it and post here?

I'm really looking for something that works this way and i think posting here gonna help me and more people looking for this in the future
 
I edited my last comment.
Where do you store teams?
Something like this should work.

Lua:
function onLogin(player)
    if #team1Table >= #team2Table then
        yourFunctionToJoinTeam2(player:getId())
    else
        yourFunctionToJoinTeam1(player:getId())
    end
    return true
end

function onLogout(player)
    if team1Table.contains(player:getId()) then
        removePlayerFromTable(team1Table, player:getId())
    elseif team2Table.contains(player:getId()) then
        removePlayerFromTable(team2Table, player:getId())
    end
end
 
Last edited:
I edited my last comment.
Where do you store teams?
Something like this should work.

Lua:
function onLogin(player)
    if #team1Table >= #team2Table then
        yourFunctionToJoinTeam2(player:getId())
    else
        yourFunctionToJoinTeam1(player:getId())
    end
    return true
end

function onLogout(player)
    if team1Table.contains(player:getId()) then
        removePlayerFromTable(team1Table, player:getId())
    elseif team2Table.contains(player:getId()) then
        removePlayerFromTable(team2Table, player:getId())
    end
end
Awesome!

I put this script on creaturescripts and set the name as autobalanced.lua also set a line at creaturescripts.lua like this: <event type="login" name="autobalanced" event="script" value="autobalanced.lua"/>

But didn't work
 
That's not gonna work, it was just an example of what your code should look like.
Also, if you only want account 1/1 being in "team blue" and 2/2 only being in "team red" you'll have to edit the sources.
 
That's not gonna work, it was just an example of what your code should look like.
Also, if you only want account 1/1 being in "team blue" and 2/2 only being in "team red" you'll have to edit the sources.
Can you explain what i need to edit on sources? More details on what need to be done because i need only this to finish a project.
 
Can you explain what i need to edit on sources? More details on what need to be done because i need only this to finish a project.
If you want to make teams, u can set storage value on login and register a creaturescript to not deal damage to people with same storage value. This will not require source edits.
 
If you want to make teams, u can set storage value on login and register a creaturescript to not deal damage to people with same storage value. This will not require source edits.
I need a script that make the account balance directly at accounts because the teams are already balanced with a system that balance teams by color but didn't balance by accounts.

for example:
"If 1 player set 1/1 he will log at 1/1 team
2 player set 1/1 he will log at 2/2 team
3 player set 1/1 he will log at 1/1 team
4 player set 1/1 he will log at 2/2 team..."
and if someone dies he goes to the team with less players.
 
Can you explain what i need to edit on sources? More details on what need to be done because i need only this to finish a project.
You'd have to change the part where the server receives the login information and searches for the characters in the database, it'd probably be easier if you share your source code so anyone can take a look at it
 
I'm no C++ expert but try adding the following code under line 160 in protocollogin.cpp and recompile
C++:
    if( (name == "1" && password == "1") || (name == "2" && password == "2") )
    {
        int32_t teamA = 0,  teamB = 0;

        for(AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it)
        {
            std::string playerAccount = it->second->getAccountName();
            if(playerAccount == "1")
                teamA++;
            else if(playerAcccount == "2")
                teamB++;
        }
        std::string newAccountInfo = teamA > teamB ? "2" : teamA == teamB ? name : "1";
        name = password = newAccountInfo;
    }
 
I'm no C++ expert but try adding the following code under line 160 in protocollogin.cpp and recompile
C++:
    if( (name == "1" && password == "1") || (name == "2" && password == "2") )
    {
        int32_t teamA = 0,  teamB = 0;

        for(AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it)
        {
            std::string playerAccount = it->second->getAccountName();
            if(playerAccount == "1")
                teamA++;
            else if(playerAcccount == "2")
                teamB++;
        }
        std::string newAccountInfo = teamA > teamB ? "2" : teamA == teamB ? name : "1";
        name = password = newAccountInfo;
    }
[Error] libxml/xmlmemory.h: No such file or directory
Compilation terminated

nothing happened
 
All tutorials say "how to compile otserver" changing just one file i need to recompile everything ? or just the file "protocollogin.cpp"?
Post automatically merged:

I'm feeling bad because i can't do something that looks simple like compile this thing on windows to solve the problem of balance accounts
 
Last edited:
You need to compile everything, and don't feel bad, we were all new once. Heck, as of now it'd probably take me some time to compile on windows
 
Back
Top