Author Topic: sBalance  (Read 5452 times)

0 Members and 1 Guest are viewing this topic.

Offline cooz

  • Soldier
  • **
  • Posts: 187
  • BANNED
sBalance
« on: November 21, 2006, 07:58:12 pm »
Script Name: sBalance
Script Description: script moving players to make teams equal
Original Author: cooz
Core Version: 2.5.2

Code: [Select]
const
  CHECK_TIME = 2;

var
  i,j,temp,idtoswitch: integer;

function IDtoKills(PlayerID: integer):integer;
begin
  case PlayerID of
    1: Result:= Player_Kills_1;
    2: Result:= Player_Kills_2;
    3: Result:= Player_Kills_3;
    4: Result:= Player_Kills_4;
    5: Result:= Player_Kills_5;
    6: Result:= Player_Kills_6;
    7: Result:= Player_Kills_7;
    8: Result:= Player_Kills_8;
    9: Result:= Player_Kills_9;
    10: Result:= Player_Kills_10;
    11: Result:= Player_Kills_11;
    12: Result:= Player_Kills_12;
    13: Result:= Player_Kills_13;
    14: Result:= Player_Kills_14;
    15: Result:= Player_Kills_15;
    16: Result:= Player_Kills_16;
    17: Result:= Player_Kills_17;
    18: Result:= Player_Kills_18;
    19: Result:= Player_Kills_19;
    20: Result:= Player_Kills_20;
    21: Result:= Player_Kills_21;
    22: Result:= Player_Kills_22;
    23: Result:= Player_Kills_23;
    24: Result:= Player_Kills_24;
    25: Result:= Player_Kills_25;
    26: Result:= Player_Kills_26;
    27: Result:= Player_Kills_27;
    28: Result:= Player_Kills_28;
    29: Result:= Player_Kills_29;
    30: Result:= Player_Kills_30;
    31: Result:= Player_Kills_31;
    32: Result:= Player_Kills_32;
  end;
end;

function IDtoTeam(PlayerID: integer):integer;
begin
  case PlayerID of
    1: Result:= Player_Team_1;
    2: Result:= Player_Team_2;
    3: Result:= Player_Team_3;
    4: Result:= Player_Team_4;
    5: Result:= Player_Team_5;
    6: Result:= Player_Team_6;
    7: Result:= Player_Team_7;
    8: Result:= Player_Team_8;
    9: Result:= Player_Team_9;
    10: Result:= Player_Team_10;
    11: Result:= Player_Team_11;
    12: Result:= Player_Team_12;
    13: Result:= Player_Team_13;
    14: Result:= Player_Team_14;
    15: Result:= Player_Team_15;
    16: Result:= Player_Team_16;
    17: Result:= Player_Team_17;
    18: Result:= Player_Team_18;
    19: Result:= Player_Team_19;
    20: Result:= Player_Team_20;
    21: Result:= Player_Team_21;
    22: Result:= Player_Team_22;
    23: Result:= Player_Team_23;
    24: Result:= Player_Team_24;
    25: Result:= Player_Team_25;
    26: Result:= Player_Team_26;
    27: Result:= Player_Team_27;
    28: Result:= Player_Team_28;
    29: Result:= Player_Team_29;
    30: Result:= Player_Team_30;
    31: Result:= Player_Team_31;
    32: Result:= Player_Team_32;
  end;
end;

procedure switchPlayers(plrteam: byte; plramount: integer);
begin
  temp:=65535;
  for i:=1 to plramount do begin
    for j:=1 to NumPlayers do begin
      if((IDtoKills(j)<=temp)and(IDtoTeam(j)<>plrteam)) then begin
        temp:= IDtoKills(j);
        idtoswitch:=j;
      end;
    end;
    command('/setteam'+inttostr(plrteam)+' '+inttostr(idtoswitch));
  end;
end;

procedure AppOnIdle(Ticks: integer);
begin
  if Ticks mod(3600*CHECK_TIME)=0 then begin
    if BravoPlayers+2<=AlphaPlayers then begin switchPlayers(2,(AlphaPlayers-BravoPlayers)/2); end
     else if AlphaPlayers+2<=BravoPlayers then switchPlayers(1,(BravoPlayers-AlphaPlayers)/2);
  end;
end;

procedure OnCommand(ID: integer;Text: string);
begin
  if Text = '/sbalance' then begin
    if BravoPlayers+2<=AlphaPlayers then begin switchPlayers(2,(AlphaPlayers-BravoPlayers)/2); end
     else if AlphaPlayers+2<=BravoPlayers then switchPlayers(1,(BravoPlayers-AlphaPlayers)/2);
  end;
end;

features:
- every (defined) amount of time script checks if number of players in each teams isn't different more then 2, then eventually move players with lowest kill amount to opposite team
- admin commands:
  /sbalance - force to check team balance
- script switches:
  CHECK_TIME - interval between each check, in minutes (default: 2 )

note:
 script shouln't be use on servers with bots, if you want use bot balance set it in server.ini

script made on request - sorry Leo for such delay :-[

ps. also i decided to change place of [stable], [unstable] topics prefix
« Last Edit: November 29, 2006, 04:05:50 pm by cooz »
Dead man! Dead man walking! We got a dead man walking here! Banned man crawling more like

Offline Mistercharles

  • Veteran
  • *****
  • Posts: 1371
  • +
Re: [stable] sBalance
« Reply #1 on: November 21, 2006, 07:59:59 pm »
Here's a challenge- if a team has one more player than the other, and that bigger team is winning, their worst player gets transfered to the losing team.
shoutout to m'boyz eagles_arrows, echo_trail, wraithlike, sadistatheart, chakapoko maker, jrgp, aznblood, chakra, keron cyst, et al, miss you, let's '#gather some day

Offline cooz

  • Soldier
  • **
  • Posts: 187
  • BANNED
Re: [stable] sBalance
« Reply #2 on: November 21, 2006, 08:04:30 pm »
Here's a challenge- if a team has one more player than the other, and that bigger team is winning, their worst player gets transfered to the losing team.

shh: s[imple]Balance,
i have more complex idea of balancing teams,
but everything in right time ::)
Dead man! Dead man walking! We got a dead man walking here! Banned man crawling more like

Offline Leo

  • Soldat Beta Team
  • Veteran
  • ******
  • Posts: 1011
Re: [stable] sBalance
« Reply #3 on: November 22, 2006, 04:35:21 am »
Thanks cooz :)

Offline toRch

  • Major
  • *
  • Posts: 55
  • <3
Re: sBalance
« Reply #4 on: December 24, 2006, 07:33:30 am »
a question: if a player changes teams, and the teams arent fair anymore, will the script even the teams, like on the tba server? thanks.

Offline cooz

  • Soldier
  • **
  • Posts: 187
  • BANNED
Re: sBalance
« Reply #5 on: December 24, 2006, 08:22:11 am »
answer is: yes,
after those  minutes (or whatever time you set) teams will be even again
Dead man! Dead man walking! We got a dead man walking here! Banned man crawling more like