• 🏆 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!

Takes Damage -> Add Damage source to unitgroup not working

Status
Not open for further replies.
Level 6
Joined
Jan 12, 2011
Messages
110
Hello!
I'm having a trouble regarding custom Experience and Gold system. I'm using unit indexer, tried even setting custom value myself to all units.
It should work like this:
At init, every unit creates a Event in trigger when it Takes Damage
When the unit takes damage, damaging unit (Damage Source) is added into UnitGroup(CustomValueOfDamagedUnit)
When the unit dies, every unit, that damaged it (every unit in unitgroup) is rewarded with XP and gold.

The problem starts with the unit not being added into the unit group. I have also seen, that when I turn Unit Indexer off and don't assing any custom value to the dying units, the system works just fine.
Problem is, I need the custom value for respawn of the units.
Also, unit with custom value 1 still gives gold and exp, others dont - so the Takes Damage event is properly set and "working".

Any good soul here to try resolve my issue?
I can either respawn units properly, or use the exp and gold system properly with this solution of mine.

PS: Dont mind the text messages, those are for testing purpose only.

EDIT: Also added demo test map I'm using to test the system, which is taken from the main map.

  • EB Refresh
    • Events
      • Time - Every 60.00 seconds of game time
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Trigger - Reset EB Init Dmg Source <gen>
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units owned by Neutral Hostile) and do (Actions)
        • Loop - Actions
          • Set Respawn_Point[(Custom value of (Picked unit))] = (Position of (Picked unit))
          • Trigger - Add to EB Init Dmg Source <gen> the event (Unit - (Picked unit) Takes damage)
  • EB Init Dmg Source
    • Events
    • Conditions
      • Multiple ConditionsAnd - All (Conditions) are true
        • Conditions
          • ((Damage source) is in EB_UG[(Custom value of (Triggering unit))]) Equal to (==) False
          • ((Damage source) is A Hero) Equal to (==) True
    • Actions
      • Custom script: local unit u = GetTriggerUnit()
      • Custom script: local unit d = GetEventDamageSource()
      • Custom script: local integer i = GetUnitUserData(u)
      • Custom script: call GroupAddUnit(udg_EB_UG[i] , d )
      • Game - Display to (All players) the text: (Name of (GetEventDamageSource()))
  • EB Trigger
    • Events
      • Unit - A unit Dies
    • Conditions
      • Multiple ConditionsOr - Any (Conditions) are true
        • Conditions
          • (Owner of (Dying unit)) Equal to (==) Neutral Hostile
          • (Owner of (Dying unit)) Equal to (==) Player 12 (Brown)
      • ((Killing unit) is A Hero) Equal to (==) True
    • Actions
      • Game - Display to (All players) the text: EB TRIGGER 1
      • Game - Display to (All players) the text: (String((Number of units in EB_UG[(Custom value of (Triggering unit))])))
      • Set EB_UnitNumber = (Number of units in EB_UG[(Custom value of (Triggering unit))])
      • Game - Display to (All players) the text: (String(EB_UnitNumber))
      • If (EB_UnitNumber Equal to (==) 0) then do (Skip remaining actions) else do (Do nothing)
      • Game - Display to (All players) the text: EB TRIGGER 2
      • Set Integer_Procs = (Integer_Procs + 1)
      • Set EB_Unit = (Triggering unit)
      • Set EB_Life = (Max life of (Triggering unit))
      • Set EB_Point = (Position of EB_Unit)
      • Set EB_CustomValue = (Custom value of (Triggering unit))
      • -------- This makes life of healers easier putting them onto damage list too. --------
      • Set EB_UGHealers = (Units within 1000.00 of EB_Point matching (((Matching unit) is A Hero) Equal to (==) True))
      • Unit Group - Pick every unit in EB_UGHealers and do (Actions)
        • Loop - Actions
          • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Multiple ConditionsOr - Any (Conditions) are true
                • Conditions
                  • (Unit-type of (Picked unit)) Equal to (==) UnitType_Healer[1]
                  • (Unit-type of (Picked unit)) Equal to (==) UnitType_Healer[2]
                  • (Unit-type of (Picked unit)) Equal to (==) UnitType_Healer[3]
                  • (Unit-type of (Picked unit)) Equal to (==) UnitType_Healer[4]
                  • (Unit-type of (Picked unit)) Equal to (==) UnitType_Healer[5]
                  • (Unit-type of (Picked unit)) Equal to (==) UnitType_Healer[6]
            • Then - Actions
              • Unit Group - Add (Picked unit) to EB_UG[EB_CustomValue]
              • Unit Group - Remove (Picked unit) from EB_UGHealers
            • Else - Actions
              • Unit Group - Remove (Picked unit) from EB_UGHealers
      • -------- --------------------------------------- --------
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • EB_UnitNumber Equal to (==) 1
          • Then - Actions
            • Player Group - Add (Owner of (Killing unit)) to EB_Force
            • -------- Checks if the distance of levels isn't higher than 20 --------
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Multiple ConditionsOr - Any (Conditions) are true
                    • Conditions
                      • ((Level of (Triggering unit)) - (Level of (Killing unit))) Greater than or equal to (>=) 20
                      • ((Level of (Triggering unit)) - (Level of (Killing unit))) Less than or equal to (<=) -20
                      • ((Level of (Killing unit)) - (Level of (Triggering unit))) Greater than or equal to (>=) 20
                      • ((Level of (Killing unit)) - (Level of (Triggering unit))) Less than or equal to (<=) -20
                • Then - Actions
                  • Set EB_Exp = 5.00
                  • Set EB_Bounty = 5.00
                • Else - Actions
                  • -------- Sets appropriate number of XP gained by hero; If hero's level is higher -> less XP; if lower -> more XP --------
                    • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • (Level of (Killing unit)) Greater than or equal to (>=) (Level of (Triggering unit))
                      • Then - Actions
                        • Set EB_Level = ((Level of (Killing unit)) - (Level of (Triggering unit)))
                        • Set EB_Exp = (EB_ExpGain x (EB_Life x 0.50))
                        • Set EB_Exp = (EB_Exp - ((EB_Exp x 0.05) x (Real(EB_Level))))
                      • Else - Actions
                        • Set EB_Level = ((Level of (Triggering unit)) - (Level of (Killing unit)))
                        • Set EB_Exp = (EB_ExpGain x (EB_Life x 0.50))
                        • Set EB_Exp = (EB_Exp + ((EB_Exp x 0.02) x (Real(EB_Level))))
                  • -------- The same for Bounty --------
                    • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • (Level of (Killing unit)) Greater than or equal to (>=) (Level of (Triggering unit))
                      • Then - Actions
                        • Set EB_Level = ((Level of (Killing unit)) - (Level of (Triggering unit)))
                        • Set EB_Bounty = (EB_BountyGain x (EB_Life x 0.10))
                        • Set EB_Bounty = (EB_Bounty - ((EB_Bounty x 0.05) x (Real(EB_Level))))
                      • Else - Actions
                        • Set EB_Level = ((Level of (Triggering unit)) - (Level of (Killing unit)))
                        • Set EB_Bounty = (EB_BountyGain x (EB_Life x 0.10))
                        • Set EB_Bounty = (EB_Bounty + ((EB_Bounty x 0.02) x (Real(EB_Level))))
            • -------- Adds XP and Bounty --------
            • Set EB_Bounty = (EB_Bounty x (Random real number between 0.00 and 2.00))
            • Hero - Add (Integer(EB_Exp)) experience to (Killing unit), Show level-up graphics
            • Player - Add (Integer(EB_Bounty)) to (Owner of (Killing unit)) Current gold
            • -------- Creates Gold gained text --------
            • Floating Text - Create floating text that reads (+ + ((String((Integer(EB_Bounty)))) + copper)) at EB_Point with Z offset 0.00, using font size 10.00, color (72.00%, 45.00%, 20.00%), and 0.00% transparency
            • Floating Text - Hide (Last created floating text) for (All players)
            • Floating Text - Show (Last created floating text) for EB_Force
            • Floating Text - Set the velocity of (Last created floating text) to 80.00 towards 90.00 degrees
            • Floating Text - Change (Last created floating text): Disable permanence
            • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
            • Floating Text - Change the fading age of (Last created floating text) to 2.50 seconds
            • -------- Creates Experience gained text --------
            • Floating Text - Create floating text that reads (+ + ((String((Integer(EB_Exp)))) + experience)) at EB_Point with Z offset 45.00, using font size 10.00, color (20.00%, 20.00%, 80.00%), and 0.00% transparency
            • Floating Text - Hide (Last created floating text) for (All players)
            • Floating Text - Show (Last created floating text) for EB_Force
            • Floating Text - Set the velocity of (Last created floating text) to 80.00 towards 90.00 degrees
            • Floating Text - Change (Last created floating text): Disable permanence
            • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
            • Floating Text - Change the fading age of (Last created floating text) to 2.50 seconds
          • Else - Actions
            • Unit Group - Pick every unit in EB_UG[(Custom value of (Triggering unit))] and do (Actions)
              • Loop - Actions
                • Player Group - Add (Owner of (Picked unit)) to EB_Force
                • -------- Checks if the distance of levels isn't higher than 20 --------
                  • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Multiple ConditionsOr - Any (Conditions) are true
                        • Conditions
                          • ((Level of (Triggering unit)) - (Level of (Picked unit))) Greater than or equal to (>=) 20
                          • ((Level of (Triggering unit)) - (Level of (Picked unit))) Less than or equal to (<=) -20
                          • ((Level of (Picked unit)) - (Level of (Triggering unit))) Greater than or equal to (>=) 20
                          • ((Level of (Picked unit)) - (Level of (Triggering unit))) Less than or equal to (<=) -20
                    • Then - Actions
                      • Set EB_Exp = 0.00
                      • Set EB_Bounty = 0.00
                    • Else - Actions
                      • -------- Sets appropriate number of XP gained by hero; If hero's level is higher -> less XP; if lower -> more XP --------
                        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                          • If - Conditions
                            • (Level of (Picked unit)) Greater than or equal to (>=) (Level of (Triggering unit))
                          • Then - Actions
                            • Set EB_Level = ((Level of (Picked unit)) - (Level of (Triggering unit)))
                            • Set EB_Exp = (EB_ExpGain x (EB_Life x 0.50))
                            • Set EB_Exp = (EB_Exp - ((EB_Exp x 0.05) x (Real(EB_Level))))
                          • Else - Actions
                            • Set EB_Level = ((Level of (Triggering unit)) - (Level of (Picked unit)))
                            • Set EB_Exp = (EB_ExpGain x (EB_Life x 0.50))
                            • Set EB_Exp = (EB_Exp + ((EB_Exp x 0.02) x (Real(EB_Level))))
                      • -------- The same for Bounty --------
                        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                          • If - Conditions
                            • (Level of (Picked unit)) Greater than or equal to (>=) (Level of (Triggering unit))
                          • Then - Actions
                            • Set EB_Level = ((Level of (Picked unit)) - (Level of (Triggering unit)))
                            • Set EB_Bounty = (EB_BountyGain x (EB_Life x 0.10))
                            • Set EB_Bounty = (EB_Bounty - ((EB_Bounty x 0.05) x (Real(EB_Level))))
                          • Else - Actions
                            • Set EB_Level = ((Level of (Triggering unit)) - (Level of (Picked unit)))
                            • Set EB_Bounty = (EB_BountyGain x (EB_Life x 0.10))
                            • Set EB_Bounty = (EB_Bounty + ((EB_Bounty x 0.02) x (Real(EB_Level))))
                • -------- Adds XP and Bounty --------
                • Set EB_Bounty = (EB_Bounty x (Random real number between 0.00 and 2.00))
                • Hero - Add (Integer(EB_Exp)) experience to (Picked unit), Show level-up graphics
                • Player - Add (Integer(EB_Bounty)) to (Owner of (Picked unit)) Current gold
                • -------- Creates Gold gained text --------
                • Floating Text - Create floating text that reads (+ + ((String((Integer(EB_Bounty)))) + copper)) at EB_Point with Z offset 0.00, using font size 10.00, color (72.00%, 45.00%, 20.00%), and 0.00% transparency
                • Floating Text - Hide (Last created floating text) for (All players)
                • Floating Text - Show (Last created floating text) for EB_Force
                • Floating Text - Set the velocity of (Last created floating text) to 80.00 towards 90.00 degrees
                • Floating Text - Change (Last created floating text): Disable permanence
                • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
                • Floating Text - Change the fading age of (Last created floating text) to 2.50 seconds
                • -------- Creates Experience gained text --------
                • Floating Text - Create floating text that reads (+ + ((String((Integer(EB_Exp)))) + experience)) at EB_Point with Z offset 45.00, using font size 10.00, color (20.00%, 20.00%, 80.00%), and 0.00% transparency
                • Floating Text - Hide (Last created floating text) for (All players)
                • Floating Text - Show (Last created floating text) for EB_Force
                • Floating Text - Set the velocity of (Last created floating text) to 80.00 towards 90.00 degrees
                • Floating Text - Change (Last created floating text): Disable permanence
                • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
                • Floating Text - Change the fading age of (Last created floating text) to 2.50 seconds
                • -------- Clears udgs for next player/unit --------
                • Set EB_Exp = 0.00
                • Set EB_Bounty = 0.00
                • Player Group - Remove (Owner of (Picked unit)) from EB_Force
      • Unit Group - Remove all units from EB_UG[EB_CustomValue]
      • Set EB_Unit = No unit
      • Set EB_Bounty = 0.00
      • Set EB_Exp = 0.00
      • Set EB_UnitNumber = 0
      • Set EB_CustomValue = 0
      • Custom script: call RemoveLocation(udg_EB_Point)
      • Custom script: call DestroyGroup(udg_EB_UGHealers)
  • Unit Indexer
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: call ExecuteFunc("InitializeUnitIndexer")
      • Custom script: endfunction
      • -------- --------
      • -------- This is the most important function - it provides an index for units as they enter the map --------
      • -------- --------
      • Custom script: function IndexUnit takes nothing returns boolean
      • Custom script: local integer pdex = udg_UDex
      • -------- --------
      • -------- You can use the boolean UnitIndexerEnabled to protect some of your undesirable units from being indexed --------
      • -------- - Example: --------
      • -------- -- Set UnitIndexerEnabled = False --------
      • -------- -- Unit - Create 1 Dummy for (Triggering player) at TempLoc facing 0.00 degrees --------
      • -------- -- Set UnitIndexerEnabled = True --------
      • -------- --------
      • -------- You can also customize the following block - if conditions are false the (Matching unit) won't be indexed. --------
      • -------- --------
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • UnitIndexerEnabled Equal to (==) True
          • Then - Actions
            • -------- --------
            • -------- Generate a unique integer index for this unit --------
            • -------- --------
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • UDexRecycle Equal to (==) 0
                • Then - Actions
                  • Set UDex = (UDexGen + 1)
                  • Set UDexGen = UDex
                • Else - Actions
                  • Set UDex = UDexRecycle
                  • Set UDexRecycle = UDexNext[UDex]
            • -------- --------
            • -------- Link index to unit, unit to index --------
            • -------- --------
            • Set UDexUnits[UDex] = (Matching unit)
            • Unit - Set the custom value of UDexUnits[UDex] to UDex
            • -------- --------
            • -------- Use a doubly-linked list to store all active indexes --------
            • -------- --------
            • Set UDexPrev[UDexNext[0]] = UDex
            • Set UDexNext[UDex] = UDexNext[0]
            • Set UDexNext[0] = UDex
            • -------- --------
            • -------- Fire index event for UDex --------
            • -------- --------
            • Set UnitIndexEvent = 0.00
            • Set UnitIndexEvent = 1.00
            • Set UnitIndexEvent = 0.00
            • Custom script: set udg_UDex = pdex
          • Else - Actions
      • Custom script: return false
      • Custom script: endfunction
      • -------- --------
      • -------- The next function is called each time a unit enters the map --------
      • -------- --------
      • Custom script: function IndexNewUnit takes nothing returns boolean
      • Custom script: local integer pdex = udg_UDex
      • Custom script: local integer ndex
      • -------- --------
      • -------- Recycle indices of units no longer in-play every (15) units created --------
      • -------- --------
      • Set UDexWasted = (UDexWasted + 1)
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • UDexWasted Equal to (==) 15
          • Then - Actions
            • Set UDexWasted = 0
            • Set UDex = UDexNext[0]
            • Custom script: loop
            • Custom script: exitwhen udg_UDex == 0
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Custom value of UDexUnits[UDex]) Equal to (==) 0
                • Then - Actions
                  • -------- --------
                  • -------- Remove index from linked list --------
                  • -------- --------
                  • Custom script: set ndex = udg_UDexNext[udg_UDex]
                  • Custom script: set udg_UDexNext[udg_UDexPrev[udg_UDex]] = ndex
                  • Custom script: set udg_UDexPrev[ndex] = udg_UDexPrev[udg_UDex]
                  • Set UDexPrev[UDex] = 0
                  • -------- --------
                  • -------- Fire deindex event for UDex --------
                  • -------- --------
                  • Set UnitIndexEvent = 2.00
                  • Set UnitIndexEvent = 0.00
                  • -------- --------
                  • -------- Recycle the index for later use --------
                  • -------- --------
                  • Set UDexUnits[UDex] = No unit
                  • Set UDexNext[UDex] = UDexRecycle
                  • Set UDexRecycle = UDex
                  • Custom script: set udg_UDex = ndex
                • Else - Actions
                  • Set UDex = UDexNext[UDex]
            • Custom script: endloop
            • Custom script: set udg_UDex = pdex
          • Else - Actions
      • -------- --------
      • -------- Handle the entering unit (Matching unit) --------
      • -------- --------
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Custom value of (Matching unit)) Equal to (==) 0
          • Then - Actions
            • Custom script: call IndexUnit()
          • Else - Actions
      • Custom script: return false
      • Custom script: endfunction
      • -------- --------
      • -------- The next function initializes the core of the system --------
      • -------- --------
      • Custom script: function InitializeUnitIndexer takes nothing returns nothing
      • Custom script: local integer i = 0
      • Custom script: local region re = CreateRegion()
      • Custom script: local rect r = GetWorldBounds()
      • Set UnitIndexerEnabled = True
      • Custom script: call RegionAddRect(re, r)
      • Custom script: call TriggerRegisterEnterRegion(CreateTrigger(), re, Filter(function IndexNewUnit))
      • Custom script: call RemoveRect(r)
      • Custom script: set re = null
      • Custom script: set r = null
      • Custom script: loop
      • Custom script: call GroupEnumUnitsOfPlayer(bj_lastCreatedGroup, Player(i), Filter(function IndexUnit))
      • Custom script: set i = i + 1
      • Custom script: exitwhen i == 16
      • Custom script: endloop
      • -------- --------
      • -------- This is the "Unit Indexer Initialized" event, use it instead of "Map Initialization" for best results --------
      • -------- --------
      • Set UnitIndexEvent = 3.00
      • Set UnitIndexEvent = 0.00
 

