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
➜ Help w/lua scripting
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Salaz
(5 posts) 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! | | Top |
|
| Posted by
| WillFa
USA (525 posts) 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.
| | Top |
|
| Posted by
| Salaz
(5 posts) 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? | | Top |
|
| Posted by
| Larkin
(278 posts) 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. | | Top |
|
| Posted by
| WillFa
USA (525 posts) 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. | | Top |
|
| Posted by
| Salaz
(5 posts) 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
| | Top |
|
| Posted by
| Nick Gammon
Australia (23,166 posts) 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 | | 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.
26,179 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top