• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Goes Wrong the Second Time

Status
Not open for further replies.
Level 3
Joined
Sep 10, 2012
Messages
39
Goes Wrong the Second Time (Solved)

I have created an ability that, when used, increases maximum and current life and mana by 500. When the ability expires, the 500 life and mana, both maximum and current, are lost. When used the first time, the ability functions without flaw. When used the second time... all units who were previously affected by the ability die.

Ability is cast

  • Last Stand Cast Lv1
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (Morlar, Conquerer) Last Stand
    • Actions
      • Set LSCasterLoc = (Position of (Triggering unit))
      • Countdown Timer - Start LSTimer as a One-shot timer that will expire in 15.10 seconds
      • Unit Group - Pick every unit in (Units within 1000.00 of LSCasterLoc matching (((Owner of (Matching unit)) Equal to Player 1 (Red)) or (((Matching unit) belongs to an ally of Player 1 (Red)) Equal to True))) and do (Actions)
        • Loop - Actions
          • Unit Group - Add (Picked unit) to LSTargets
      • Trigger - Run Last Stand Effect Lv1 <gen> (ignoring conditions)
      • Trigger - Turn on Last Stand Expire Lv1 <gen>
Ability takes effect

  • Last Stand Effect Lv1
    • Events
    • Conditions
    • Actions
      • Unit Group - Pick every unit in LSTargets and do (Actions)
        • Loop - Actions
          • Hashtable - Save ((Life of (Picked unit)) + 500.00) as 1 of (Key (Picked unit)) in LSTargetTable
          • Hashtable - Save ((Mana of (Picked unit)) + 500.00) as 2 of (Key (Picked unit)) in LSTargetTable
          • Unit - Add LS Armor Bonus to (Picked unit)
          • Unit - Add LS Damage Bonus to (Picked unit)
          • Unit - Add LS Max Life Bonus to (Picked unit)
          • Unit - Add LS Max Mana Bonus to (Picked unit)
          • Unit - Add LS Attack Speed Bonus to (Picked unit)
          • Unit - Add LS Move Speed Bonus to (Picked unit)
          • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + 500.00)
          • Unit - Set mana of (Picked unit) to ((Mana of (Picked unit)) + 500.00)
          • Unit - Set life of (Picked unit) to (Load 1 of (Key (Picked unit)) from LSTargetTable)
          • Unit - Set mana of (Picked unit) to (Load 2 of (Key (Picked unit)) from LSTargetTable)
Ability expires

  • Last Stand Expire Lv1
    • Events
      • Time - LSTimer expires
    • Conditions
    • Actions
      • Unit Group - Pick every unit in LSTargets and do (Actions)
        • Loop - Actions
          • Hashtable - Save ((Life of (Picked unit)) - 500.00) as 1 of (Key (Picked unit)) in LSTargetTable
          • Hashtable - Save ((Mana of (Picked unit)) - 500.00) as 2 of (Key (Picked unit)) in LSTargetTable
          • Unit - Remove LS Armor Bonus from (Picked unit)
          • Unit - Remove LS Damage Bonus from (Picked unit)
          • Unit - Remove LS Attack Speed Bonus from (Picked unit)
          • Unit - Remove LS Move Speed Bonus from (Picked unit)
          • Unit - Remove LS Max Life Bonus from (Picked unit)
          • Unit - Remove LS Max Mana Bonus from (Picked unit)
          • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) - 500.00)
          • Unit - Set mana of (Picked unit) to ((Mana of (Picked unit)) - 500.00)
          • Unit - Set life of (Picked unit) to (Load 1 of (Key (Picked unit)) from LSTargetTable)
          • Unit - Set mana of (Picked unit) to (Load 2 of (Key (Picked unit)) from LSTargetTable)
          • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in LSTargetTable
      • Hashtable - Clear LSTargetTable
      • Unit Group - Remove all units from LSTargets
      • Trigger - Turn off (This trigger)
It has been some time since I made this trigger (in fact, since I worked with the world editor at all) so I may be overlooking something simple. I *have* determined that it has something to do with how I have it handle the life and mana reduction (saving as a value in a hashtable - but without it the loss is handled wierdly when the bonus abilities are removed.)
 
Last edited:
Level 30
Joined
Nov 29, 2012
Messages
6,637
I think it would be better that instead of setting life, give two abilities to the casting unit. Namely, abilities that increases life and mana. The problem with your trigger that as far as I know is you set the life of the unit to its main life or mana - 500. What would happen if the unit's main life is 500 or below then reduced by 500 when the effect of the bonuses expired? It would die but this is just a wild guess to your problem, not exactly sure yet.

