Author Topic: help file system + daemon  (Read 5324 times)

Offline detah

  • BFF
  • ***
  • Posts: 190
  • Ruler of 2D
    • View Profile
help file system + daemon
« on: October 02, 2006, 05:33:16 PM »
An alternative Help File System.



Features:

* _NO_ interactive menus!

* automated indexing system ie displays your exact location in the help structure at the top of each output.

* individual files can include color tags

* forgiving parsing. The program ignores spacing and capitalization.

* its a simple matter to have multiple keywords directed to one help file. see the 'help i' and 'help inv' code for an example

* its a simple matter to adjust for unusual characters in words like the hyphen in half-elf. use the same feature as in 'inventory' to direct the system to the halfelf.c file.



To utilize this help code:

1) Take /daemon/help.c, /lib/help.c and /cmds/common/help.c and move them to a temp directory somewhere for backup purposes.

2) Copy the below help.c file and place it in /cmds/common/.

3) Place your own created help files in the respective directories.

I currently have 3 paths setup in the file below: /doc/help/players/*.*, /doc/help/players/information/*.* and /doc/help/players/movement/*.*.  So for example, if you wanted to have a 'help age' helpfile, then you would create a .c file for age and place it /doc/help/players/information/age.c.

4) update /cmds/common/help.c

DONE//



code:

/****************************************
 *  /cmds/common/help.c                 *
 *  Help File System                    *
 *  writes header, path index, helpfile *
 *  name, helpfile output, footer       *
 *  Created by Detah@Arcania 8-6-06     *
 *  Last Modified 9-27-06               *
 ****************************************/
#include <lib.h>
inherit LIB_DAEMON;
#define HEADBAR "%^BLUE%^+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+%^RESET%^"

string array players=({"combat","communication","guilds","information","miscellaneous","movement","object","powers","races","schools","skills","spells","spheres","stats","utility","help"});
string array information=({"age","areas","biography","bluetokens","commands","effects","eq","equipment","faq","i","inv","inventory","levels","levels2","levels3","levels4","maps","newbie","news","peer","plan","pharmacopeia","platinumtokens","rcost","redtokens","regen","report","rquest","rules","scan","score","score2","session","who","who2","wizlist"});
string array movement=({"climb","crawl","dig","general","down","east","enter","follow","jump","north","northeast","northwest","out","rest","sit","sleep","south","southeast","southwest","stand","swim","unfollow","up","wake","west"});

mixed cmd(string arg) {
    string arg2;
    string htitle="";
    string content;
    string dirf="";
    string helppath="";
    string array dira;
    int docsnum, dirscount, x, y, i;

  if(!stringp(arg)) {
    helppath="";
    arg2="none";
  }  
  if(!arg || arg=="") {
    helppath="/doc/help/players/help.c";
    arg2="none";
  }  
  if(stringp(arg)) {
  arg2=convert_name(lower_case(arg));
  }

/*Border and Mudname header*/
write(HEADBAR);
write(sprintf("%%^BLUE%%^|%%^WHITE%%^%*' '|s %%^BLUE%%^|%%^RESET%%^", 59, mud_name() + " Help System"));
write(HEADBAR);

/*Assigns path of help file*/

//if(!arg || arg2=="" || arg2=="help" || (member_array(arg2, players) != -1)) {
if(member_array(arg2, players) != -1) {
  helppath="/doc/help/players/"+arg2+".c";
}

if(member_array(arg2, information) != -1) {
  helppath="/doc/help/players/information/"+arg2+".c";
  if(arg2=="eq") helppath="/doc/help/players/information/equipment.c";
  if(arg2=="i" || arg2=="inv") helppath="/doc/help/players/information/inventory.c";
}

if(member_array(arg2, movement) != -1) {
  helppath="/doc/help/players/movement/"+arg2+".c";
  if(member_array(arg2,({"down","east","enter","north","northeast","northwest","out","south","southeast","southwest","up","west"}) )!=-1) helppath="/doc/help/players/movement/general.c";
}

/*Lattice to show Help File structure and produce index*/
dira = explode(helppath,"/");              //places each subdir in an array called dira
docsnum = member_array("players", dira);   //returns the array element number for docs
dirscount = sizeof(dira);                 //returns the number of elements in the array dira
x = docsnum+1;                             //x defines first subdir after /players/
y = dirscount-1;                           //y defines the second to last element of the array, the enddir
dirf+="%^WHITE%^HELP > ";
for(i=x; i<y; i++) {
  dirf+=(upper_case(dira));
  dirf+=" > ";
}
dirf+="\n";
if(arg) dirf+="Index: %^YELLOW%^" + capitalize(arg) + "%^CYAN%^";

/*Writing Help Output to player*/
write(dirf);
if(helppath=="") {
  write("\nThere is no help file for that word.");
  write("If you would like to see a help file for something, make an idea log.\n");
}
content=helppath;
write(read_file(content));
write(HEADBAR);

return 1;
}




