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.

      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