[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Help w/lua scripting

Help w/lua scripting

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


Posted by Salaz   (5 posts)  [Biography] bio
Date Sat 20 Sep 2008 12:04 AM (UTC)
Message
I'm relatively new to mush and lua but i am able to create simple aliases,triggers and timers.
I'd like to learn more, and i find that i learn best when i have examples i can look at. so basically i'm asking if anyone has simple scripts they've written in lua that i can i take a look at and learn from. (any simple script will do, but i play achaea and will appreciate any related material)

Secondly, i need help converting this zmud alias to mush:
#ALIAS i_info {#ECHO "";#say %ansi( red)~[%ansi( gray)SCS%ansi( red)~]%ansi( gray): %ansi( white)%expand( %-1)%ansi( gray)}

what it does is similar to world.AnsiNote but instead of just displaying the note, it adds "SCS:" to it with all that coloring.

And finally, i wana write a script that gags/highlights/notes certain text from the output. But i dont know how to go about doing that. I mean i cant figure out whether to make triggers that call a certain function from my script file or just to make separate triggers and omit them from output.
This is an example in zmud that Daes wrote for achaea (just a part of it)

Quote:
#CLASS {Combat|Highlights, Echos, Gags, Warnings}
#REGEX {^You secrete (.+) and} {#gag;i_info ENVENOMED: %upper( %1)}
#REGEX {^There are no venoms on that item at present\.$} {#gag} "" {case}
#REGEX {^You sink your fangs into (.+), injecting just the proper amount of (.+)\.$} {#gag;i_info BITE: %upper( %1) with %upper( %2)}
#REGEX {^The chaos hound explodes into a fury of claws and teeth, rending your flesh\.$} {#gag} "" {case}
.


Hope i'm not asking too much and/or bothering ya'll
Appreciate the help in advance!
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #1 on Sat 20 Sep 2008 12:49 AM (UTC)

Amended on Sat 20 Sep 2008 01:17 AM (UTC) by WillFa

Message
To answer the second question in your script file (ctrl+shift+h):

function SCSnote ( passedtext )
    ColourNote ( "red", "black" , "[" ,
                 "gray", "black", "SCS",
                 "red", "black", "]",
                 "gray", "black", ":",
                 "white", "black", passedtext)
end

The ColourNote function needs 3 parameters; foreground, background, and text. It will also take those 3 parameters multiple times if you're using Lua.

For samples, I'd recommend looking at the plugins that Nick provides.

For gags, I'd recommend multiple triggers.
i.e.
trigger pattern: ^You secrete (.+) and .++$
trigger field value for Script: Secrete

in your script file again:

function Secrete (trig, line, wildcards, styleruns)
   SCSNote ("ENVENOMED: " .. wildcards[1]:upper() )
end


Or if you prefer,
trigger pattern: ^You secrete (.+) and .++$
trigger field value for Send To: Script After Omit
trigger field value for send:

SCSNote ("ENVENOMED: " .. string.upper("%1")) 


Here's a small 'gotcha!' for the people that use the send field of a triger or alias.
Mushclient needs to do a literal replacement of the %1, %2, etc before sending the text to the Lua compiler. Keep in mind if you want your code to be 'string.upper(poison)' (a variable named poison), or 'string.upper("poison")' (convert the literal string to upper case) when using the Send field in the trigger dialog. If you have any familiarity with C/C++, it's easier to think that '%1' isn't a variable that's passed into your script, it's a token that the precompiler replaces.





[Go to top] top

Posted by Salaz   (5 posts)  [Biography] bio
Date Reply #2 on Sat 20 Sep 2008 01:23 AM (UTC)

Amended on Sat 20 Sep 2008 01:47 AM (UTC) by Salaz

Message
could you please explain what the following are and how they work:

wildcards[1]:upper() & string.upper("%1")

PS: does it make a difference which of the gag methods i use? i wana assume that the first method using my script file would be best cause it doesn't create too much clutter?
[Go to top] top

Posted by Larkin   (278 posts)  [Biography] bio
Date Reply #3 on Sat 20 Sep 2008 02:19 AM (UTC)
Message
wildcards[1]:upper() is another way to write string.upper(wildcards[1]). It's what we call 'syntactic sugar' and you can use either method you choose.
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #4 on Sat 20 Sep 2008 02:34 AM (UTC)
Message
in the line:

function Secrete (trig, line, wildcards, styleruns)


those 4 parameters are passed into the function by Mushclient when the script is called. wildacards ans styleruns are tables, which are a data type in Lua. http://www.lua.org/pil/index.html (Programming in Lua, PiL) is a useful reference for learning the language and the general syntax. It's a book, and not just a reference manual; it will have some of the generic examples to learn the language syntax that you're looking for.

'syntactic sugar' is a concept that's explained in the PiL. It's just a more concise way of writing the same thing.

Tables are fun, and a bit more complex than I want to get in here when PiL says the same thing, only better. Tables are arrays, dictionaries, hashes, and maps found in other languages all rolled into one.
[Go to top] top

Posted by Salaz   (5 posts)  [Biography] bio
Date Reply #5 on Wed 08 Oct 2008 02:28 PM (UTC)
Message
Hi, me again and i've got a rather large project on my hands
trying to convert this :http://www.freewebs.com/heroica/Sabiru_Delusion.TXT
to mush.

Now i know its mostly just a bunch of aliases i have to make but there a few things i cant do. like these
Quote:
#ALIAS itog {#if (@Illusioning) {illusioning = 0;report Illusioning OFF} {illusioning = 1;report Illusioning ON}} "Delusion|Illusions"
#ALIAS it {#if (@illusion_targetting) {illusion_targetting=0;report Not targetting illusions} {illusion_targetting=1;report Targetting illusions}} "Delusion|Illusions"
#ALIAS ill {#if {@Illusioning=1} {#if (@illusion_targetting) {conjure @target illusion %-1} {conjure illusion %-1}}} "Delusion|Illusions"
#ALIAS ilt {conjure @target illusion} "Delusion|Illusions"
#ALIAS ilw {illusioning_what=%proper(%-1)} "Delusion|Illusions"


And i dont understand what the functions #Case and #if (%1="") in the following alias do or how they are used in mush

Quote:
ALIAS bxen {screte xentio;#CASE %random {ibcur} {iscur} {isscy} {isdar} {iseup} {ibscy} {ibdar} {ibeup} {ginsengillusion} {bloodrootillusion};#if (%1="") {bite @target} {bite %1}} "Delusion|Venom"


And finally, if all this can be a placed in a neat script like that on the site. hope i'm not asking too much and thanks in advance
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Thu 09 Oct 2008 06:05 AM (UTC)

Amended on Thu 09 Oct 2008 06:06 AM (UTC) by Nick Gammon

Message
The illusions one could look like this:


<aliases>
  <alias
   match="itog"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

illusioning = not illusioning -- toggle it

if illusioning then
  Note "Illusioning ON"
  Send "Delusion"
else
  Note "Illusioning OFF"
  Send "Illusions"
end -- if

</send>
  </alias>
</aliases>


This uses Lua variables, not MUSHclient variables, but that would be OK for a single session.

The bexn alias will be something like this:


<aliases>
  <alias
   match="^bxen( .+)?$"
   enabled="y"
   expand_variables="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

Send "screte xentio"

do
  local t = {
  "ibcur",
  "iscur",
  "isscy",
  "isdar",
  "iseup",
  "ibscy", 
  "ibdar",
  "ibeup",
  "ginsengillusion",
  "bloodrootillusion",
  }

  Send (t [math.random (#t)])  -- send a random item
end -- do

if "%1" == "" then
  Send ("bite @target")
else
  Send ("bite%1")
end -- if

Send "Delusion|Venom"
    </send>
  </alias>
</aliases>



I am guessing a bit at what the original does, but this should help you get started. The case is selecting from a group based on a random number, so I made a table of those words, and used math.random to pick an item from it.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] 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.


19,511 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]