Constructive comments welcome.

Offline saquivor

  • BFF
  • ***
  • Posts: 110
    • View Profile
help file system + daemon
« Reply #1 on: October 03, 2006, 12:11:16 AM »
Cool post Detah. Any chance you could post a couple of example help files. To give some info on formattting et all.



Saquivor

Offline detah

  • BFF
  • ***
  • Posts: 190
  • Ruler of 2D
    • View Profile
help file system + daemon
« Reply #2 on: October 03, 2006, 06:03:01 AM »
Here are 3 example files. I chose 1 for each of the example arrays/directories in the help code.



Place http://www.monkeyx.net/spells.c">spells.c in /doc/help/players/.

Place http://www.monkeyx.net/levels.c ">levels.c in /doc/help/players/information/.

Place http://www.monkeyx.net/sleep.c ">sleep.c in /doc/help/players/movement/.



Note: you do NOT need to remove any of the existing stock help files, unless you want to.



You probably dont need to update help.c if you already have.

Then just type 'help spells', 'help levels' and 'help sleep'.



My help system utilizes the read_file efun. There is a really nice sideeffect of using this efun....you can add your color coding directly to the help files themselves.  So each file can be color-managed separately.

Offline daelaskai

  • BFF
  • ***
  • Posts: 174
    • View Profile
help file system + daemon
« Reply #3 on: October 03, 2006, 07:45:08 AM »

Very Cool indeed :)





Daelas/Amun-Ra


Offline detah

  • BFF
  • ***
  • Posts: 190
  • Ruler of 2D
    • View Profile
help file system + daemon
« Reply #4 on: November 04, 2006, 08:36:31 PM »

you may need to do

update /daemon/command

to use the new help system.



I do not fully understand the circumstances which cause the need to do this, but I had my help command named myhelp.c for testing purposes, then I decided to delete the stock DS help.c files entirely. I then renamed my myhelp.c to help.c. I updated

-r /lib/creator and -r /cmds/common/help

and strangely, 'myhelp' still worked.

The only way to take an old system out of memory is to update /daemon/command.



Just thought I would mention it incase someone ran into this situation.


Offline Thales

  • Acquaintance
  • *
  • Posts: 2
    • View Profile
Re: help file system + daemon
« Reply #5 on: December 26, 2006, 02:23:35 AM »
I had to re-implement this in my mud, and I can't remember the last little detail that I had to add to make this work without loading errors.

/cmds/players/help.c line 69: Bad argument 1 to efun upper_case()
   
---
*Error in loading object '/cmds/players/help'
Object: /secure/save/creators/t/thales (/lib/command.c) at line 93

'<function>' at /secure/save/creators/t/thales (<function>) at /:0
'cmdAll' at /secure/save/creators/t/thales (/lib/command.c) at line 93

is what I'm recieving when I try to use the help system in-game.  I know detah figured this one out for me earlier and I would appreciate a reminder.

Offline detah

  • BFF
  • ***
  • Posts: 190
  • Ruler of 2D
    • View Profile
Re: help file system + daemon
« Reply #6 on: December 27, 2006, 12:16:52 AM »
hmm.
please paste your lines 59-79 here and Ill take a look.
Nothing is springing to mind right now. Its probably a bracket type issue or an error on the definition of your directory name.

Offline Thales

  • Acquaintance
  • *
  • Posts: 2
    • View Profile
