• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] "Anti-Spirit Link"

Status
Not open for further replies.
Level 4
Joined
Nov 20, 2016
Messages
75
Hi! First of all, I just registered so I'm not sure how things go, but I think this is the proper forum for this.

I am trying to make an altered melée map with new tavern heroes, and I want one of them to have an ability that links enemy units, so when one of them is damaged, all linked units receive either a percentage of that damage, or the same amount of damage (without reducing the damage that the first unit takes).

What I got:

I'm using GDD v 1.21
When my hero casts the ability (I called it Soul Bind, so I will call it "SB" for the rest of the post) I create a dummy unit for the owner of the target unit and have that unit cast an ability based on spirit link (with a buff based on the spirit link buff).

Now here's where I've got the problem:

SB Damage Trigger:
When a unit is damaged (detected with GDD v1.21), if it has the SB buff, I cause a the damage source to damage all units with the buff, which fires the trigger again, causing an infinite loop that kills all units with the buff.

I tried turning off the trigger (SB Damage), and making another trigger (SB Control) that turns it on when a unit with the buff is attacked. This makes SB Damage run all the way once, but when it is turned on again by the other trigger, for some reason, it doesn't go into the loop that's supposed to damage all units with the buff.

Code for SB_Damage

  • Soul Bind Damage
    • Events
      • Game - GDD_Event becomes Equal to 1.00
    • Conditions
      • (GDD_DamagedUnit has buff Soul Bind ) Equal to True
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area) matching ((((Triggering unit) belongs to an ally of (Triggering player)) Igual a True) and (((Matching unit) has buff Soul Bind ) Igual a True))) and do (Actions)
        • Loop: Actions
          • Game - Display to (All players) the text: Trigger is running ...
          • Unit Group - Add (Picked unit) to SoulBind_Target_Group
          • Unit Group - Remove GDD_DamagedUnit from SoulBind_Target_Group
          • Unit Group - Pick every unit in SoulBind_Target_Group and do (Actions)
            • Loop: Actions
              • Game - Display to (All players) the text: (String((Number of units in SoulBind_Target_Group)))
              • Unit - Cause GDD_DamageSource to damage (Picked unit), dealing GDD_Damage damage of attack type Spell and damage type Normal
          • Trigger - Turn off (This trigger)
      • Custom script: call RemoveLocation (udg_SoulBind_Target_Location)
      • Custom script: call DestroyGroup (udg_SoulBind_Target_Group)
I looked for a similar spell in the resources section and for posts of people trying to make it to see if it was already solved, but found nothing. If you guys can help me, I'll be incredibly thankful ^^
 
Last edited:
Level 37
Joined
Jul 22, 2015
Messages
3,485
Before dealing damage, turn off the trigger. After dealing damage, turn it back on. Given that you deal damage in a unit group loop, its smarter to turn it off right before you enumerate units.

  • Trigger - Turn off (This trigger)
  • Unit Group - Pick every unit in (Units in (Playable map area) matching ((((Triggering unit) belongs to an ally of (Triggering player)) Igual a True) and (((Matching unit) has buff Soul Bind ) Igual a True))) and do (Actions)
    • Loop - Actions
      • -------- deal damage --------
  • Trigger - Turn on (This trigger)
On a side note, you leak a unit group.

Also, I think this spell seems to similar to what I made here.
 
Level 4
Joined
Nov 20, 2016
Messages
75
Before dealing damage, turn off the trigger. After dealing damage, turn it back on. Given that you deal damage in a unit group loop, its smarter to turn it off right before you enumerate units.

  • Trigger - Turn off (This trigger)
  • Unit Group - Pick every unit in (Units in (Playable map area) matching ((((Triggering unit) belongs to an ally of (Triggering player)) Igual a True) and (((Matching unit) has buff Soul Bind ) Igual a True))) and do (Actions)
    • Loop - Actions
      • -------- deal damage --------
  • Trigger - Turn on (This trigger)
On a side note, you leak a unit group.

Also, I think this spell seems to similar to what I made here.


Yes! Thank you, this works! I over-complicated the code because it wasn't working at first! And.. yes, it looks like what you did, but I searched the forums with "spirit link" "negative spirit link" "fatal bonds" "link units damaged" and I couldn't find it O_O

Anyhow, now that you've helped I can remove half my code that was overcomplicating things. Is this leakless now? ^_^

  • Soul Bind Damage
    • Events
      • Game - GDD_Event becomes Igual a 1.00
    • Conditions
      • (GDD_DamagedUnit has buff Soul Bind ) Equal to True
    • Actions
      • Trigger - Turn off (This trigger)
      • Set SoulBind_Target_Group = (Units in (Playable map area) matching ((((Matching unit) has buff Alma Encadenada ) Igual a True) and (((Matching unit) belongs to an ally of (Triggering player)) Equal to True)))
      • Unit - Pick every unit in SoulBind_Target_Group and do (Actions)
        • Loop: Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If: Conditions
              • (Picked unit) Not equal to GDD_DamagedUnit
            • Then: Actions
              • Unit - Cause GDD_DamageSource to damage (Picked unit), dealing GDD_Damage damage of attack type Spell and damage type Normal
              • Custom script: call DestroyGroup (udg_SoulBind_Target_Group)
            • Else: Actions
      • Trigger - Turn on Soul Bind Damage <gen>
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
You need to destroy the unit group variable after the unit group enumeration, not inside it. Here are some other suggestions:
  • Turn off (This trigger) > Turn off Soul Bind Damage <gen>. It's slightly faster :p
  • I'm not a big fan of filtering unit groups using (Matching unit). I explain here why it's not the best and show a better alternative
  • Avoid using repeating function calls. For example, you use (Picked unit) twice in the unit group loop. You can just store (Picked unit) into a variable and just reference that
 
Level 4
Joined
Nov 20, 2016
Messages
75
Thank you very much, I'll try to keep your advice in mind!
I know I can store picked unit into a variable, but I thought it was unnecesary. Is there a reason for that too?

I'm kind of a noob when it comes to this stuff, I just played around with it, and now I'm trying to make something that actually works haha. I'll change the topic to [Solved] now, you were a great help.
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
I know I can store picked unit into a variable, but I thought it was unnecesary. Is there a reason for that too?
As mentioned, only if you repeat function calls. In your trigger, you called the (Picked unit) function twice. Instead of calling it twice, you can just call it once, store it into a variable, and then reference that variable instead.
 
Status
Not open for further replies.
Top