The safest thing (even disregarding about the problem I said above and you should try it) to do is take the ability "Item Life Bonus" and Item Mana Bonus and make a custom ability based on it. Set their bonuses in OE to 500 life and mana. You would have two ability after that: Item Life Bonus (+500 HP) and Item Mana Bonus (+500 Mana) then when the spell is activated, give the casting unit these two abilities and removed it when expired.

Additional notes, anything used twice should be stored into variables such as the Picked Unit, Mathcing Unit and etc. It would also maybe be useful also to store the first "Pick every..." action in your first trigger, referring to that "Units within 1000.00 of LSCasterLoc...".

Good luck and hope I helped.
 
No need of this second trigger. Just make the actions immediatly in your enumeration insid your caste trigger.

Seems you only change the "life" of unit. If I understood right you would have to change to "Max Life".

Something like this is redundant, because you immediatly change life/mana again to an other value:
  • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + 500.00)
  • Unit - Set mana of (Picked unit) to ((Mana of (Picked unit)) + 500.00)
  • Unit - Set life of (Picked unit) to (Load 1 of (Key (Picked unit)) from LSTargetTable)
  • Unit - Set mana of (Picked unit) to (Load 2 of (Key (Picked unit)) from LSTargetTable)
And both do exactly the same. And you don't even need a hashatble here. Just set set Max Life/Mana of unit + 500, and if timer expires change Max Life/Mana -500.

Use "call RemoveLocation (udg_LSCasterLoc)" in end of your cast trigger to remove your location leak. (http://www.hiveworkshop.com/forums/triggers-scripts-269/things-leak-35124/)

Also destroy your group instead of only clearing it: "call DestroyGroup (udg_ LSTargets)"

No need to turn on/off your timer trigger. It will only fire when your timer expires, so only if you order it.

Your system at the moment is only for 1 instance. Casting the spell more often, during the timer is expiring, will cause bug.

Just ask, if you didnt understand something.
 
Level 3
Joined
Sep 10, 2012
Messages
39
  • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + 500.00)
  • Unit - Set mana of (Picked unit) to ((Mana of (Picked unit)) + 500.00)
  • Unit - Set life of (Picked unit) to (Load 1 of (Key (Picked unit)) from LSTargetTable)
  • Unit - Set mana of (Picked unit) to (Load 2 of (Key (Picked unit)) from LSTargetTable)
The top two are actually leftovers from when I'd attempted to fix the problem before. Summarily, I forgot to clean up after myself.

And you don't even need a hashatble here. Just set set Max Life/Mana of unit + 500, and if timer expires change Max Life/Mana -500.
The problem is that, any way I've tried it without hashtables, the current life and mana values for a unit are not adjusted properly when the ability takes effect (there is an increase/decrease, but it is always considerably less than 500)

The safest thing (even disregarding about the problem I said above and you should try it) to do is take the ability "Item Life Bonus" and Item Mana Bonus and make a custom ability based on it. Set their bonuses in OE to 500 life and mana. You would have two ability after that: Item Life Bonus (+500 HP) and Item Mana Bonus (+500 Mana) then when the spell is activated, give the casting unit these two abilities and removed it when expired.
That's what "LS Max Life Bonus" and "LS Max Mana Bonus" are - they're abilities based off of items.
 
Have you made changes? I don't see a new question. In my post above some mistakes are mentioned, you should try to fix them, and update your code here if it's not working.

And no, you don't need hashatble here. What for?

Pick UnitGroup --> Set Max HP/MP +50
Timer runs...
Pick UnitGroup --> Set Max HP/MP - 50

Hashtable would even make it worse. In case a unit gets changed it's Max HP/MP during the
timer expires there will be no effect anymore, after you load the old HP/MP values out of hashtable.
 
Level 3
Joined
Sep 10, 2012
Messages
39
And no, you don't need hashatble here. What for?
Because, if I do not include them, the current life/mana levels are not adjusted properly.
Example:
*With* hashtables
Unit has 500/1000 life. Ability is cast. Unit has 1000/1500 life. Ability expires. Unit returns to 500/1000 life.
Unit has 1000/1000 life. Ability is cast. Unit has 1500/1500 life. Ability expires.
Unit returns to 1000/1000 life.
*Without* hashtables
Unit has 500/1000 life. Ability is cast. Unit has 1000/1500 life plus ~25% of their max life. Ability expires. Unit returns to 500/1000 life.
Unit has 1000/1000 life. Ability is cast. Unit has 1500/1500 life. Ability expires.
Unit has anywhere between 70-95% of max life as current.
The same behavior is seen in mana levels.