Re: help file system + daemon
« Reply #7 on: December 27, 2006, 01:55:28 AM »
/*Lattice to show Help File structure and produce index*/
dira = explode(helppath,"/");              //places each subdir in an array called dira
docsnum = member_array("players", dira);   //returns the array element number for docs
dirscount = sizeof(dira);                 //returns the number of elements in the array dira
x = docsnum+1;                             //x defines first subdir after /players/
y = dirscount-1;                           //y defines the second to last element of the array, the enddir
dirf+="%^WHITE%^HELP > ";
for(i=x; i<y; i++) {
  dirf+=(upper_case(dira));
  dirf+=" > ";
}
dirf+="\n";
if(arg) dirf+="Index: %^YELLOW%^" + capitalize(arg) + "%^CYAN%^";

/*Writing Help Output to player*/
write(dirf);
if(helppath=="") {
  write("\nThere is no help file for that word.");
  write("If you would like to see a help file for something, make an idea log.\n");
}

Offline detah

  • BFF
  • ***
  • Posts: 190
  • Ruler of 2D
    • View Profile
Re: help file system + daemon
« Reply #8 on: December 27, 2006, 09:50:57 AM »
dira is an array. So it needs an element number. In this case you are missing the element identifier.

Code: [Select]
  dirf+=(upper_case(dira[i]));

Try to conceptualize what these dira's look like. eg.
dira might be {"doc","help","players","information","levels"}
Then the FOR loop is grabbing all the directory names AFTER "players" and BEFORE the last one. Where the last one is the filename/helpkeyword.

PS
I see what has happened here. Somehow when the code section was imported into the new forums, it turned the square brackets with an i in it into the html code for italicized. Look closely at the last two parentheses. They are italicized.
« Last Edit: December 27, 2006, 10:03:30 AM by detah »

Offline detah

  • BFF
  • ***
  • Posts: 190
  • Ruler of 2D
    • View Profile
Re: help file system + daemon
« Reply #9 on: June 05, 2007, 03:23:38 PM »
Please use this. The above code was ported from the old forums and has inadvertantly converted some of the code into quasihtml code. ie. it wont copy correctly. The following is correct:

Code: [Select]
/****************************************
 *  /cmds/common/help.c                 *
 *  Help File System                    *
 *  writes header, path index, helpfile *
 *  name, helpfile output, footer       *
 *  Created by Detah@Arcania 8-6-06     *
 *  Last Modified 9-27-06               *
 ****************************************/
#include <lib.h>
inherit LIB_DAEMON;
#define HEADBAR "%^BLUE%^+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+%^RESET%^"

string array players=({"combat","communication","guilds","information","miscellaneous","movement","object","powers","races","schools","skills","spells","spheres","stats","utility","help"});
string array information=({"age","areas","biography","bluetokens","commands","effects","eq","equipment","faq","i","inv","inventory","levels","levels2","levels3","levels4","maps","newbie","news","peer","plan","pharmacopeia","platinumtokens","rcost","redtokens","regen","report","rquest","rules","scan","score","score2","session","who","who2","wizlist"});
string array movement=({"climb","crawl","dig","general","down","east","enter","follow","jump","north","northeast","northwest","out","rest","sit","sleep","south","southeast","southwest","stand","swim","unfollow","up","wake","west"});

