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.
 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   (80 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  (23,120 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   (80 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.


9,361 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.