0 Members and 1 Guest are viewing this topic.
{| CTF Team Balancer by Swompie (©2o1o) - Modified by StayAlive (@2012) |} {| Working on Soldat Dedicated Server 1.6.3 (v2.7.3) |}const cBalance = $FF0000; // Color of the messages BalanceInterval = 60; // Delay beetween the teams will be balanced in seconds.function GetTeamArray(const Team: byte): Array of byte;var i, x: integer;begin i := 1; x := 0; while i < 32 do begin if GetPlayerStat(i, 'Active') = true then if GetPlayerStat(i, 'Team') = Team then begin SetArrayLength(Result, x + 1); Result[x] := i; x := x + 1; end; i := i + 1; end;end;procedure Balance();var i, Difference: integer; A: integer; B: integer; Players: Array of byte;begin //changed by StayAlive (@2012) A := AlphaPlayers; B := BravoPlayers; Difference := A - B; //end of change if (Difference > 1) and (AlphaPlayers > 1) then begin Players := GetTeamArray(1); while (true) do begin i := Players[Random(0, GetArrayLength(Players) - 1)]; if GetPlayerStat(i, 'Flagger') = false then break; end; Command('/setteam2 ' + inttostr(i)); WriteConsole(i, 'You were balanced due to unbalanced teams.', cBalance); end; if (Difference < -1) and (BravoPlayers > 1) then begin Players := GetTeamArray(2); while (true) do begin i := Players[Random(0, GetArrayLength(Players) - 1)]; if GetPlayerStat(i, 'Flagger') = false then break; end; Command('/setteam1 ' + inttostr(i)); WriteConsole(i, 'You were balanced due to unbalanced teams.', cBalance); end; //changed by StayAlive (@2012) A := AlphaPlayers; B := BravoPlayers; Difference := A - B; //end of change if (Difference > 1) or (Difference < -1) then Balance() else WriteConsole(0, 'Teams balanced. If you see no result teams are balanced.', cBalance);end;procedure OnPlayerSpeak(ID: byte; Text: string);begin if LowerCase(Copy(Text, 1, 8)) = '!balance' then Balance();end;procedure AppOnIdle(Ticks: integer);begin if Ticks mod (60 * BalanceInterval) = 0 then Balance();end;
const cBalance = $FF0000; // Color of the messages. BalanceInterval = 120; // Delay beetween the teams will be balanced in seconds.var a,b: integer;function GetTeamArray(const Team: byte): Array of byte;var i,x: integer;begin i := 1; x := 0; while (i < 32) do begin if (GetPlayerStat(i, 'Active') = true) then if (GetPlayerStat(i, 'Team') = Team) then begin SetArrayLength(Result, x + 1); Result[x] := i; inc(x,1); end; inc(i,1); end;end;procedure Balance();var i,Difference: integer; Players: Array of byte;begin Difference:=(a-b); if (Difference > 1) and (a > 1) then begin Players := GetTeamArray(1); while (true) do begin i := Players[Random(1, GetArrayLength(Players) - 1)]; if (GetPlayerStat(i, 'Flagger') = false) then break; end; Command('/setteam2 ' + inttostr(i)); dec(a,1); WriteConsole(i, 'You were balanced due to unbalanced teams.', cBalance); end; if (Difference < -1) and (b > 1) then begin Players := GetTeamArray(2); while (true) do begin i := Players[Random(1, GetArrayLength(Players) - 1)]; if (GetPlayerStat(i,'Flagger') = false) then break; end; Command('/setteam1 ' + inttostr(i)); dec(b,1); WriteConsole(i, 'You were balanced due to unbalanced teams.', cBalance); end; Difference:=(a-b); if (Difference > 1) or (Difference < -1) then Balance() else WriteConsole(0, 'Teams balanced. If you see no result teams are balanced.', cBalance);end;procedure OnPlayerSpeak(ID: byte; Text: string);begin if regExpMatch('^!(balance|bal|teams)$',lowercase(Text)) then if (GetPlayerStat(ID,'Team')<>5) begin a:=AlphaPlayers; b:=BravoPlayers; Balance(); end else WriteConsole(ID, 'You can`t balance the teams being on spec.', cBalance);end;procedure AppOnIdle(Ticks: integer);begin if (Ticks mod (60 * BalanceInterval) = 0) then begin a:=AlphaPlayers; b:=BravoPlayers; Balance(); end;end;