Author Topic: Map Seach by Polifen  (Read 1437 times)

0 Members and 1 Guest are viewing this topic.

Offline Polifen

  • Soldier
  • **
  • Posts: 127
Map Seach by Polifen
« on: February 06, 2011, 05:54:25 am »
Just a short one, searching for string in mapslist and displays matches.
Requested script.

Requested by me, but Mighty's didn't work as it should, it caused big lag with my 1250 lines mapslist. Mine works with no problem. You can specify file to search ( i'm not gonna use mapslist.txt, but list.txt created with Shell_Exec('ls maps > list.txt'); for example).

Code: [Select]
const
  Color = $FFFF0000;
  file = 'mapslist.txt';
 
function Explode(Source: string; const Delimiter: string): array of string;
var
  Position, DelLength, ResLength: integer;
begin
  DelLength := Length(Delimiter);
  Source := Source + Delimiter;
  repeat
    Position := Pos(Delimiter, Source);
    SetArrayLength(Result, ResLength + 1);
    Result[ResLength] := Copy(Source, 1, Position - 1);
    ResLength := ResLength + 1;
    Delete(Source, 1, Position + DelLength - 1);
  until (Position = 0);
  SetArrayLength(Result, ResLength - 1);
end;

procedure Search(ID : byte; Text : string);
var
i : integer;
list : array of string;
begin
if FileExists(file) = true then begin
list := Explode(ReadFile(file), chr(13) + chr(10));
for i := 0 to ArrayHigh(list) - 1 do
if ContainsString(LowerCase(list[i]), Text) then WriteConsole(ID, list[i], Color);
end
else WriteConsole(ID, 'File with mapslist does not exist', Color);
end;

function OnPlayerCommand(ID: Byte; Text: string): boolean;

begin
if LowerCase(Copy(Text, 1, 8)) = '/search ' then begin
Delete(Text, 1, 8);
Search(ID, LowerCase(Text));
end;
 
  Result := false;
end;



Edit: Added LowerCase functions, to disable case sensitivity. Now you can use /search My_MAp, and it will find both my_map and MY_MaP.

Edit2: Added LowerCase to the Copy function too.

Edit3: Added spacebar and changed copy 7 to copy 8. Better now? I'd not say it's a big difference.
« Last Edit: February 07, 2011, 02:58:11 am by Polifen »

Offline SyavX

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 338
Re: Map Seach by Polifen
« Reply #1 on: February 06, 2011, 11:16:31 am »
Hint: replace this line
Code: [Select]
   if Copy(Text, 1, 7) = '/search' then begin
with something like this
Code: [Select]
   if LowerCase(Copy(Text, 1, 8)) = '/search ' then begin

Update:
Quote
Edit2: Added LowerCase to the Copy function too.
It's sad that you didn't get the whole point of my suggestion...
« Last Edit: February 06, 2011, 01:16:23 pm by SyavX »