• 🏆 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] Unit group problem

Status
Not open for further replies.
Level 5
Joined
Dec 25, 2018
Messages
110
I want to make a passive ability which makes following after attacking:
-Heals hero based on fixed value + STR bonus (WORKS)
-Creates Special effect on hero while attacking. (WORKS)
-Creates unit group of friendly nearby units near our hero. (DOESN'T WORK)
-Heals units around that hero for fixed value + STR bonus (DOESN'T WORK)
-Creates Special effect on nearby units while attacking. (WORKS)

Theres problem only in Action section



  • Judgment
    • Events
      • Game - GDD_Event becomes Equal to 0.00
    • Conditions
      • (Unit-type of GDD_DamageSource) Equal to Paladin
      • (GDD_DamageSource has buff Judgment of Light ) Equal to True
    • Actions
      • Custom script: local unit udg_LocalUnit
      • Custom script: local location udg_LocalPoint
      • Custom script: local group udg_LocalGroup
      • Set LocalUnit = GDD_DamageSource
      • Set LocalPoint = (Position of LocalUnit)
      • Set LocalGroup = (Units within (150.00 + ((Real((Level of Judgment of Light for LocalUnit))) x 100.00)) of (Position of LocalUnit))
      • Special Effect - Create a special effect attached to the origin of LocalUnit using Abilities\Spells\Human\Heal\HealTarget.mdl
      • Unit - Set life of LocalUnit to (((Real((Strength of LocalUnit (Include bonuses)))) / 4.00) + ((Life of LocalUnit) + ((Real((Level of Judgment of Light for LocalUnit))) x 5.00)))
      • Special Effect - Destroy (Last created special effect)
      • Unit Group - Pick every unit in LocalGroup and do (Actions)
        • Loop - Actions
          • Unit - Set life of (Picked unit) to (((Real((Strength of LocalUnit (Include bonuses)))) / 4.00) + ((Life of (Picked unit)) + ((Real((Level of Judgment of Light for LocalUnit))) x 5.00)))
          • Special Effect - Create a special effect attached to the origin of (Picked unit) using Abilities\Spells\Human\Heal\HealTarget.mdl
      • Custom script: set udg_LocalUnit = null
      • Custom script: call RemoveLocation(udg_LocalPoint)
      • Custom script: call DestroyGroup(udg_LocalGroup)
Informations:

-I tried storing hero's str etc in local variable but still units nearby didn't get healed, although if I set it to PickedUnitHp+(PickedUnitHp+20) then they will get healed for 20hp.

-If I put 'Destroy last effect created' after the second effect, then it doesn't appear at all.

-I can't detect allied units, I tried something like this:
  • Unit Group - Pick every unit in LocalGroup and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Picked unit) belongs to an ally of (Owner of LocalUnit)) Equal to True
        • Then - Actions
          • Unit - Set life of (Picked unit) to (((Real((Strength of LocalUnit (Include bonuses)))) / 4.00) + ((Life of (Picked unit)) + ((Real((Level of Judgment of Light for LocalUnit))) x 5.00)))
          • Special Effect - Create a special effect attached to the origin of (Picked unit) using Abilities\Spells\Human\Heal\HealTarget.mdl
        • Else - Actions
And I tried setting up LocalGroup to pick up units on condition that they are ally of owner of LocalUnit.
 
Level 38
Joined
Feb 27, 2007
Messages
4,951
Since your trigger doesn't involve any waits there's no need to locally shadow those 3 variables like you're doing. I would remove or comment-out (ctrl+F) the first 3 lines and see how that works for you. The problem I immediately see is that your unit-group setting line internally uses GroupEnumUnitsInRange() which requires that the group variable passed to it is not null. When you shadow the group locally it has never been assigned the value of 'empty group' so it can't be used to enum. You can try changing that line to local group udg_LocalGroup = CreateGroup() (might throw an editor error) or add in a 4th line below that says set udg_LocalGroup = CreateGroup(). The local point setting line does work even if the variable is null beforehand so it doesn't suffer from the same problem.

You didn't use LocalPoint properly in the line that sets LocalGroup. You should use some sort of "Matching ..." statement in your group setting line so that you don't grab the enemy units and heal them too! I also noticed that the hero is healed the same amount as the allied units, so instead of healing the hero separately you could just put the hero into the unit group. I'll leave it separate in my code below though. Since you're going to compute the STR amount and the level of Judgement for the paladin multiple times, you might as well just save them into a variable:

  • Set LVLreal = (Real(Level of ...))
  • Set STRreal = (Real(Strength of ...))
  • ...
  • Set LocalGroup = (Units within (150.00 + (LVLreal x 100.00)) of LocalPoint) matching (((Matching Unit) belongs to an ally of (Owner of LocalUnit)) equal to true)
  • Unit Group - Remove LocalUnit from LocalGroup
  • Unit - Set life of LocalUnit to (((Life of LocalUnit) + (STRreal / 4.00)) + (LVLreal x 5.00))
