How do I pass an argument from trigger to external scrip file?

Posted by Blixel on Sun 27 Dec 2020 02:19 PM — 3 posts, 13,856 views.

#0
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.
Australia Forum Administrator #1
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]
...
#2
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.