Author Topic: Problem with voting  (Read 828 times)

0 Members and 1 Guest are viewing this topic.

Offline hugoleonardofa

  • Major(1)
  • Posts: 5
Problem with voting
« on: January 21, 2011, 06:24:13 am »
I have a problem voting on the script, the percentage of votes does not increase, you can correct for me?
Code: [Select]
const
        Color = $E56600;
        VoteTime = 60;
        AddTime = 1;
        VotePerc = 70;
        MSGCor = $66FF00;
        MSGCor2 = $FFFFFF;

var
        Voted : array[1..32] of boolean;
        VoteRun, EnDis : boolean;
        Time : integer;
        Script : string;
       
procedure ScriptChange(const ScriptName : string; const State : boolean);

var
        Index, SIndex : string;
        rec : boolean;

begin
   
  if not FileExists('scripts/' + ScriptName + '/Includes.txt') then begin
          exit;
  end;
  Index := ReadFile('scripts/' + ScriptName + '/Includes.txt');
    SIndex := Copy(Index,0,length(Index));
          rec := false;
            if (State) and (Copy(Index,0,2) = '//') then begin
              WriteFile('scripts/' + ScriptName + '/Includes.txt',Copy(Index,3,length(Index)));
                    rec := true;
            end else if (State) and (Copy(Index,0,2) = '//') then begin
              WriteFile('scripts/' + ScriptName + '/Includes.txt',Copy(Index,3,length(Index)));
             end;
            if (rec) and (ScriptName = '1') then begin
              WriteFile('scripts/3/Includes.txt','//3.pas');
              Command('/recompile');

              end else if (rec) and (ScriptName = '3') then begin
              WriteFile('scripts/1/Includes.txt','//1.pas');
              Command('/recompile');             
             
              end else if not (rec) and (ScriptName = '1') then begin
              WriteFile('scripts/3/Includes.txt','//3.pas');
              Command('/recompile'); 
             
              end else if not (rec) and (ScriptName = '3') then begin
              WriteFile('scripts/1/Includes.txt','//1.pas');
              Command('/recompile'); 
               end
end;

function GetScriptState(const ScriptName : string): boolean;

var
        Index : string;
       
begin

  if FileExists('scripts/' + ScriptName + '/Includes.txt') then begin
    Index := ReadFile('scripts/' + ScriptName + '/Includes.txt');
          if Copy(Index,0,2) = '//' then begin
            Result := false;
          end else Result := false
  end;
end;

procedure OnLeaveGame(ID, Team: byte; Kicked: boolean);

begin


end;


procedure OnPlayerSpeak(ID: byte; Text: string);

var
        Total, i : integer;
begin
  if (LowerCase(GetPiece(Text,' ',0)) = '!vote') and not (Voted[ID]) then
    if (GetPlayerStat(ID,'Active')) then
          if FileExists('scripts/' + GetPiece(Text,' ',1) + '/Includes.txt') then begin
            Total := Total + 1;
              Voted[ID] := true;
                VoteRun := true;
                          if Time = 0 then Time := VoteTime else Time := Time + AddTime;
                        if GetScriptState(GetPiece(Text,' ',1)) = true then begin
                              EnDis := false;
                                    WriteConsole(ID,'O jogador ' + IdToName(ID) + ' Votou no mode ' + GetPiece(Text,' ',1),Color);                     
                                end else if GetScriptState(GetPiece(Text,' ',1)) = false then begin
                              EnDis := true;
                                    WriteConsole(ID,'O jogador ' + IdToName(ID) + ' votou para ativar o mode ID: ' + GetPiece(Text,' ',1),Color);
                                end;
                                  Script := GetPiece(Text,' ',1);
         
         
    if (100 * Total / (NumPlayers - NumBots) >= VotePerc) then begin
      for i := 1 to 32 do Voted[ID] := false;
           WriteConsole(ID,'Votação para mudar de mode teve sucesso. O Mode ID: "' + Script + '" está ativado',Color);
              ScriptChange(Script,EnDis);
  end else WriteConsole(0,FloatToStr(RoundTo(100 * Total / (NumPlayers - NumBots), 2)) + '% / ' + InttoStr(VotePerc) + '% requeridos para muda o mode.', Color);
   end else WriteConsole(ID,'Error, Mode ID: ' + GetPiece(Text,' ',1) + ' não encontrado.',Color);
     
end;

procedure AppOnIdle(Ticks: integer);

var
        i, b : integer;
begin

  if Time > 0 then begin
    Time := Time - 1;
  end;
 
  if Time = 0 then begin
    for b := 1 to 32 do Voted[b] := false;
 
 
end;
end;

Offline Mighty

  • Camper
  • ***
  • Posts: 276
Re: Problem with voting
« Reply #1 on: January 22, 2011, 05:49:36 am »
I'd try putting "Total" variable into global. but that's a quick thing, idk if it will solve the problem.
xFire: macmil        e-mail: macekmil@gmail.com
My scripts: Accuracy Script       Flashbang       Punishments GUID
            CatchMe Gamemod       AntiFake
            CW System             AntiFakeGUID

