!nextmap Voting

From Soldat Community Wiki
Revision as of 17:49, 14 August 2012 by Freeman (talk | contribs) (Created page with "===!nextmap Voting by Curt=== <source lang="pascal"> const Color = $FFFFFFFF; VotePerc = 51; VoteTime = 30; AddTime = 5; var Go: boolean; VFor,Time: byte; Voted...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

!nextmap Voting by Curt

const
  Color = $FFFFFFFF;
  VotePerc = 51;
  VoteTime = 30;
  AddTime = 5;

var
  Go: boolean;
  VFor,Time: byte;
  Voted: array[1..32] of boolean;

procedure AppOnIdle(Ticks: integer);
var
  i: byte;
begin
  if Time > 0 then Time := Time - 1 else if Go then begin
    Go := false;
    for i := 1 to 32 do Voted[i] := false;
    VFor := 0;
    Time := 0;
    WriteConsole(0,'Map vote failed.',Color);
  end;
end;

procedure OnMapChange(NewMap: String);
var
  i: byte;
begin
  Go := false;
  for i := 1 to 32 do Voted[i] := false;
  VFor := 0;
  Time := 0;
end;

procedure OnPlayerSpeak(ID: byte; Text: string);
var
  i: byte;
begin
  if Text = '!nextmap' then if Voted[ID] = false then begin
    if Go = false then Time := VoteTime else Time := Time + AddTime;
    Go := true;
    Voted[ID] := true;
    VFor := VFor + 1;
    if VFor / NumPlayers * 100 >= VotePerc then begin
      Go := false;
      for i := 1 to 32 do Voted[i] := false;
      VFor := 0;
      Time := 0;
      WriteConsole(0,'Map vote passed.',Color);
      Command('/nextmap');
    end else WriteConsole(0,'Voting percentage of needed people: ' + FloattoStr(RoundTo(VFor / NumPlayers * 100,2)) + '% / ' + InttoStr(VotePerc) + '%.',Color);
  end else WriteConsole(ID,'You have already voted.',Color);
end;

procedure OnLeaveGame(ID, Team: byte; Kicked: boolean);
var
  i: byte;
begin
  if Voted[ID] then begin
    Voted[ID] := false;
    VFor := VFor - 1;
  end else begin
    if NumPlayers > 1 then if VFor / (NumPlayers - 1) * 100 >= VotePerc then begin
      Go := false;
      for i := 1 to 32 do Voted[i] := false;
      VFor := 0;
      Time := 0;
      WriteConsole(0,'Map vote passed.',Color);
      Command('/nextmap');
    end;
  end;
end;