The best that I can tell is because merely adding/removing the abilities that give bonus max life/mana itself affects current life/mana levels. To my own knowledge, using hashtables is the only way to counter this. Changing the order in which the bonus abilities are added/removed and current life/mana levels are adjusted have not helped. I have not found an action that affects *max* life/mana in the trigger editor. If you know of one, please post the line as a trigger. If it requires custom script, I ask that you post it *precisely* as it would be written in the trigger editor, as I have no knowledge of Jass and will be unable to correct any errors. That very thing happened when I attempted to add "call DestroyGroup (udg_ LSTargets)" - the map could not save the script because the line was apparently written improperly. "expected a name", I believe, was the error it came up with. I have not attempted to add the line to fix the leak, but I assume the same thing would happen, as the two lines share identical formatting.

I will post the updated code.




  • Last Stand Cast Lv1
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (Morlar, Conquerer) Last Stand
    • Actions
      • Set LSCasterLoc = (Position of (Triggering unit))
      • Countdown Timer - Start LSTimer as a One-shot timer that will expire in 15.10 seconds
      • Unit Group - Pick every unit in (Units within 1000.00 of LSCasterLoc matching (((Owner of (Matching unit)) Equal to Player 1 (Red)) or (((Matching unit) belongs to an ally of Player 1 (Red)) Equal to True))) and do (Actions)
        • Loop - Actions
          • Unit Group - Add (Picked unit) to LSTargets
      • Unit Group - Pick every unit in LSTargets and do (Actions)
        • Loop - Actions
          • Hashtable - Save ((Life of (Picked unit)) + 500.00) as 1 of (Key (Picked unit)) in LSTargetTable
          • Hashtable - Save ((Mana of (Picked unit)) + 500.00) as 2 of (Key (Picked unit)) in LSTargetTable
          • Unit - Add LS Armor Bonus to (Picked unit)
          • Unit - Add LS Damage Bonus to (Picked unit)
          • Unit - Add LS Max Life Bonus to (Picked unit)
          • Unit - Add LS Max Mana Bonus to (Picked unit)
          • Unit - Add LS Attack Speed Bonus to (Picked unit)
          • Unit - Add LS Move Speed Bonus to (Picked unit)
          • Unit - Set life of (Picked unit) to (Load 1 of (Key (Picked unit)) from LSTargetTable)
          • Unit - Set mana of (Picked unit) to (Load 2 of (Key (Picked unit)) from LSTargetTable)
      • Trigger - Turn on Last Stand Expire Lv1 <gen>
  • Last Stand Expire Lv1
    • Events
      • Time - LSTimer expires
    • Conditions
    • Actions
      • Unit Group - Pick every unit in LSTargets and do (Actions)
        • Loop - Actions
          • Hashtable - Save ((Life of (Picked unit)) - 500.00) as 1 of (Key (Picked unit)) in LSTargetTable
          • Hashtable - Save ((Mana of (Picked unit)) - 500.00) as 2 of (Key (Picked unit)) in LSTargetTable
          • Unit - Remove LS Armor Bonus from (Picked unit)
          • Unit - Remove LS Damage Bonus from (Picked unit)
          • Unit - Remove LS Attack Speed Bonus from (Picked unit)
          • Unit - Remove LS Move Speed Bonus from (Picked unit)
          • Unit - Remove LS Max Life Bonus from (Picked unit)
          • Unit - Remove LS Max Mana Bonus from (Picked unit)
          • Unit - Set life of (Picked unit) to (Load 1 of (Key (Picked unit)) from LSTargetTable)
          • Unit - Set mana of (Picked unit) to (Load 2 of (Key (Picked unit)) from LSTargetTable)
      • Hashtable - Clear LSTargetTable
      • Unit Group - Remove all units from LSTargets
      • Trigger - Turn off (This trigger)
 
Level 3
Joined
Sep 10, 2012
Messages
39
You can find "MaxLife" in same category as just "Life".

Real --> unit property --> select "Max Life"
That appears to be something in 'conditions', not 'actions'.

I have also learned why the script was not functioning - there is a space between the dash and the variable name. It is difficult to tell because of the typeface used, but it's there. Removed, the script causes no problems.

Well, after testing, it seems it causes one problem. With it, the ability no longer functions past the first time at all. Do I have to renew the variable or something?
 
Last edited:
Status
Not open for further replies.
Top