I suggest to combine the two scripts. If you use the same events in separate scripts they often interact in a bad way.
Version one, separated:
procedure OnJoinTeam(ID, Team: byte);
begin
if Team < 5 then
if AlphaPlayers + BravoPlayers + CharliePlayers + DeltaPlayers >= 4 then
Command('/setteam5 ' + inttostr(ID));
end;
Version two, combined with the previous one:
procedure OnJoinTeam(ID, Team: byte);
begin
if Team < 5 then
begin
if AlphaPlayers + BravoPlayers >= 4 then
Command('/setteam5 ' + inttostr(ID))
else if Team > 2 then
if AlphaPlayers > BravoPlayers then
Command('/setteam2 ' + inttostr(ID))
else
Command('/setteam1 ' + inttostr(ID));
end;
end;
Note: I'm not sure, but I think AlphaPlayers,... contains the old number of players, excluding the one joining.