Offline hugoleonardofa

  • Major(1)
  • Posts: 5
Re: Problem with voting
« Reply #2 on: January 22, 2011, 07:22:33 pm »
The problem remains, please help me to make it work  :-\

Offline Stuffy

  • Soldier
  • **
  • Posts: 182
  • Very stuffy.
    • Climb-Zone Forum
Re: Problem with voting
« Reply #3 on: January 23, 2011, 12:05:45 pm »
OnJoinGame and OnLeave game is missing. I'll post you my original version.

Code: [Select]
const
Color = $E56600;
VoteTime = 60;
AddTime = 15;
VotePerc = 65;

var
Voted : array[1..32] of boolean;
VoteRun, EnDis, Enable : boolean;
Time : integer;
Script : string;

procedure ScriptChange(const ScriptName : string; const State : boolean);

var
Index, SIndex : string;
rec : boolean;

begin
  if not FileExists('scripts/' + ScriptName + '/Includes.txt') then begin
  exit;
  end;
  Index := ReadFile('scripts/' + ScriptName + '/Includes.txt');
    SIndex := Copy(Index,0,length(Index));
  rec := false;
    if (State) and (Copy(Index,0,2) = '//') then begin
      WriteFile('scripts/' + ScriptName + '/Includes.txt',Copy(Index,3,length(Index)));
    rec := true;
    end else if not (State) and (Copy(Index,0,2) <> '//') then begin
      WriteFile('scripts/' + ScriptName + '/Includes.txt','//' + SIndex);
    rec := true;
    end else if not (State) and (Copy(Index,0,2) = '//') then begin
  rec := false;
    end else if (State) and (Copy(Index,0,2) <> '//') then begin
      rec := false;
        end;
    if rec then begin
      Command('/recompile ' + ScriptName);
    end else if not rec then exit;
end;

procedure ActivateServer();
begin
  Enable := true;
end;
 
function GetScriptState(const ScriptName : string): boolean;

var
Index : string;

begin

  if FileExists('scripts/' + ScriptName + '/Includes.txt') then begin
    Index := ReadFile('scripts/' + ScriptName + '/Includes.txt');
  if Copy(Index,0,2) = '//' then begin
    Result := false;
  end else Result := true
  end;
end;

procedure OnJoinGame(ID, Team: byte);
begin
  Voted[ID] := false;
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;
      Enable := false;
      WriteConsole(0, 'Scriptvote passed', Color);
      ScriptChange(Script,EnDis);
    end else WriteConsole(0,FloattoStr(RoundTo(100 * Total / (NumPlayers - NumBots), 2)) + '% / ' + InttoStr(VotePerc) + '% required for a vote pass', Color);
  end;
end;



procedure OnPlayerSpeak(ID: byte; Text: string);

var
Total, i : integer;
begin
  if (LowerCase(GetPiece(Text,' ',0)) = '!change') and not (Voted[ID]) and (Enable) then
    if (GetPlayerStat(ID,'Active')) then
  if FileExists('scripts/' + GetPiece(Text,' ',1) + '/Includes.txt') then begin
    Total := Total + 1;
      Voted[ID] := true;
        VoteRun := true;
  if Time = 0 then Time := VoteTime else Time := Time + AddTime;
        if GetScriptState(GetPiece(Text,' ',1)) = true then begin
      EnDis := false;
    WriteConsole(ID,'Player ' + IdToName(ID) + ' voted to enable the script ' + GetPiece(Text,' ',1),Color);
end else if GetScriptState(GetPiece(Text,' ',1)) = false then begin
      EnDis := true;
    WriteConsole(ID,'Player ' + IdToName(ID) + ' voted to disable the script ' + GetPiece(Text,' ',1),Color);
end;
  Script := GetPiece(Text,' ',1);
 
    if (100 * Total / (NumPlayers - NumBots) >= VotePerc) then begin
      for i := 1 to 32 do Voted[ID] := false;
    WriteConsole(ID,'Script-Change vote passed! Script "' + Script + '" is now ' +iif(EnDis,'en','dis') + 'abled',Color);
      ScriptChange(Script,EnDis);
 end else WriteConsole(0,FloatToStr(RoundTo(100 * Total / (NumPlayers - NumBots), 2)) + '% / ' + InttoStr(VotePerc) + '% required for a vote pass', Color);
   end else WriteConsole(ID,'Error, Script ' + GetPiece(Text,' ',1) + ' not found.',Color);
end;

procedure AppOnIdle(Ticks: integer);

var
i, b : integer;
begin

  if Time >= 0 then begin
    Time := Time - 1;
  end;
 
  if Time = 0 then begin
    for b := 1 to 32 do Voted[b] := false;
  WriteConsole(0, 'Script-Vote failed', Color);
  end;
end;
« Last Edit: January 23, 2011, 12:08:04 pm by Stuffy »
The truth is out there? Does anyone know the URL?
The URL is here