Author Topic: SpecCourtesy  (Read 1563 times)

0 Members and 1 Guest are viewing this topic.

Offline Savage

  • Soldier
  • **
  • Posts: 155
SpecCourtesy
« on: October 13, 2016, 11:19:52 am »
Script Name: SpecCourtesy
Script Description: Script allows players to join to server as spectator even if MaxPlayers number is reached. (This is different than MaxPlayers from soldat.ini).
Original Author(s): Savage
Compilation: Passed
Core Version: 2.8.1 (SC3)

Code: [Select]
//SpecCourtesy by Savage
//Core Version: 2.8.1
//Description: Script allows players to join to server as spectator even if MaxPlayers number is reached. (This is different than MaxPlayers from soldat.ini).

const
MaxSpectators = 32; //MaxSpectators from soldat.ini suc**
MaxPlayers = 6; //Spectators aren't counted

procedure OnJoinTeam(Player: TActivePlayer; Team: TTeam);
var
i, AmountNoColor, AmountAlpha, AmountBravo, AmountCharlie, AmountDelta, AmountSpectators: Byte; //TTeam.Count is bugged in 2.8.1 so we have to count it at our own
begin
for i := 1 to 32 do
if Players[i].Active then
case Players[i].Team of
0 : Inc(AmountNoColor, 1);
1 : Inc(AmountAlpha, 1);
2 : Inc(AmountBravo, 1);
3 : Inc(AmountCharlie, 1);
4 : Inc(AmountDelta, 1);
5 : Inc(AmountSpectators, 1);
end;

if AmountNoColor + AmountAlpha + AmountBravo + AmountCharlie + AmountDelta > MaxPlayers then begin
Player.WriteConsole('Max players number reached', $FF0000);
Player.Team := 5;
end else
if (Team.ID = 5) and (AmountSpectators > MaxSpectators) then begin
Player.WriteConsole('Spectators team is full', $FF0000);
Player.Kick(TKickSilent);
end;
end;

procedure Init;
var
i: Byte;
begin
for i := 0 to 5 do Game.Teams[i].OnJoin := @OnJoinTeam;
end;

begin
Init;
end.
« Last Edit: October 13, 2016, 06:20:12 pm by Savage »