mixed cmd(string arg) {
    string arg2, content;
    string htitle="";
    string dirf="";
    string helppath="";
    string array dira;
    int docsnum, dirscount, x, y, i;

  if(!stringp(arg)) {
    helppath="";
    arg2="none";
  } 
  if(!arg || arg=="") {
    helppath="/doc/help/players/help.c";
    arg2="none";
  } 
  if(stringp(arg)) {
  arg2=convert_name(lower_case(arg));
  }

/*Border and Mudname header*/
write(HEADBAR);
write(sprintf("%%^BLUE%%^|%%^WHITE%%^%*' '|s %%^BLUE%%^|%%^RESET%%^", 59, mud_name() + " Help System"));
write(HEADBAR);

/*Assigns path of help file*/
if(member_array(arg2, players) != -1) {
  helppath="/doc/help/players/"+arg2+".c";
}
if(member_array(arg2, information) != -1) {
  helppath="/doc/help/players/information/"+arg2+".c";
  if(arg2=="eq") helppath="/doc/help/players/information/equipment.c";
  if(arg2=="i" || arg2=="inv") helppath="/doc/help/players/information/inventory.c";
}
if(member_array(arg2, movement) != -1) {
  helppath="/doc/help/players/movement/"+arg2+".c";
  if(member_array(arg2,({"down","east","enter","north","northeast","northwest","out","south","southeast","southwest","up","west"}) )!=-1) helppath="/doc/help/players/movement/general.c";
}

/*Lattice to show Help File structure and produce index*/
dira = explode(helppath,"/");              //places each subdir in an array called dira
docsnum = member_array("players", dira);   //returns the array element number for docs
dirscount = sizeof(dira);                 //returns the number of elements in the array dira
x = docsnum+1;                             //x defines first subdir after /players/
y = dirscount-1;                           //y defines the second to last element of the array, the enddir
dirf+="%^WHITE%^HELP > ";
for(i=x; i<y; i++) {
  dirf+=(upper_case(dira[i]));
  dirf+=" > ";
}
dirf+="\n";
if(arg) dirf+="Index: %^YELLOW%^" + capitalize(arg) + "%^CYAN%^";

/*Writing Help Output to player*/
write(dirf);
if(helppath=="") {
  write("\nThere is no help file for that word.");
  write("If you would like to see a help file for something, make an idea log.\n");
}
content=helppath;
write(read_file(content));
write(HEADBAR);

return 1;
}

Instructions in post 1 are still the same.

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
Re: help file system + daemon
« Reply #10 on: August 10, 2011, 07:32:54 PM »
So I decided to prettify the output a little:  I improved the visibility of the borders, made the border fill the width of the user's terminal, and added left and right borders to the help area to keep the text together.  Two spaces are added after periods, exclamation points, question marks, and colons.  I added the additional feature of allowing a text in the helpfile to be centre-justified onscreen; prepend a line with '<c>' and it will be formatted.  If the text runs off onto additional lines, they too will be centre-justified.  The modification I made includes some drawbacks:  empty lines are ignored, so must contain a single space to appear in the display; multiple spaces are also ignored, so including columnar or otherwise formatted text is not possible.  There is an experimental feature, two-column mode, which splits the text in half across two 'pages' on the screen.  This looks silly when there isn't much text to handle.

Code: [Select]
/****************************************
 *  /cmds/common/help.c
 *  Help File System
 *  writes header, path index, helpfile name, helpfile output, footer
 *  Created by Detah@Arcania 8-6-06
 *  Last Modified 9-27-06
 *  modified 2011-Aug-09 by T. Cook to improve display
 *  modified 2011-Aug-10 by T. Cook to correct errors in handling <c> tag
 ****************************************/
#include <lib.h>
inherit LIB_DAEMON;
#define COLMODE 1

string array players = ({
"combat", "communication", "guilds", "information", "miscellaneous", "movement", "object",
"powers", "races", "schools", "skills", "spells", "spheres", "stats", "utility", "help"
});
string array information = ({
"age", "areas", "biography", "bluetokens", "commands", "effects", "eq", "equipment", "faq",
"i", "inv", "inventory", "levels", "levels2", "levels3", "levels4", "maps", "newbie",
"news", "peer", "plan", "pharmacopeia", "platinumtokens", "rcost", "redtokens", "regen",
"report", "rquest", "rules", "scan", "score", "score2", "session", "who", "who2", "wizlist"
});
string array movement = ({
"climb", "crawl", "dig", "general", "down", "east", "enter", "follow", "jump", "north",
"northeast", "northwest", "out", "rest", "sit", "sleep", "south", "southeast", "southwest",
"stand", "swim", "unfollow", "up", "wake", "west"
});

