Author Topic: NumPlayersonTeam (Multiple ways)  (Read 2085 times)

0 Members and 1 Guest are viewing this topic.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
NumPlayersonTeam (Multiple ways)
« on: July 01, 2007, 06:04:45 pm »
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.
Code: [Select]
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)
Code: [Select]
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
Code: [Select]
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 :))