Official Soldat Forums
Server Talk => Scripting Releases => Topic started by: cooz 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
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
-
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?
-
(a + b + d) i'd say :P
// 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)
-
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.
-
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...)