Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ Converting Zmud script to LUA

Converting Zmud script to LUA

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Mjolnir07   (1 post)  Bio
Date Fri 09 Jan 2009 07:37 AM (UTC)
Message
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.


Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 09 Jan 2009 08:53 PM (UTC)

Amended on Fri 09 Jan 2009 08:55 PM (UTC) by Nick Gammon

Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


13,287 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.