mixed cmd( string arg ){
//---- declare variables
string arg2, content, htitle, dirf, helppath, hr1, hr2, hr3, spaces, s_temp1, s_temp2;
string array dira, sa_temptext1, sa_temptext2, sa_temptext3, sa_helptext;
int docsnum, dirscount, x, y, i, i2, scr_x, pagewidth, cflag;
//---- initialise variables
htitle = ""; dirf = ""; helppath = "";
hr1 =  "--------------------------------------------------------------------------------";
hr1 += "--------------------------------------------------------------------------------";
hr1 += "--------------------------------------------------------------------------------";
hr2 =  "================================================================================";
hr2 += "================================================================================";
hr2 += "================================================================================";
hr3 =  "----+---01----+---02----+---03----+---04----+---05----+---06----+---07----+---08";
hr3 += "----+---09----+---0A----+---0B----+---0C----+---0D----+---0E----+---0F----+---10";
spaces =  "                                                                                ";
spaces += "                                                                                ";
spaces += "                                                                                ";
//---- get the width of the player's screen; assign help page width
scr_x = this_player()->GetScreen()[0] - 1;
if( scr_x < 40 ){ scr_x = 40; }
if( COLMODE == 2 ){ pagewidth = ( this_player()->GetScreen()[0] - 10 ) / 2; }
else{ pagewidth = this_player()->GetScreen()[0] - 6; }
//---- process argument passed to help command
if( !stringp( arg ) ){ helppath = ""; arg2 = "none"; } 
if( !arg || arg == "" ){ helppath = "/doc/help/players/help.c"; arg2 = "none"; } 
if( stringp( arg ) ){ arg2 = convert_name( lower_case( arg ) ); }
//---- display top border and mudname
write( "%^BOLD%^%^BLUE%^+" + hr2[0..(scr_x - 2)] + "+%^RESET%^" );
write( sprintf(
"%%^BOLD%%^%%^BLUE%%^|%%^RESET%%^%*' '|s %%^BOLD%%^%%^BLUE%%^|%%^RESET%%^",
scr_x - 2,
mud_name() + " Help System"
) );
//---- assign path of help file
if( member_array( arg2, players ) != -1 ){
helppath = "/doc/help/players/" + arg2 + ".c";
}
if( member_array( arg2, information ) != -1 ){
helppath = "/doc/help/players/information/" + arg2 + ".c";
if( arg2 == "eq" ){ helppath = "/doc/help/players/information/equipment.c"; }
if( arg2 == "i" || arg2 == "inv" ){ helppath = "/doc/help/players/information/inventory.c"; }
}
if( member_array( arg2, movement ) != -1 ){
helppath = "/doc/help/players/movement/" + arg2 + ".c";
if( member_array( arg2, ({
"down", "east", "enter", "north", "northeast", "northwest", "out", "south", "southeast",
"southwest", "up", "west"
}) )!=-1 ){ helppath = "/doc/help/players/movement/general.c"; }
}
//---- display help file path & header border
dira = explode( helppath, "/" );            // places each subdir in an array called dira
docsnum = member_array( "players", dira );  // returns the array element number for docs
dirscount = sizeof( dira );                 // returns the number of elements in the array dira
x = docsnum + 1;                            // x defines first subdir after /players/
y = dirscount - 1;                          // y defines 2nd-to-last array element, the enddir
dirf += "%^CYAN%^Help%^RESET%^ > ";
for( i = x; i < y; i++ ){
dirf += ( "%^CYAN%^" + capitalize( dira[i] ) + "%^RESET%^");
dirf += " > ";
}
if( arg ){ dirf += "%^BOLD%^%^CYAN%^" + capitalize( arg ) + "%^RESET%^"; }
write(
"%^BOLD%^%^BLUE%^|%^RESET%^  " + dirf +
spaces[0..( scr_x - sizeof( strip_colors( dirf ) ) - 4 )] + "%^BOLD%^%^BLUE%^|%^RESET%^"
);
write( "%^BOLD%^%^BLUE%^+" + hr1[0..(scr_x - 2)] + "+%^RESET%^" );
//---- build & display text block
content = helppath;

s_temp1 = s_temp2 = ""; sa_temptext1 = sa_helptext = ({});
// put each line into array element
if( helppath == "" ){
sa_temptext1 = ({ "<c>%^FLASH%^%^RED%^Attention!%^RESET%^","No help file " +
"could be found for " + arg + "!  To request addition of a help topic, use the " +
"'%^B_WHITE%^%^BLACK%^idea%^RESET%^' command." });
}else{
sa_temptext1 = explode( read_file( content ), "\n" );
}
for( i = 0; i < sizeof( sa_temptext1 ); i++ ){
// put each word into array element
s_temp1 = replace_string( sa_temptext1[i], "<c>", "" );  // sans <c>
sa_temptext2 = explode( s_temp1, " " ) - ({ "" });
sa_temptext3 = explode( strip_colors( s_temp1 ), " " ) - ({ "" });  // colorless
s_temp1 = "";
if( sa_temptext1[i] == " " ){
s_temp2 += spaces[0..pagewidth-1] + "\n";
}
for( i2 = 0; i2 < sizeof( sa_temptext2 ); i2++ ){
// will this word and a space fit on this line?
if( sizeof( strip_colors( s_temp1 ) ) + sizeof( sa_temptext3[i2] ) + 1 < pagewidth ){
s_temp1 += sa_temptext2[i2];  // add the word
// are we before the last word of this line?
if( i2 < sizeof( sa_temptext2 ) - 1 ){
s_temp1 += " ";  // add a space
switch( sa_temptext3[i2][<1..<1] ){
case ".":
case ":":
case "?":
case "!": s_temp1 += " "; break;  // add a second space where relevant
default: break;
}
}
// last word of line, will fit, add to block of text
else{
// if first element of the lines was <c>, center the text
if( sa_temptext1[i][0..2] == "<c>" ){
s_temp2 += sprintf(
"%s%s%s\n",
spaces[0..( pagewidth - sizeof( strip_colors( s_temp1 ) ) - 2 ) / 2 ],
s_temp1,
spaces[0..( pagewidth - sizeof( strip_colors( s_temp1 ) ) - 1 ) / 2 ]
);
}
// just add the text
else{
s_temp2 += sprintf(
"%s%s\n",
s_temp1,
spaces[0..pagewidth - sizeof( strip_colors( s_temp1 ) ) - 1]
);
s_temp1 = "";
}
}
}
// word won't fit on this line
else{
// if first element of the line in the file was <c>, center the text
if( sa_temptext1[i][0..2] == "<c>" ){
s_temp2 += sprintf(
"%s%s%s\n",
spaces[0..( pagewidth - sizeof( strip_colors( s_temp1 ) ) - 1 ) / 2 - 1],
s_temp1,
spaces[0..( pagewidth - sizeof( strip_colors( s_temp1 ) ) ) / 2 ]
);
}
// add the text to the block
else{
s_temp2 += sprintf(
"%s%s\n",
s_temp1,
spaces[0..pagewidth - sizeof( strip_colors( s_temp1 ) ) - 1]
);
}
// begin to build next line
s_temp1 = sa_temptext2[i2];  // add the word
// are we before the last word of this line?
if( i < sizeof( sa_temptext2 ) - 1 ){
s_temp1 += " ";
if( sa_temptext3[i2][<1..<1] == "." || sa_temptext3[i2][<1..<1] == ":" ){
s_temp1 += " ";  // add a second space after colons and periods
}
}
}
}
}
//----  output the help text & bottom border
sa_helptext = explode( s_temp2, "\n" );
if( COLMODE == 2 ){
for( i = 0; i < sizeof( sa_helptext ) / 2; i++ ){
write(
"%^BOLD%^%^BLUE%^|%^RESET%^  " +
sa_helptext[i] +
"  %^BOLD%^%^BLUE%^|%^RESET%^  " +
sa_helptext[sizeof( sa_helptext ) / 2 + i] +
"  %^BOLD%^%^BLUE%^|%^RESET%^"
);
}
}else{
for( i = 0; i < sizeof( sa_helptext ); i++ ){
write(
"%^BOLD%^%^BLUE%^|%^RESET%^  " +
sa_helptext[i] +
"  %^BOLD%^%^BLUE%^|%^RESET%^"
);
}
}
write( "%^BOLD%^%^BLUE%^+" + hr2[0..(scr_x - 2)] + "+%^RESET%^" );
return 1;
}

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
Re: help file system + daemon
« Reply #11 on: August 11, 2011, 08:45:14 PM »
An important note:  removing /lib/help.c and /daemon/help.c make the mud very sad and stop responding to basic commands like 'north' and 'examine' and so forth.

