Wait or Wait (Game-Time)?

jaybles169

New Member
Reaction score
2
Ran into an issue with this trigger and a couple other triggers that utilize a similar idea.

This is intended to be a heal over time potion, healing x amount each second for 5 seconds, but sometimes they bug out and don't stop after 5 seconds, thus repeatedly healing a character for an extended time but eventually stopping. I'm not sure if using Wait (Game-Time) would make a difference or not. Am I going about this the right way? If not, does anyone have suggestions for a different way to do it?

Trigger:
  • Rejuvenation Potions
    • Events
      • Unit - A unit Uses an item
    • Conditions
    • Actions
      • -------- Lesser Rejuv --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item being manipulated) Equal to (Item carried by (Triggering unit) of type Potion of Lesser Rejuvenation)
        • Then - Actions
          • For each (Integer A) from 1 to 5, do (Actions)
            • Loop - Actions
              • Wait 1.00 seconds
              • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + 180.00)
              • Unit - Set mana of (Triggering unit) to ((Mana of (Triggering unit)) + 150.00)
        • Else - Actions
      • -------- Greater Rejuv --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item being manipulated) Equal to (Item carried by (Triggering unit) of type Potion of Greater Rejuvenation)
        • Then - Actions
          • For each (Integer A) from 1 to 5, do (Actions)
            • Loop - Actions
              • Wait 1.00 seconds
              • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + 500.00)
              • Unit - Set mana of (Triggering unit) to ((Mana of (Triggering unit)) + 400.00)
        • Else - Actions
 

tommerbob

Minecraft. :D
Reaction score
110
Yes. Don't use waits, especially inside a loop. They can be very buggy. Instead, use two triggers. The first trigger is to run when the hero drinks the potion. The second trigger will be a periodic trigger that will do the actual healing.
 

tommerbob

Minecraft. :D
Reaction score
110
For your first trigger, you want to do something like this: (free hand)

Trigger:
  • Events
    • Unit - A unit uses an item
    • Conditions
      • Or - Conditions
        • Item-type of (item being manipulated) equal to (Potion of Lesser Rejuvenation)
        • Item-type of (item being manipulated) equal to (Potion of Greater Rejuvenation)
    • Actions
      • Set HealTarget = (Triggering unit)
      • Set HealDuration = 5
      • Set HealType = Item-type of (item being manipulated)
      • Trigger - Turn on Heal Potion


And now for the periodic trigger:

Trigger:
  • Events
    • Time - every 1 second of (game time)
    • Conditions
    • Actions
      • Set HealDuration = (HealDuration - 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • HealType Equal to Potion of Lesser Rejuvenation)
        • Then - Actions
          • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + 180.00)
          • Unit - Set mana of (Triggering unit) to ((Mana of (Triggering unit)) + 150.00)
        • Else - Actions
    • -------- Greater Rejuv --------
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • HealType Equal to Potion of Greater Rejuvenation
      • Then - Actions
        • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + 500.00)
        • Unit - Set mana of (Triggering unit) to ((Mana of (Triggering unit)) + 400.00)
      • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • HealDuration Less Than or Equal to 0
      • Then - Actions
        • Trigger - Turn off (This trigger)


That should work. The only problem is its not MUI, meaning that more than 1 unit cannot run this trigger at the same time.
 

Bogrim

y hello thar
Reaction score
154
The reason for your trigger breaks is because the loop action uses a variable to keep track of the current loop number. The variable you use, "Integer A", is a global variable. When you run a loop with waits, and another loop uses the variable in the duration, the first loop will break because of the variable's altered data. Printing the variable's value as in-game text would give you a clear example of this:

Integer A = 1
Integer A = 2
Integer A = 3
Integer A = 4
Integer A = 2 -> the loop went haywire

I've written a tutorial on how to create MUI loops in GUI here. However, loops may not be the best approach for your spell effect. Instead, you should consider using a hashtable and a periodic time event, as it will allow you to create different healing values and durations for the units in the trigger.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • jonas jonas:
    Cool, enjoy your vacation!
  • The Helper The Helper:
    Have a great vacation Tom!
  • The Helper The Helper:
    Happy Friday Night!
    +1
  • V-SNES V-SNES:
    Happy Friday Night!
    +1
  • The Helper The Helper:
    Going out of a town for the weekend will be back sunday night! Hope everyone has a great weekend!
    +2
  • The Helper The Helper:
    Happy Monday!
  • Ghan Ghan:
    Monday? Speak for yourself. :p
    +2
  • The Helper The Helper:
    Happy Taco Tuesday!
    +1
  • The Helper The Helper:
    Tacos! :)
  • The Helper The Helper:
    Check out the discord for taco pictures :) You cannot put pictures in this chat
    +1
  • The Helper The Helper:
    Damn here come the bots again - 193 online but they are totally invisible to any stats - bunch of bots!'
  • C cubanismo:
    Re: Taco Tuesday, if there were some way to share edible tacos over the internet, technology would be complete.
    +2
  • The Helper The Helper:
    One can only wish!
  • tom_mai78101 tom_mai78101:
    I'm back from Taiwan
    +1
  • The Helper The Helper:
    I am reorganizing the site I know nobody will notice but I am not done quite yet but the main forums order has been changed and there is a new news category in Other News which is all the remaining headline news stuff not categorized - Headline News is just the stuff that shows on the main page now and the news archive is off the main forums page
  • The Helper The Helper:
    and the real archive lives off of headline news
  • The Helper The Helper:
    Happy Monday!

    The Helper Discord

    Members online

    No members online now.

    Affiliates

    Hive Workshop NUON Dome World Editor Tutorials

    Network Sponsors

    Apex Steel Pipe - Buys and sells Steel Pipe.
    Top