Author Topic: [Release] Vote random map (with time)  (Read 2574 times)

0 Members and 1 Guest are viewing this topic.

Offline DhD

  • Major(1)
  • Posts: 2
[Release] Vote random map (with time)
« on: June 15, 2007, 12:58:46 pm »
Script Name: Vote random map
Script Description: Players can vote a random map by !voterandom. If they vote, they can't vote again until the time you have set is over. When map is changed the time will be reseted.
Original Author(s): DhD (DieHardDie)
Core Version: 2.6.1

If you want the script to work, you have to make a .txt file and edit the name in the script. Standard the name is randmaplist.txt
You can also adjust the time that the players have to wait before they can vote again.

Code: [Select]
const
  iTimer  = (3*60);            {time in seconds that the players have to wait before voting}
  sRanMap = 'randmaplist.txt'; {text file where the list of maps to choose from is}
var
  aPlayer: array[1..32] of Integer;

function OnRequestGame(IP: string; State: integer): integer;
begin
  Result := State;
end;

procedure OnMapChange(NewMap: string);
  var
    iFor: integer;
begin

  for iFor := 1 to 32 do begin
 
    aPlayer[iFor] := TimeLeft;
  end;
end;

procedure OnJoinTeam(ID, Team: byte);
begin
 
  aPlayer[ID] := TimeLeft;
end;

function xSplit(const source: string; const delimiter: string):TStringArray;
  var
    i,x,d:integer;
    s:string;
   
begin
 
  d:=length(delimiter);
  x:=0;
  i:=1;
  SetArrayLength(Result,1);
 
  while(i<=length(source)) do begin
 
    s:=Copy(source,i,d);
   
     if(s=delimiter) then begin
     
      inc(i,d);
      inc(x,1);
      SetArrayLength(result,x+1);
    end
    else begin
   
      result[x]:= result[x]+Copy(s,1,1);
      inc(i,1);
    end;
  end;
end;

procedure VoteMap(cText: string; Name: integer);
  var
    iList: Integer;
    iRep:  Integer;
    aList: TStringArray;
    sMap:  String;

begin
 
  iList := 1;
  if ((aPlayer[Name]-iTimer) >= TimeLeft) then begin
   
    if (FileExists(sRanMap)) then begin
     
      aList := xSplit(ReadFile(sRanMap), (chr(13)+chr(10)));
      iList := ArrayHigh(aList);
      sMap  := aList[random(0, iList)]
     
      repeat
       
        sMap := aList[random(0, iList)]
        iRep := iRep+1;
      until (sMap <> CurrentMap) or (iRep = 10);
     
      StartVoteMap(Name, sMap);
     
      aPlayer[Name] := TimeLeft;
    end
    else begin
     
      Command('/say Map list is not found.');
    end;
  end
  else begin
   
    Command('/say You have to wait ' + IntToStr(TimeLeft - (aPlayer[Name]-iTimer)) + ' seconds till next vote.');
  end;
end;

function OnPlayerSpeak(Name: string; Text: string): boolean;
  var
    cText:  String;
   
begin
 
  cText  := LowerCase(Text);
 
  if (cText = '!voterandom') then begin
   
    VoteMap(cText, StrToInt(Name));
  end;
end;

Thanks to all the scripts on this site and enesce!
« Last Edit: June 15, 2007, 01:38:21 pm by DhD »

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: [Release] Vote random map (with time)
« Reply #1 on: June 15, 2007, 01:13:58 pm »
The OnPlayerSpeak event, the correct is

Code: [Select]
procedure OnPlayerSpeak(ID: Byte; Text: string);
Maybe you should check also if the random map isn't the CurrentMap, so you don't vote the map you are playing on.
urraka

Offline DhD

  • Major(1)
  • Posts: 2
Re: [Release] Vote random map (with time)
« Reply #2 on: June 15, 2007, 01:37:25 pm »
Thanks for your fast reaction! I changed it and I'll edit my post!

Offline kusyi

  • Major(1)
  • Posts: 8
  • Ural Clan
Re: [Release] Vote random map (with time)
« Reply #3 on: June 16, 2007, 02:28:32 am »
thx
^^

Offline miketh2005

  • Soldat Beta Team
  • Flagrunner
  • ******
  • Posts: 668
  • What's the URL for www.microsoft.com?
Re: [Release] Vote random map (with time)
« Reply #4 on: August 23, 2007, 05:50:25 pm »
can someone sip this to work with new Core version? too lazy to do it myself :( sry thanx
Quote from: 'Ando.' pid='12999178' dateline='1309046898'
My new password is secure as shit :)
Mate, I am not sure Shit is even secured nowadays.

Offline Iq Unlimited

  • Flagrunner
  • ****
  • Posts: 863
  • mr. foobar2000
Re: [Release] Vote random map (with time)
« Reply #5 on: August 23, 2007, 08:48:35 pm »
sure, gimme 3 seconds...

here.

« Last Edit: August 24, 2007, 11:40:34 am by Iq Unlimited »

Offline miketh2005

  • Soldat Beta Team
  • Flagrunner
  • ******
  • Posts: 668
  • What's the URL for www.microsoft.com?
Re: [Release] Vote random map (with time)
« Reply #6 on: August 25, 2007, 01:39:30 pm »
thanx
Quote from: 'Ando.' pid='12999178' dateline='1309046898'
My new password is secure as shit :)
Mate, I am not sure Shit is even secured nowadays.