Offline detah

  • BFF
  • ***
  • Posts: 190
  • Ruler of 2D
    • View Profile
Re: help file system + daemon
« Reply #12 on: July 30, 2013, 03:35:00 PM »
I thought I had posted this eons ago, but I cannot find it on the forum.

Here is an addition to my help file system. If a player types in a keyword which does not have a precise file match, then this code will allow you to give the player suggestions for other help keywords to search for.  For instance, if the player types 'help fire', you have no help file for fire, but you do have help files for fireball, wall of fire and firebreath, then this will spit out something like the following:

There is no help file for that term. See also: fireball, wall of fire and firebreath.

Code: [Select]
/********************************************************
 *           Help File System Augmentations             *
 * Author: Detah@Arcania 2-22-08                        *
 * Desc: loads all help files into a single array,      *
 *   helpfiles, searches for substring matching the     *
 *   string given by the player, displays matches at    *
 *   bottom of the Help File output.                    *
 * Example: A player types 'help fire', this augment    *
 *   will find all helpfiles with 'fire' as a substring.*
 *   eg. "firebolt", "firebreath", "fireshield" in      *
 *   addition to the 'fire' listing.                    *
 ********************************************************/
int w, x, y, z;
string a;
string array helpfiles, dirs, dirs1, dirs2, dirs3, dirs4, dirs5;
a="/doc/help/players/";

