New to MUSHclient Lua Scripting

Posted by Silentius on Sat 01 Mar 2008 07:45 PM — 8 posts, 26,502 views.

#0
Ok, so after browsing around for a while.. I felt ready to try and set up my own script. I loaded up mushclient... connected to the world... created a new trigger...

Put in

BLahh * more blaaahh * blah.

Then went down to Scripts and put in
MyScript

I then went to the scripts, made a blank lua file and put in:

Sub Myscript (name, trig_line, wildcards)

local mobname = wildcards [1]
local experience = wildcards [2]

Say("That was a " .. mobname)
Say("I got " .. experience)

end -- of Myscript

After that I saved it. However.. when I try to test the trigger to see if it all works, I get the following error...

[string "Script file"]:1: '=' expected near 'Myscript'

Any tips?
Australia Forum Administrator #1
Have a look inside exampscript.lua which comes with MUSHclient. The examples there should help.

For a start, you declare functions with "function" not "Sub" (Sub is from VBscript). So the first line should read:


function Myscript (name, trig_line, wildcards)


Then these lines use a function that doesn't exist:


Say("That was a " .. mobname)
Say("I got " .. experience)


You need to "Send" the "say" command, like this:


Send ("say That was a " .. mobname)
Send ("say I got " .. experience)


Or if you meant to say it to yourself, use Note, like this:


Note ("That was a " .. mobname)
Note ("I got " .. experience)


#2
[string "Script file"]:6: attempt to call global 'Say' (a nil value)
stack traceback:
[string "Script file"]:6: in function <[string "Script file"]:1>

Called By:
Function/Sub: Myscript called by trigger
Reason: processing trigger ""

(Once I get one simple script working, I will be able to do the rest.)
Amended on Sat 01 Mar 2008 08:40 PM by Silentius
Australia Forum Administrator #3
Did you read the rest of my reply? There is no MUSHclient command "Say" - you need to use "Note".
#4
Ahh, I'm all hopped up on Limeade. Sorry :)
#5
<triggers>
<trigger
enabled="y"
group="Multi Line"
lines_to_match="2"
keep_evaluating="y"
match="(.*?) is DEAD\!\nYou receive (.*?) combat experience\.\Z"
multi_line="y"
regexp="y"
script="Myscript"
sequence="100"
>
<send>%0</send>
</trigger>
</triggers>


I'm getting calls to the script, but It's not sending back the responses... I recoded the lua to be

function Myscript (name, trig_line, wildcards)

local mobname = wildcards [1]
local experience = wildcards [2]

Send ("say That was a " .. mobname)
Send ("say I got " .. experience)

end -- of Myscript



Australia Forum Administrator #6
Well it worked when I tested it.

One thing to look out for is, after a script error, it disables calling that script function again, so you don't get the same error message many times.

You need to go to the Game menu -> Reload Script File. This forces the file to be reprocessed and clears any script errors for triggers.

I would also not put %0 in the "send" box as that is sending the matching line back to the MUD. Just leave it blank.

An alternative approach, which might be simpler, is to use "send to script" rather than using a script file. In this case you leave the "script" box blank, and put scripting commands directly in the trigger, like this:


<triggers>
  <trigger
   enabled="y"
   group="Multi Line"
   lines_to_match="2"
   keep_evaluating="y"
   match="(.*?) is DEAD\!\nYou receive (.*?) combat experience\.\Z"
   multi_line="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
local mobname = "%1"
local experience = %2

Send ("say That was a " .. mobname)
Send ("say I got " .. experience)
</send>
  </trigger>
</triggers>


Now the wildcards are just %1, %2 etc. inside the Send box. Note that you have to quote string wildcards (like a mob name).
#7
awesome. Thanks for the help. Now that I figured out how to make it work, I've already added on the ability to figure out when my exp gain drops, and move onto the next tier of enemies :)