Script Name: Number of Players on Team Checker
Script Description: For better ways of checking the number of players so you may use loops more easily to check all teams for whatever instead of having six different ifs for each variable (2 needed to be home made, the DM team and spectator team, because they are excluded)
Original Author: Curt (DorkeyDear)
Core Version: 2.6.1b
Code:Easy way to do a check for each team of how many players are on the team or number of alive players on a team.
function NumberofPlayers(Team: shortint; CheckAlive: boolean): byte;
var
i: byte;
begin
for i := 1 to 32 do if ((Team = -1) or (GetPlayerStat(i,'Team') = Team)) and ((CheckAlive = false) or (GetPlayerStat(i,'Alive'))) then Result := Result + 1;
end;
team -1 or all players
Or if you prefer having the number of players in an array
Note that AlivePlayers has a 6th team, that is for total alive players (i would do -1 but these are untested scripts and i don't know if that negative array values are allowed)
var
Players: array[0..5] of byte;
AlivePlayers: array[0..6] of byte;
function FixType(Value: integer): integer;
begin
Result := StrtoInt(InttoStr(Value));
end;
procedure UpdatePlayers;
var
i,j: byte;
begin
for i := 1 to 32 do begin
Inc(Players[FixType(GetPlayerStat(i,'Team'))],1);
if GetPlayerStat(i,'Alive') then begin
Inc(AlivePlayers[FixType(GetPlayerStat(i,'Team'))],1);
Inc(AlivePlayers[6],1);
end;
end;
end;
(This one I prefere, but I have to call UpdatePlayers b4 I actually use the numbers, so... I would actually use the first one)
but if you prefere the classic style, with multiple variables, here is the DM and spectator team number of players
function DMPlayers: byte;
var
i: byte;
begin
for i := 1 to 32 do if (GetPlayerStat(i,'Active')) and (GetPlayerStat(i,'Team') = 0) then Inc(Result,1);
end;
function SpecPlayers: byte;
var
i: byte;
begin
for i := 1 to 32 do if GetPlayerStat(i,'Team') = 5 then Inc(Result,1);
end;
The "if (GetPlayerStat(i,'Active'))" on the DMPlayers is only there beause the player's ID team is 0 if they are not ingame, although not required in the SpecPlayers.
Just a note that these are untested. (Urging to mess with IRC some more, sorry for no testing
)