Author Topic: Votemap error  (Read 1871 times)

0 Members and 1 Guest are viewing this topic.

Offline MrHamsTR

  • Soldier
  • **
  • Posts: 209
  • One day, everything will end..
Votemap error
« on: December 06, 2014, 11:02:04 am »
Compiling vote -> core.pas...
vote -> [Hint] (35:10): Variable 'Result' never used
vote -> [Error] (57:29): Unknown identifier 'Total'
Disabling vote
Done

Code: [Select]
const
  Color = $9933FFF;
  VotePerc = 51;
  InitTime = 60;
  AddTime = 10;

var
  Enable: boolean;
  Time: integer;
  Voted: array[1..32] of boolean;

procedure DisableVoteNext;
begin
  Enable := false;
end;

procedure ActivateServer();
begin
  Enable := true;
end;

procedure AppOnIdle(Ticks: integer);
var
  i: byte;
begin
  if (Time > 0) then begin
    Time := Time - 1;
    if (Time = 0) then begin
      for i := 1 to 32 do Voted[i] := false;
      WriteConsole(0, 'Oylama basarisiz', Color);
    end;
  end;
end;

function OnCommand(Id: byte; Text: string): boolean;
begin
  if ((LowerCase(Copy(Text, 1, 8)) = '/restart') or (LowerCase(Copy(Text, 1, 8)) = '/nextmap') or ((LowerCase(Copy(Text, 1, 4)) = '/map') and (FileExists('maps/' + Copy(Text, 6, Length(Text)) + '.PMS')))) then DisableVoteNext;
end;

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

procedure OnJoinGame(ID, Team: byte);
begin
  Voted[ID] := false;
end;

function ShowTrimmedPercentage(): string;
var i: byte;
begin
Result := FloatToStr(100 * Total / (NumPlayers - NumBots));

While (Copy(Result, Length(Result), 1) = '0') do
Result := Copy(Result, 1, Length(Result) - 1);
end;

procedure OnLeaveGame(ID, Team: byte; Kicked: boolean);
var
  i, Total: byte;
begin
  Voted[ID] := false;
  for i := 1 to 32 do if (GetPlayerStat(i, 'Active') = true) and (Voted[i]) then Total := Total + 1;
  if (Total > 0) then begin
    if (100 * Total / (NumPlayers - NumBots) >= VotePerc) then begin
      for i := 1 to 32 do Voted[ID] := false;
      DisableVoteNext;
      WriteConsole(0, 'Oylama basarili', Color);
      Command('/nextmap');
    end else WriteConsole(0,ShowTrimmedPercentage() + '% / ' + InttoStr(VotePerc) + '% gerekiyor', Color);
  end;
end;

procedure OnPlayerSpeak(ID: byte; Text: string);
var
  i, Total: byte;
begin
  if ((LowerCase(Text) = '!nextmap') and (Enable)) then begin
    if Voted[ID] then WriteConsole(ID, 'Zaten oy kullandin.', Color) else if (Time = 0) then Time := InitTime else Time := Time + Addtime;
    Voted[ID] := true;
    for i := 1 to 32 do if (GetPlayerStat(i, 'Active') = true) and (Voted[i]) then Total := Total + 1;
    if (100 * Total / (NumPlayers - NumBots) >= VotePerc) then begin
      for i := 1 to 32 do Voted[ID] := false;
      DisableVoteNext;
      WriteConsole(0, 'Oylama basarili', Color);
      Command('/nextmap');
    end else WriteConsole(0,ShowTrimmedPercentage() + '% / ' + InttoStr(VotePerc) + '% gerekiyor', Color);
  end;
end;
Is there anybody can write script?
Good, go and play soldat ^^

Offline rOy

  • Soldier
  • **
  • Posts: 120
Re: Votemap error
« Reply #1 on: December 06, 2014, 05:46:20 pm »
Hey

Try this ;)

