Making a automated healing trigger.

valvido
Posts: 11
Joined: Thu Apr 18, 2013 10:48 am

Making a automated healing trigger.

Post by valvido » Thu Apr 18, 2013 10:57 am

Hi,

Could someone show me how to make this automated healing trigger that look at your HP and determine if you need to continue yourself or not? It will not trigger if I am in combat.

No combat prompt. Note the * next to HP meaning no combat.

Code: Select all

(AFK [GT 12:20 pm] *HP:300/356 MA:511/516 MV:443/451 Gold:295 W/A:0 Standing)> 
Current fighting prompt. Note the ! next to HP meaning in active combat.

Code: Select all

(AFK [GT 12:20 pm] !HP:300/356 MA:511/516 MV:443/451 Gold:295 W/A:0 Standing)> 
Now, I want to start casting heal when I am not in active combat and my current HP is 50HP less than the max HP.

Code: Select all

cast heal self
Do I need to use a Script or can I do this via Trigger? If someone that know coding and can actually create the code for me that would be great. I learn best when I actually see an example.

Also, is it possible to create an Alias to turn ON and OFF this Script/Trigger? Like sometime, I run with a healer and don't need to heal myself, so I would prefer to turn it off then using an Alias.

Thank you!

User avatar
Oneymus
Posts: 321
Joined: Thu Sep 17, 2009 5:24 am

Re: Making a automated healing trigger.

Post by Oneymus » Thu Apr 18, 2013 1:47 pm

This is untested, so use at your own risk. I would suggest, as a learning exercise, if it does have problems, you try to work through them using the tools Mudlet gives you, such as the error window and the debug output. If you have any further questions, I'll get back to you as time permits.

Trigger Pattern (regex):

Code: Select all

^.*(.)HP:(\d+)/(\d+) MA:(\d+)/(\d+) MV:(\d+)/(\d+) Gold:(\d+) W/A:(\d+) (\w+)\)>$
Script:
Code: [show] | [select all] lua
-- This is a trigger on your prompt. We collect all of the
-- useful data from the prompt. Currently, this data is just used
-- locally, but it would make more sense to store this in some
-- global table so it can be used outside of this trigger.

-- As an architectural practice, generally speaking, you want
-- to separate your data input (this trigger) from your logic
-- (the healing bit); however, for this simple, specific case,
-- this works.

local in_combat = matches[2] == "!"

-- Collect our stats, and turn them into numbers for
-- comparison later on.
local health_current = tonumber(matches[3])
local health_max = tonumber(matches[4])

local mana_current = tonumber(matches[5])
local mana_max = tonumber(matches[6])

local move_current = tonumber(matches[7])
local move_max = tonumber(matches[8])

local gold = tonumber(matches[9])

-- No idea what "W/A" means. You may want to rename this.
local wa = tonumber(matches[10])

local is_standing = matches[11] == "Standing"

-- Spam protection.
if not healing_trigger then
	if (health_current / health_max) <= .75 then
		-- This creates a temporary trigger so we know when the heal
		-- was successful. This is to prevent spamming, since you
		-- could potentially match the prompt conditions multiple
		-- times just from the act of casting.
		healing_trigger = tempExactMatchTrigger( "HEALING LINE", 
			function ()
				killTrigger(healing_trigger)
			end)

		-- This is where we tell the MUD to cast heal.
		send("cast heal self")
	end if
end if
Try pasting that into a new trigger, open up your errors and/or debug output, and see what you get. It may be helpful to turn on highlighting to make sure everything is matching properly.

At the very least, this should be a good place to start.

valvido
Posts: 11
Joined: Thu Apr 18, 2013 10:48 am

Re: Making a automated healing trigger.

Post by valvido » Fri Apr 19, 2013 7:05 am

Thank you for given me a foundation to work out.

I'm having problem creating an Alias to disable this Trigger completely, what am I doing wrong?

The Healing Trigger is named "Healing"

I used an Alias "stophealing" with this code in the LUA textbox.