Attachments

  • test EB.w3x
    34.5 KB · Views: 54
Last edited:
Level 22
Joined
Feb 6, 2014
Messages
2,466
First of all, your EB Refresh doesn't refresh at all. You should destroy-re-create EB Init Dmg Source so that the 'trigger don't get overflooded' with events. Next is you leak handles, which can be fixed by: set u = null and set d = null, etc.

Now your problem is caused by not creating the unit- group. Before calling GroupAddUnit, you should check first if udg_EB_UG == null and if it is, set udg_EB_UG = CreateGroup()

And, when a new Neutral Unit enters the map, it won't be registered to the DDS until another 60 seconds have passed. So you might wanna create another trigger for that. Event is: A unit enters Playable map area.
 
Level 6
Joined
Jan 12, 2011
Messages
110
First of all, your EB Refresh doesn't refresh at all. You should destroy-re-create EB Init Dmg Source so that the 'trigger don't get overflooded' with events. Next is you leak handles, which can be fixed by: set u = null and set d = null, etc.

Now your problem is caused by not creating the unit- group. Before calling GroupAddUnit, you should check first if udg_EB_UG == null and if it is, set udg_EB_UG = CreateGroup()

And, when a new Neutral Unit enters the map, it won't be registered to the DDS until another 60 seconds have passed. So you might wanna create another trigger for that. Event is: A unit enters Playable map area.


Thank you very much for prompt reply!
I did the changes and was aware of the leaks :)...

Anyway, I used different indexer, didn't like this one, and now it works perfectly as intended.

One more question though...
How come that "Trigger - Reset Trigger" does not renew the trigger? In comment it says "Resets a trigger to its original state" - to me it says It will delete every changes made to the trigger, and renew the state you see in World Editor.
Or am I wrong?
 
Level 22
Joined
Feb 6, 2014
Messages
2,466
To be honest, I'm not sure about the 'Reset Trigger' Action. But other DDS does not use that instead, they destroy-re-create triggers.
Your interpretation could be right, but it can also mean reset the trigger by means of ON or OFF. It could mean that if your trigger is initially ON, and you changes it, reseting it will turn it ON again. That hypothesis could be wrong though, but to be sure, just destroy-re-create the trigger.
 
Status
Not open for further replies.
Top