Gammon Forum
See www.mushclient.com/spam for dealing with forum spam.
Please read the MUSHclient FAQ!
Entire forum
MUSHclient
Lua
How do I pass an argument from trigger to external scrip file?
|
How do I pass an argument from trigger to external scrip file?
|
It is now over 60 days since the last post. This thread is closed.
 
Refresh page
| Posted by |
Blixel
(72 posts) bio
|
| Date |
Sun 27 Dec 2020 02:19 PM (UTC) |
| Message |
I have a trigger set up to look out for monster names. Here's an example trigger:
<trigger
enabled="y"
group="Monster List for Auto-Killing"
keep_evaluating="y"
match="^M -.*?( gorgon).*?$"
regexp="y"
send_to="12"
sequence="140"
>
<send>-- I made the gorgon its own trigger so it
-- doesn't get confused with demogorgon
--
-- HIT DAMAGE: 30 + dice(4,10)
-- MAX DAMAGE: 40
Execute("disableHitMessages")
EnableTrigger("hitMessage40", true)
if (autokill) then
Execute ("killonemob %1")
end
</send>
</trigger>
I have an alias called "killonemob *", and this alias does what I want. But I want to move its functionality to an external script file so that I don't have to edit it inside of MUSHclient. Here is the alias I have at the moment:
<alias
script="killOneMob"
match="killonemob *"
enabled="y"
group="Kill Routines"
keep_evaluating="y"
sequence="100"
>
</alias>
And finally, here is how it is being called in my external script file.
function killOneMob(monster)
if (readytokill) then
-- The first thing we do is set readytokill to false so another
-- instance can't overlap.
readytokill = false
require "wait"
wait.make (function ()
giveup = false
-- Initialize x variable to nil
local x = nil
-- Our main kill loop
while not (x or giveup) do
-- Keep hitting until the mob is dead or until one of the other
-- 6 conditions are met. Check our kill readiness one more time
-- just before we start swinging.
if (autokill and readytokill == false and giveup == false) then
Send ("kill " .. monster)
end
x = wait.regexp ("^The .*? (is slain!)|(flees in panic!)|(^There is no .*? here\.$)|(^You can\'t attack yourself!$)|(^A being clothed in white appears before you\.$)|(^Do what\.?$)|(^The dead have no need to fight\.$)", attackDelayTime)
end -- while
.
.
.
The problem I'm having is that when this function runs "Send ("kill " ... monster)" ... I'm getting "kill *alias1761164" instead of "kill <monster name>"
So my question is: How do I fix my sequence so that when <monster name> is in the room, my trigger will send "killonemob *" and my function will "kill <monster name>" instead of "kill *alias1761164".
Thanks. | top |
|
| Posted by |
Nick Gammon
Australia (22,556 posts) bio
Forum Administrator |
| Date |
Reply #1 on Sun 27 Dec 2020 07:15 PM (UTC) |
| Message |
The arguments to external trigger scripts are name, line, wildcards, styles, so your function should look like this:
function killOneMob(name, line, wildcards, styles)
local monster = wildcards [1]
...
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
| Posted by |
Blixel
(72 posts) bio
|
| Date |
Reply #2 on Sun 27 Dec 2020 08:26 PM (UTC) |
| Message |
Nick Gammon said:
The arguments to external trigger scripts are name, line, wildcards, styles, so your function should look like this:
function killOneMob(name, line, wildcards, styles)
local monster = wildcards [1]
...
That works! Thanks. | 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.
511 views.
It is now over 60 days since the last post. This thread is closed.
 
Refresh page
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.