string array get_alt_files(a) {
/*defines starting dir and collects all dirs&files from that dir*/
dirs1=get_dir(a);  /*dirs1=({"chelp","combat","combat.c"...}) */
w=sizeof(dirs1);   /*x=35                                     */

/*collects dirs&files from dirs1*/
for(i=0; i<w; i++) {
     n=strlen(dirs1[i]);
     if(dirs1[i][n-1..n]!=".c") {   /*these are the dirs (since I used .c as my help file extentions)*/
   dirs2+=a+dirs1[i]+"/";       /*fills dirs2 with full paths; dirs2=({"/doc/help/players/chelp/","/doc/help/players/combat/"...}) */
     }
     if(dirs1[i][n-1..n]==".c") {   /*these are the files*/
   helpfiles+=dirs1[i];         /*helpfiles=({"combat.c","communication.c"})*/
     }
}
dirs=dirs2;                         /*puts 19 paths into dirs*/
x=sizeof(dirs2);                    /*z=19 dirs*/

/*collects dirs&files from dirs2*/
for(i=0; i<x; i++) {
dirs3=get_dir(dirs2[i]);       /*dirs2[1]="/doc/help/players/chelp/" dirs3=({"chelp.c"})*/
     n=strlen(dirs3[i]);
     if(dirs3[i][n-1..n])!=".c") {  /*these are the dirs*/
       dirs+=dirs2[i]+dirs3[i]+"/"; /*adds new subdirs*/
       dirs-=dirs2[i];              /*removes the current path*/
     }
     if(dirs3[i][n-1..n)==".c") {   /*these are the files*/
       dirs-=dirs2[i];              /*removes the current path*/
       helpfiles+=dirs3[i];
     }

y=sizeof(dirs3);

/*collects dirs&files from dirs3*/
for(i=0; i<y; i++) {
     dirs4=get_dir(dirs3[i]);
     n=strlen(dirs4[i]);
     if(dirs4[i][n-1..n])!=".c") {
       dirs+=dirs3[i]+dirs4[i]+"/";
       dirs-=dirs3[i];
     }
     if(dirs4[i][n-1..n)==".c") {
       dirs-=dirs3[i];
       helpfiles+=dirs4[i];
     }

z=sizeof(dirs4);
     
/*collects dirs&files from dirs4*/
for(i=0; i<z; i++) {
     dirs5=get_dir(dirs4[i]);
     if(dirs5[i][n-1..n])!=".c") {
       dirs+=dirs4[i]+dirs5[i]+"/";
       dirs-=dirs4[i];
     }
     if(dirs5[i][n-1..n)==".c") {
       dirs-=dirs4[i];
       helpfiles+=dirs5[i];
     }
}
return helpfiles;
}

/*eg. helpfiles=({"fire.c","elf.c","minotaur.c","fireshield.c"});*/
void write_alt_files(helpfiles) {
z=sizeof(helpfiles);
    output=regexp(helpfiles, str);
    write("See also:");
      for(i=0;i<z;i++) {
    if(i==0) {
          message("NO",output[i],this_player()); /*the first argument NO causes it to suppress the newline*/
        }
        else {
          message("NO",", "+output[i],this_player());
        }
      }
      write(".\n");
}


I have tried this code on about 1100 files. That works. I suspect that if you have 64,000+ help files, it will break the array element barrier.

This code is PD.

Sincerely,
Detah