|
Oddity Newbie
Joined: 04 Nov 2007 Posts: 3
|
Posted: Sun Nov 04, 2007 2:58 am
Triggers and Zmud |
Okay, let me just start off by saying that I'm new to coding completely, but having read through the help files and asked questions in various other forums, I think I'm slowly getting the hang of the basics.
But for some reason I seem to be having a problem with this one trigger. I'm trying to create a trigger to auto drink a healing potion whenever my health gets below 80% and I am capable of drinking health.
Quote: |
#TRIGGER {^You take a drink from *.$} {#var amdrinking 1}
#TRIGGER {^The elixir heals and soothes you.$} {drinkbalance=0}
#TRIGGER {^The elixir flows down your throat without effect.$} {drinkbalance=0}
#TRIGGER {^Health: (%d)/(%d) Mana: (%d)/(%d)$} {maxhealth=%2;maxmana=%4}
#TRIGGER {H:(%d) M:(%d) E:(%d) W:(%d) ~[*~]} {#if (@ameating=0) {herbheal};currenthealth=%1;currentmana=%2;#if (@drinkbalance=1 AND @amdrinking=0 AND (@currenthealth*100)/@maxhealth)<80) {drink health}} "" {disable}
#VAR currenthealth {2170}
#VAR currentmana {1928}
#VAR maxhealth {2170}
#VAR maxmana {2830}
#VAR amdrinking {1}
#VAR drinkbalance {0} |
You might notice I have no trigger yet to reset my variables to drinkbalance=1 or amdrinking=0. That's on purpose, because for some reason, even with those variables I'm drinking health on every -single- prompt. So my variable @drinkbalance=0 and yet my trigger on my prompt will still fire. Any ideas guys?
(PS- I apologize in advance if it's something really simple that I've just missed.) |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sun Nov 04, 2007 3:10 am |
It looks like you have a mismatched parenthesis.
#TRIGGER {H:(%d) M:(%d) E:(%d) W:(%d) ~[*~]} {#if (@ameating=0) {herbheal};currenthealth=%1;currentmana=%2;#if (@drinkbalance=1 AND (@currenthealth*100/@maxhealth)<80) {drink health}} "" {disable}
I also tend to suggest adding extra parenthesis just to assure the behavior of AND is how you want it.
#TRIGGER {H:(%d) M:(%d) E:(%d) W:(%d) ~[*~]} {#if (@ameating=0) {herbheal};currenthealth=%1;currentmana=%2;#if ((@drinkbalance=1) AND ((@currenthealth*100/@maxhealth)<80)) {drink health}} "" {disable} |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Oddity Newbie
Joined: 04 Nov 2007 Posts: 3
|
Posted: Sun Nov 04, 2007 3:33 am |
My god, I can't believe it was just a matter of adding a couple of extra brackets. Thanks for the help guys, sorry for the stoopid question.
EDIT: Hrm, okay, probably an other stupid question, but here goes anyway. I'm sure I've added all the right brackets this time. I've expanded the last trigger to include healing mana if my health is above 90% and my mana is below 60%.
Quote: |
#TRIGGER {H:(%d) M:(%d) E:(%d) W:(%d) ~[*~]} {#if (@ameating=0) {herbheal};currenthealth=%1;currentmana=%2;#if ((@drinkbalance=1) AND (@amdrinking=0) AND ((@currenthealth*100)/(@maxhealth))<80) {drink health;amdrinking=1} {#if ((@drinkbalance=1) AND (@amdrinking=0) AND ((@currenthealth*100)/(@maxhealth))>90 AND ((@currentmana*100)/(@maxmana)<60))} {drink mana;amdrinking=1}} |
Help would be appreciated. I'm probably getting in over my head making triggers this complicated this early on in my learning. |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sun Nov 04, 2007 4:21 am |
Old old programming trick. Much faster too when properly applied, all ANDs within an if can be made as seperate nested if's.
#IF (condition1 AND condition2) {do} can become #IF (condition1) {#IF (condition2) {do}}
You start with common conditions that will immediately invalidate everything else.
Code: |
#TRIGGER {H:(%d) M:(%d) E:(%d) W:(%d) ~[*~]} {
currenthealth=%1
currentmana=%2
#if (@ameating=0) {herbheal}
#if ((@drinkbalance=1) {
#IF (@amdrinking=0) {
#IF ((@currenthealth*100/@maxhealth)<80) {
drink health;amdrinking=1
} {
#if ((@currenthealth*100/@maxhealth)>90) {
#IF ((@currentmana*100/@maxmana)<60) {drink mana;amdrinking=1}
}
}
}
}
} |
Do you see how that combines the checks for drinkbalance and amdrinking? This will make it go faster when either of those conditions is right to skip past the other if's. You could probably shorten it further if you wanted to adjust you health numbers, currently you check for less then 80%, then have an else which means you have already done the math to say you have >=80%. Another speed gain can be achieved if you can elminate the second set of math, although it is a small gain. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Nov 04, 2007 9:46 am |
I should probably mention that what Viji is suggesting there is quite a bad habit to get into. It helps in zMUD because of the way zMUD handles AND and OR, but in other scripting languages (and in CMUD) it doesn't actually help and gives you a bunch of nested ifs that you may find confusing.
|
|
|
|
|
|