The 'immediately destroy SFX after creation' trick should work fine here because afaik the heal model doesn't have any named animations. Create+Destroy will automatically play the model's death animation if it has one but if it has no named animations it'll just play its 'stand' or default animation.
 
Level 5
Joined
Dec 25, 2018
Messages
110
  • Judgment Copy Copy
    • Events
      • Game - GDD_Event becomes Equal to 0.00
    • Conditions
      • (Unit-type of GDD_DamageSource) Equal to Paladin
      • (GDD_DamageSource has buff Judgment of Light ) Equal to True
    • Actions
      • Set LocalUnit = GDD_DamageSource
      • Set LocalPoint = (Position of LocalUnit)
      • Set PaladinSTR = ((Real((Strength of LocalUnit (Include bonuses)))) / 4.00)
      • Set PaladinLvL = (Real((Level of Judgment of Light for LocalUnit)))
      • Set LocalGroup = (Units within (400.00 + ((Real((Level of Judgment of Light for LocalUnit))) x 100.00)) of LocalPoint matching (((Matching unit) belongs to an ally of (Owner of LocalUnit)) Equal to True))
      • Unit Group - Pick every unit in LocalGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) has buff Judgment of Light ) Equal to True
            • Then - Actions
              • Unit - Set life of (Picked unit) to (PaladinSTR + ((Life of (Picked unit)) + (PaladinLvL x 5.00)))
              • Special Effect - Create a special effect attached to the origin of (Picked unit) using Abilities\Spells\Human\Heal\HealTarget.mdl
            • Else - Actions
Seems like I don't understand local variables yet, I thought I always need to make them to make the spell MUI.
Your suggestion worked, I deleted locals and changed 'Matching' and its fine now.
Problem with effect remains tho, if I add delete last created effect after Special effect line, then the effect doesn't play at all.
Is it the only leak in the code? Maybe
Custom script: call DestroyGroup(LocalGroup) at the end?
 
Last edited:
Level 38
Joined
Feb 27, 2007
Messages
4,951
It could be the problem with the effect is that you attached it to "origin" whereas healtarget.mdl normally attaches to "chest". Try that. Or try another model with a death animation and see if that shows up. Not much more I can suggest other than applying the effect through a dummy ability if createdestroy doesn't work. Without the destroy line it will leak the effects, yes. You also do need to remove the point and destroy the group (why I said to remove the first 3 lines of your trigger but not the last 3):
  • Custom script: call DestroyGroup(udg_LocalGroup)
  • Custom script: call RemoveLocation(udg_LocalPoint)
You would use a local variable to store information during a Wait command that you don't want to be overwritten. For example:

  • Events
    • Unit - A unit starts the effect of an ability
  • Conditions
    • (Ability being cast) equal to Timed Delete
  • Actions
    • Custom script: local unit udg_LocalUnit
    • Custom script: local effect udg_LocalFX
    • Set LocalUnit = (Target unit of ability being cast)
    • Special Effect - Create a special effect attached to the origin of LocalUnit using Blah\Blah\Blah.mdl
    • Set LocalFX = (last created special effect)
    • Wait 5.00 game-time seconds
    • Special Effect - Destroy LocalFX
    • Unit - Explode LocalUnit
    • Custom script: set udg_LocalUnit = null
    • Custom script: set udg_LocalFX = null
 
Level 13
Joined
May 10, 2009
Messages
868
Unfortunately, that specific effect is only displayed during its "Birth" animation, meaning that you really have to wait for it, then, at last, destroy it.

EDIT:
Instead of complicating things so much, why not make it a bit easier for you? I removed the "death" animation, which didn't display anything at all, from that very same effect. This time, even if you destroy the effect right after its creation, the game will display its "birth" anim thoroughly.
 

Attachments

  • HealTarget.mdx
    5.2 KB · Views: 25
Last edited:
Level 5
Joined
Dec 25, 2018
Messages
110
Unfortunately, that specific effect is only displayed during its "Birth" animation, meaning that you really have to wait for it, then, at last, destroy it.

EDIT:
Instead of complicating things so much, why not make it a bit easier for you? I removed the "death" animation, which didn't display anything at all, from that very same effect. This time, even if you destroy the effect right after its creation, the game will display its "birth" anim thoroughly.
Thanks a lot for the effort, it works now :)
 
Status
Not open for further replies.
Top