Code: Select all

disableTrigger(Healing)
When I run this Alias, it will not disable the Trigger like I want it to.

Jor'Mox
Posts: 1094
Joined: Wed Apr 03, 2013 2:19 am

Re: Making a automated healing trigger.

Post by Jor'Mox » Fri Apr 19, 2013 2:23 pm

The name of the trigger needs to be in quotes. So instead of:
disableTrigger(Healing)
You need:
disableTrigger("Healing")

valvido
Posts: 11
Joined: Thu Apr 18, 2013 10:48 am

Re: Making a automated healing trigger.

Post by valvido » Mon Apr 22, 2013 2:57 am

Thank you for the help.

I have another problem. How do I set a variable within the trigger?

Trigger is to observe a NAME doing a ACTION. When the NAME matches when doing the ACTION, the trigger fired. I want the NAME to be stored in variable so I can change it easily.

In zMUD, this would be called @target in the trigger line and I can change the variable @target when I need the NAME to change.

Delrayne
Posts: 159
Joined: Tue Jun 07, 2011 7:07 pm
Contact:

Re: Making a automated healing trigger.

Post by Delrayne » Mon Apr 22, 2013 4:27 am

In the trigger make sure you use perl regex and capture the name with '(\w+)' if it's one word...if it's multiple words use '(.+)' Minus the quotes on each... Secondly in your target alias, assuming you've made one just do this:
Code: [show] | [select all] lua
targetVariable = string.title(matches[2])
Thirdly, in your trigger's code box put this:
Code: [show] | [select all] lua
if (matches[2] == targetVariable) then
  send("whatever you want it to do when it matches")
end

valvido
Posts: 11
Joined: Thu Apr 18, 2013 10:48 am

Re: Making a automated healing trigger.

Post by valvido » Mon Apr 22, 2013 6:11 am

Thank you.

I am having difficulty implementing this however due to the way display the NAME. Depending on its length, the NAME will have a trailing spaces at the end of it.

Example:

Code: Select all

short.name          500hp

Code: Select all

long.long.name      500hp
What happen is, when using '(.*)', it will count the trailing empty spaces at the end and won't match the targetVariable I set (because it doesn't have the trailing spaces).

Is there a way for me to strip the trailing spaces?

There is no way to know how many words the name would contains between the starting and ending at the HP count.

Example: Valid, multi-words, and different length NAME.

Code: Select all

A big bird
An eagle
The most amazing beautiful coder
This is what I am trying to convert from zMUD to Mudlet. Hopefully this make more sense to experience coders.

Code: Select all

{@target}%s (%d)/(%d)  hp

Delrayne
Posts: 159
Joined: Tue Jun 07, 2011 7:07 pm
Contact:

Re: Making a automated healing trigger.

Post by Delrayne » Mon Apr 22, 2013 7:07 am

Assuming the spacing between the name you are wanting to capture and what I am guessing is a prompt of sorts doesn't change, you can just put the spaces in the trigger. Try copy pasting this trigger with one of the long names and only change 'A big bird' to '(.+)' while leaving the rest of the spacing in tact. I've never had this issue before(though I do see what you mean) and I use that same exact formula for my bashing scripts that auto-targets etc..

valvido
Posts: 11
Joined: Thu Apr 18, 2013 10:48 am

Re: Making a automated healing trigger.

Post by valvido » Mon Apr 22, 2013 7:11 am

Thank you for the suggestion.

After digging through, I found the string.trim() command.

So what I did is capture the (.*) as a variable TEMP using string.trim(matches[2]). Then use the TEMP to match against the targetVariable.

It is now working.

Delrayne
Posts: 159
Joined: Tue Jun 07, 2011 7:07 pm
Contact:

Re: Making a automated healing trigger.

Post by Delrayne » Mon Apr 22, 2013 6:38 pm

If it isn't broke, don't fix it :P

Post Reply

Who is online

Users browsing this forum: Baidu [Spider] and 4 guests