Posted by
| Nick Gammon
Australia (23,043 posts) bio
Forum Administrator |
Message
| This has certainly been an interesting challenge. :)
I haven't tested my script on Medievia as I don't have a character there, but based on the MudMaster script this should work.
Just copy the script from between the lines and paste into your script file. This is written in Jscript.
Note: The changes mentioned in subsequent posts have been incorporated into the code below.
// Auto-walker for Medievia
// ----------------------------------------------------------
// This function installs the auto-walker
// ----------------------------------------------------------
function InstallAutoWalker ()
{
// set up triggers
world.AddTrigger ("walk_trigger",
"^(North|South|East|West)\\s+-\\s+" +
"(A Sturdy, Wooden Bridge|A Well-Traveled Road|" +
"On a Winding Forest Trail|A gravel path)$",
"",
8 + 32 + 1024, // keep evaluating / regexp / replace
-1, 0, "",
"On_Trigger_Walker_Direction"); // function to call
world.AddTrigger ("west_trigger",
"^West\\s+-\\s+.+$",
"",
8 + 32 + 1024, // keep evaluating / regexp / replace
-1, 0, "",
"On_Trigger_West"); // function to call
world.AddTrigger ("destination_trigger",
"* says, '* is * from this intersection'.",
"",
1024, // replace existing
-1, 0, "",
"On_Trigger_Walker_Destination"); // function to call
// set up aliases
world.AddAlias ("start_walker_alias", "startwalk", "", 1 + 1024, "On_Start_Walk");
world.AddAlias ("stop_walker_alias", "stopwalk", "", 1 + 1024, "On_Stop_Walk");
world.AddAlias ("do_walker_alias", "walk *", "", 1 + 1024, "On_Do_Walk");
// set up variables
world.SetVariable ("direction", ""); // no direction yet
world.SetVariable ("destination", ""); // no destination yet
world.SetVariable ("direction_count", 0); // no count yet
world.SetVariable ("disable_direction", ""); // no disabled direction yet
world.note ("Auto walker installed.");
} // end of InstallAutoWalker
// ----------------------------------------------------------
// This function removes the auto-walker
// ----------------------------------------------------------
function RemoveAutoWalker ()
{
world.DeleteTrigger ("walk_trigger");
world.DeleteTrigger ("west_trigger");
world.DeleteTrigger ("destination_trigger");
world.DeleteTimer ("walk_timer");
world.DeleteAlias ("start_walker_alias");
world.DeleteAlias ("stop_walker_alias");
world.DeleteAlias ("do_walker_alias");
world.note ("Auto walker removed.");
} // end of RemoveAutoWalker
// ----------------------------------------------------------
// This function starts the auto-walker
// ----------------------------------------------------------
function On_Start_Walk (strName, strOutput, wildcardsVB)
{
world.note ("Walker started.");
world.EnableTrigger ("walk_trigger", true);
world.EnableTrigger ("west_trigger", true);
world.EnableTrigger ("destination_trigger", true);
world.Send (world.GetVariable ("direction"));
} // end of On_Start_Walk
// ----------------------------------------------------------
// This function stops the auto-walker
// ----------------------------------------------------------
function On_Stop_Walk (strName, strOutput, wildcardsVB)
{
world.note ("Walker stopped.");
world.EnableTrigger ("walk_trigger", false);
world.EnableTrigger ("west_trigger", false);
world.EnableTrigger ("destination_trigger", false);
world.DeleteTimer ("walk_timer");
} // end of On_Stop_Walk
// ----------------------------------------------------------
// This function walks to the specified destination
// ----------------------------------------------------------
function On_Do_Walk (strName, strOutput, wildcardsVB)
{
wildcards = VBArray(wildcardsVB).toArray();
sDestination = wildcards [0];
// remember the destination
world.SetVariable ("destination", sDestination);
world.SetVariable ("direction", ""); // no direction yet
world.SetVariable ("direction_count", 0); // no count yet
world.Note ("Destination is now " + sDestination);
On_Start_Walk (0, 0, 0); // enable trigger
world.Send ("say where " + world.GetVariable ("destination"));
} // end of On_Do_Walk
// ----------------------------------------------------------
// This function is called when "walk_trigger" fires
// eg.
// North - A Gravel Path
// East - A Clear River
// South - A Gravel Path
// West - A Clear River
// ----------------------------------------------------------
function On_Trigger_Walker_Direction (strTriggerName, strTriggerLine, wildcardsVB)
{
wildcards = VBArray(wildcardsVB).toArray();
sDirection = wildcards [0];
// don't count disabled directions
if (sDirection == world.GetVariable ("disable_direction"))
return;
// count directions that we could go in
world.SetVariable ("direction_count",
parseInt (world.GetVariable ("direction_count")) + 1);
// remember the direction
world.SetVariable ("direction", sDirection);
} // end of On_Trigger_Walker_Direction
// ----------------------------------------------------------
// This function is called when we go west
// ----------------------------------------------------------
function On_Trigger_West (strTriggerName, strTriggerLine, wildcardsVB)
{
// set up 1-second timer
world.AddTimer ("walk_timer", 0, 0, 1, "",
1 + 4 + 1024, // enabled / one shot / replace existing
"On_Timer_Walker"); // function to call
} // end of On_Trigger_West
// ----------------------------------------------------------
// This function is called when "destination_trigger" fires
// eg. Lianydd says, 'Agreilith is North from this intersection'.
// ----------------------------------------------------------
function On_Trigger_Walker_Destination (strTriggerName, strTriggerLine, wildcardsVB)
{
wildcards = VBArray(wildcardsVB).toArray();
sDirection = wildcards [2];
switch (sDirection.toLowerCase())
{
case "north": sDisabledDirection = "South"; break;
case "south": sDisabledDirection = "North"; break;
case "east": sDisabledDirection = "West"; break;
case "west": sDisabledDirection = "East"; break;
default: return;
} // end of switch
// disable reciprocal direction
world.SetVariable ("disable_direction", sDisabledDirection);
world.SetVariable ("direction", ""); // no direction yet
world.SetVariable ("direction_count", 0); // no count yet
// go in specified direction
world.Send (sDirection);
} // end of On_Trigger_Walker_Destination
// ------------------------------------------
// This is called when the walker time fires
// -------------------------------------------
function On_Timer_Walker (strTimerName)
{
if (parseInt (world.GetVariable ("direction_count")) == 1)
world.Send (world.GetVariable ("direction"));
else
world.Send ("say where " + world.GetVariable ("destination"));
world.SetVariable ("direction_count", 0); // no count yet
} // end of On_Timer_Walker
To install the auto-walker
Type: /InstallAutoWalker ()
This will execute the function InstallAutoWalker which sets up the various triggers needed for the auto-walker.
To remove the auto-walker
Type: /RemoveAutoWalker ()
This removes the triggers set up by the InstallAutoWalker.
To start walking automatically
Type: walk castle
where "castle" is the name of the place you are heading for.
It will start by saying "where castle" so it can find the initial direction to walk.
To temporarily stop the auto-walker
Type: stopwalk
This disables the triggers so you will stop walking automatically.
To restart the auto-walker
Type: startwalk
This recommences walking in the last direction it was heading.
Let me know if you have problems with it.
How it works
InstallAutoWalker sets up three triggers:
1. To match on the desired paths we can take:
"A Sturdy, Wooden Bridge"
"A Well-Traveled Road"
"A Well-Traveled Road"
"A gravel path"
A regular expression is used to match on any one of the above, in combination with north, south, east or west.
2. To match on "West - (anywhere)" - when we get "West" then we get ready to walk in the desired direction.
3. To match on "* says, '* is * from this intersection'.".
The "*" is a wildcard, and is used to match on the response to saying "where location".
We also set up three aliases, startwalk, stopwalk, and walk, to handle the interface between the player and the script.
Once we start walking the triggers match on the appropriate paths above, and count how many match. If only one matches, we go that way. Otherwise we say "where location" and wait for the other trigger to match, which tells us which way to go.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|