Author Topic: [unstable] mapsList  (Read 2710 times)

0 Members and 1 Guest are viewing this topic.

Offline cooz

  • Soldier
  • **
  • Posts: 187
  • BANNED
[unstable] mapsList
« on: November 07, 2006, 05:07:44 am »
Script Name: mapsList
Script Description: simple script that shows mapslist on /mapslist (for admin), !mapslist (for players) command
Original Author: cooz
Core Version: 2.5.2

Code: [Select]
const
  ADMIN_MLIST_ON=1;      //turn off/on admin /mapslist command
  PLAYER_MLIST_ON=1;     //turn off/on player !mapslist command
var
  mapsList: TStringArray;
  i: integer;

procedure OnCommand(ID: integer;Text: string);
begin
  if((Text='/mapslist')and(ADMIN_MLIST_ON=1)) then begin
    mapsList:= split(ReadFile('mapslist.txt'),chr(13)+chr(10));
    for i:=0 to ArrayHigh(mapsList)-1 do SayToPlayer(ID,mapsList[i]);
  end;
end;

procedure OnPlayerSpeak(Name,Text: string);
begin
  if((Text='!mapslist')and(PLAYER_MLIST_ON=1)) then begin
    mapsList:= split(ReadFile('mapslist.txt'),chr(13)+chr(10));
    for i:=0 to ArrayHigh(mapsList)-1 do SayToPlayer(NametoID(Name),mapsList[i]);
  end;
end;

note:
script doesn't work on linux servers cause of bug in split() function, it will be fixed in next dedicated version
« Last Edit: November 21, 2006, 08:01:24 pm by cooz »
Dead man! Dead man walking! We got a dead man walking here! Banned man crawling more like

Offline Dizzy So 1337

  • Soldier
  • **
  • Posts: 246
Re: [unstable] mapsList
« Reply #1 on: October 09, 2007, 04:51:54 pm »
I really want this script for my server that hosts only new maps.  But it doesn't work for me.  The server will not go online.  Which could be a) because I am a noob, b) old Core version, c) this script never really worked in the first place, or d)???

Would anyone like to help, advise, fix, update, or write a new one?  I find the concept of this script very sound.

Date Posted: August 03, 2007, 12:57:44 am
Still want this script or one like it.  Any pointers/help?
xfire - todhostetler
"There's nothing I wouldn't do to win. But I never hurt anyone except to stick a dogskull on a stake."

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: [unstable] mapsList
« Reply #2 on: October 09, 2007, 08:24:18 pm »
(a + b + d) i'd say :P

Code: [Select]
// xsplit by KeYDoN
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;

function OnCommand(ID: byte; Text: string): boolean;
var
  lines: TStringArray;
  i: integer;
begin
  Result := false;
  if LowerCase(Text) = '/mapslist' then
  begin
    lines := xsplit(ReadFile('mapslist.txt'), chr(13) + chr(10));
    for i := 0 to GetArrayLength(lines) - 1 do
    begin
      if ID <> 255 then
        WriteConsole(ID, lines[i], $FFFFFFFF)
      else
        WriteLn(lines[i]);
    end;
  end;
end;

procedure OnPlayerSpeak(ID: byte; Text: string);
var
  lines: TStringArray;
  i: integer;
begin
  if LowerCase(Text) = '!mapslist' then
  begin
    lines := xsplit(ReadFile('mapslist.txt'), chr(13) + chr(10));
    for i := 0 to GetArrayLength(lines) - 1 do
      WriteConsole(ID, lines[i], $FFFFFFFF);
  end;
end;

(never tested)
urraka

Offline Dizzy So 1337

  • Soldier
  • **
  • Posts: 246
Re: [unstable] mapsList
« Reply #3 on: October 11, 2007, 02:36:01 pm »
Awesome dude thanks this one works.  This will be very helpful.  The only problem is that only the last 20 maps can be viewed.

Eh, I don't know if you or anyone else wants to tackle that (ie 'wrapping' the list across the screen instead of straight down), but I'd like to put this alternate solution proposal out there:

What would be awesome is if I made separate maplists on my server such as climbmaps.txt, ctfmaps.txt, twmaps.txt, etc.  So the different commands could pull up just those lists.

I tried a modification of this script that pulls up my climbmaps for example.  That worked fine.  But when I tried (oh Dizzy u noob) to simply replicate your code starting with function OnCommand(ID:..., so as to have the one script capable of calling from multiple lists, that didn't fly.

Is it possible could someone show me which parts of the script could be cloned, so that I could have it pull from multiple lists?  I hope you will not find this suggestion/request eh, ungrateful in any way :)  If I have to, I'll just make multiple versions of the script for each list.    But a more elegant solution would be greatly appreciated.
xfire - todhostetler
"There's nothing I wouldn't do to win. But I never hurt anyone except to stick a dogskull on a stake."

Offline deguix

  • Major
  • *
  • Posts: 79
Re: [unstable] mapsList
« Reply #4 on: October 15, 2007, 01:42:45 pm »
If the second code works and you just want to get list from dif files, then just change the file name whenever you need to access the different file... it should work... (like using "case" or "if"s to see if the user wants to access a dif file...)