Code: [Select]
const
  Color = $9933FFF;
  VotePerc = 51;
  InitTime = 60;
  AddTime = 10;

var
  Enable: boolean;
  Time: integer;
  Voted: array[1..32] of boolean;

procedure DisableVoteNext;
begin
  Enable := false;
end;

procedure ActivateServer();
begin
  Enable := true;
end;

procedure AppOnIdle(Ticks: integer);
var
  i: byte;
begin
  if (Time > 0) then begin
    Time := Time - 1;
    if (Time = 0) then begin
      for i := 1 to 32 do Voted[i] := false;
      WriteConsole(0, 'Oylama basarisiz', Color);
    end;
  end;
end;

function OnCommand(Id: byte; Text: string): boolean;
begin
    if ((LowerCase(Copy(Text, 1, 8)) = '/restart') or (LowerCase(Copy(Text, 1, 8)) = '/nextmap') or ((LowerCase(Copy(Text, 1, 4)) = '/map') and (FileExists('maps/' + Copy(Text, 6, Length(Text)) + '.PMS'))))
then DisableVoteNext;
    Result := false;
end;

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

procedure OnJoinGame(ID, Team: byte);
begin
  Voted[ID] := false;
end;

function ShowTrimmedPercentage(): string;
var
    Total: byte;
begin
Result := FloatToStr(100 * Total / (NumPlayers - NumBots));

While (Copy(Result, Length(Result), 1) = '0') do
Result := Copy(Result, 1, Length(Result) - 1);
end;

procedure OnLeaveGame(ID, Team: byte; Kicked: boolean);
var
  i, Total: byte;
begin
  Voted[ID] := false;
  for i := 1 to 32 do if (GetPlayerStat(i, 'Active') = true) and (Voted[i]) then Total := Total + 1;
  if (Total > 0) then begin
    if (100 * Total / (NumPlayers - NumBots) >= VotePerc) then begin
      for i := 1 to 32 do Voted[ID] := false;
      DisableVoteNext;
      WriteConsole(0, 'Oylama basarili', Color);
      Command('/nextmap');
    end else WriteConsole(0,ShowTrimmedPercentage() + '% / ' + InttoStr(VotePerc) + '% gerekiyor', Color);
  end;
end;

procedure OnPlayerSpeak(ID: byte; Text: string);
var
  i, Total: byte;
begin
  if ((LowerCase(Text) = '!nextmap') and (Enable)) then begin
    if Voted[ID] then WriteConsole(ID, 'Zaten oy kullandin.', Color) else if (Time = 0) then Time := InitTime else Time := Time + Addtime;
    Voted[ID] := true;
    for i := 1 to 32 do if (GetPlayerStat(i, 'Active') = true) and (Voted[i]) then Total := Total + 1;
    if (100 * Total / (NumPlayers - NumBots) >= VotePerc) then begin
      for i := 1 to 32 do Voted[ID] := false;
      DisableVoteNext;
      WriteConsole(0, 'Oylama basarili', Color);
      Command('/nextmap');
    end else WriteConsole(0,ShowTrimmedPercentage() + '% / ' + InttoStr(VotePerc) + '% gerekiyor', Color);
  end;
end;

Offline MrHamsTR

  • Soldier
  • **
  • Posts: 209
  • One day, everything will end..
Re: Votemap error
« Reply #2 on: December 06, 2014, 07:29:53 pm »
Thank you what was the problem? I couldnt get.
Is there anybody can write script?
Good, go and play soldat ^^

Offline %%%%%%%

  • Soldier
  • **
  • Posts: 205
Re: Votemap error
« Reply #3 on: December 07, 2014, 10:53:47 am »
Apparently the OnCommand function needed this: Result := false;

Offline MrHamsTR

  • Soldier
  • **
  • Posts: 209
  • One day, everything will end..
Re: Votemap error
« Reply #4 on: December 12, 2014, 08:48:58 am »
Thanks a lot Simon.
Is there anybody can write script?
Good, go and play soldat ^^