Converting Zmud script to LUA

Posted by Mjolnir07 on Fri 09 Jan 2009 07:37 AM — 2 posts, 13,809 views.

#0
Greetings!

I have a script that was written in Zmud, and being that I'm
in the infantile stages of Learning Lua, I was wondering if anyone could take a moment to explain how I would go about converting it to work in Lua on MUSHClient. The Script is as follows:

#CLASS {Dwarf} {enable}
#ALIAS scan {#VAR dir {};#VAR distance 0;#T+ scan;~scan;emote done}
#VAR imps {31}
#TRIGGER {You eat a warp pill.} {scan}
#TRIGGER {Ballox done} {eat warp}
#CLASS 0
#CLASS {Dwarf|scan} {disable}
#TRIGGER {Nearby (%w):} {#VAR dir %1;#VAR distance 1;#IF (@dir = West) {#VAR backtrack East};#IF (@dir = Down) {#VAR backtrack Up};#IF (@dir = Up) {#VAR backtrack Down};#IF (@dir = South) {#VAR backtrack North};#IF (@dir = North) {#VAR backtrack South};#IF (@dir = East) {#VAR backtrack West}}
#TRIGGER {Not Far (%w):} {#VAR dir %1;#VAR distance 2;#IF (@dir = West) {#VAR backtrack East};#IF (@dir = Down) {#VAR backtrack Up};#IF (@dir = Up) {#VAR backtrack Down};#IF (@dir = South) {#VAR backtrack North};#IF (@dir = North) {#VAR backtrack South};#IF (@dir = East) {#VAR backtrack West}}
#TRIGGER {Far off (%w):} {#VAR dir %1;#VAR distance 3;#IF (@dir = West) {#VAR backtrack East};#IF (@dir = Down) {#VAR backtrack Up};#IF (@dir = Up) {#VAR backtrack Down};#IF (@dir = South) {#VAR backtrack North};#IF (@dir = North) {#VAR backtrack South};#IF (@dir = East) {#VAR backtrack West}}
#TRIGGER {- Something Shiny} {#IF (@distance = 0) {~get all};#IF (@distance = 1) {@dir;~get all;@backtrack};#IF (@distance = 2) {@dir;@dir;~get all;@backtrack;@backtrack};#IF (@distance = 3) {@dir;@dir;@dir;~get all;@backtrack;@backtrack;@backtrack}}
#TRIGGER {Right (%w):} {#VAR dir %1;#VAR distance 0}
#CLASS 0


If you'll notice, I'm fairly certain that one of the most frequently recurring and vital parts of the script, the backtrack function, is not a recognizable function in LUA or by MUSHClient, which triggers the player to, if encountering an object that fires the trigger, to travel to the location of the object (token), and then reverse the steps traveled to get to the object.

Additionally, and I know this is fairly simple and I'm just not entirely spotless on the notion, how would I go about making an alias that would cause Muschlient to recognize and paste a trigger if the input were #Trigger? I.E. so I could type the script into the command input bar and make MUSHClient record it as a trigger, or a script, or a set of triggers?

Forgive me if this is elementary knowledge, I swear I've been skimming forums, most of which assume the user has atleast some knowledge of scripting and programming language, of which I have none, but am enthusiastic about learning.


Australia Forum Administrator #1
I am no expert in zMUD, but I will guess at what some of them do, and do a MUSHclient version. Then you can use that as a guideline for the others.

MUSHclient's scripting is more procedural, than putting everything in a long line. I have put the original code after comments (two hyphens) on each line to show what the original was.

Copy these directly into the client by following the instructions here: http://mushclient.com/pasting

Original: #ALIAS scan {#VAR dir {};#VAR distance 0;#T+ scan;~scan;emote done}


<aliases>
  <alias
   match="scan"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
dir = ""    -- #VAR dir {}
distance = 0   -- #VAR distance 0
EnableTriggerGroup ("scan", true)  -- #T+ scan
Send ("scan")  -- ~scan
Note ("done")  -- emote done
</send>
  </alias>
</aliases>


Original: #TRIGGER {You eat a warp pill.} {scan}



<triggers>
  <trigger
   enabled="y"
   group="Dwarf"
   match="You eat a warp pill."
   send_to="10"
   sequence="100"
  >
  <send>scan</send>
  </trigger>
</triggers>


Original: #TRIGGER {Nearby (%w):} {#VAR dir %1;#VAR distance 1;#IF (@dir = West) {#VAR backtrack East};#IF (@dir = Down) {#VAR backtrack Up};#IF (@dir = Up) {#VAR backtrack Down};#IF (@dir = South) {#VAR backtrack North};#IF (@dir = North) {#VAR backtrack South};#IF (@dir = East) {#VAR backtrack West}}


<triggers>
  <trigger
   enabled="y"
   group="scan"
   match="Nearby (*): *"
   send_to="12"
   sequence="100"
  >
  <send>
dir = "%1" -- #VAR dir %1
distance = 1 -- #VAR distance 1

--[[
#IF (@dir = West) {#VAR backtrack East}
#IF (@dir = Down) {#VAR backtrack Up}
#IF (@dir = Up) {#VAR backtrack Down}
#IF (@dir = South) {#VAR backtrack North}
#IF (@dir = North) {#VAR backtrack South}
#IF (@dir = East) {#VAR backtrack West}
--]]


backtracks = {
  West = "East",
  Down = "Up",
  Up = "Down",
  South = "North",
  North = "South",
  East = "West",
  }

backtrack = backtracks ["%1"]  -- lookup backtrack

  
</send>
  </trigger>
</triggers>


I'm not really clear what backtrack does in zMUD - it looks like a variable here, so I am just setting it (eg. if you get Nearby (North) backtrack will be set to South. To save a few lines of code, and to make it easier to change later, I am using a table lookup. You could put this table (the backtracks table) into the script file, making it available to all triggers, which would reduce the amount of code needed for the individual ones.

Quote:

Additionally, and I know this is fairly simple and I'm just not entirely spotless on the notion, how would I go about making an alias that would cause Muschlient to recognize and paste a trigger if the input were #Trigger?



See http://mushclient.com/faq point 29 for the general idea.

You won't be able to totally automate it, because the scripting styles are somewhat different. It could work for simple triggers like the "#TRIGGER {Ballox done} {eat warp}" one.