• 🏆 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] Dying unit, give xp/gold system...

Status
Not open for further replies.
Level 7
Joined
Dec 8, 2008
Messages
243
I post way to often on here...

  • Gold and XP System
    • Events
      • Unit - A unit Dies
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Owner of (Dying unit)) Equal to Player 12 (Brown)
          • (Owner of (Dying unit)) Equal to Neutral Hostile
    • Actions
      • Set Gain_XP = (Random integer number between (Level of (Dying unit)) and ((Level of (Dying unit)) + 5))
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in (Units within 1100.00 of (Position of (Killing unit)) matching ((((Matching unit) is A Hero) Equal to True) and ((((Matching unit) is alive) Equal to True) and (((Matching unit) belongs to an enemy of (Owner of (Dying unit))) Equal to True)))) and do (Actions)
            • Loop - Actions
              • Hero - Add Gain_XP experience to (Picked unit), Show level-up graphics
              • Floating Text - Create floating text that reads (+ + ((String(Gain_XP)) + coins)) above (Picked unit) with Z offset 0.00, using font size 10.00, color (80.00%, 80.00%, 40.00%), and 0.00% transparency
              • Floating Text - Set the velocity of (Last created floating text) to 60.00 towards 270.00 degrees
              • Floating Text - Change (Last created floating text): Disable permanence
              • Floating Text - Change the lifespan of (Last created floating text) to 1.00 seconds
              • Floating Text - Change the fading age of (Last created floating text) to 2.00 seconds
              • -------- -- --------
              • Player - Add Gain_XP to (Owner of (Picked unit)) Current gold
              • Floating Text - Create floating text that reads (+ + ((String(Gain_XP)) + xp)) above (Picked unit) with Z offset 0.00, using font size 10.00, color (66.00%, 99.00%, 66.00%), and 0.00% transparency
              • Floating Text - Set the velocity of (Last created floating text) to 60.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 1.00 seconds
              • Floating Text - Change the fading age of (Last created floating text) to 2.00 seconds
There's likely a leak I don't know about. I've not bothered to read any anti-leak tutorials (although I'm about to start)... The floating text on this works fine, but what doesn't work is, when giving the nearby hero the xp/gold, he gets 10 times what the floating text displays.

I've tried giving the hero/player Gain_XP/10, but that just gives 0.
 
Level 7
Joined
Dec 8, 2008
Messages
243
Okay! Got it to work. I completely blanked the for integer A to herp derp 1 - 10 which wasn't actually doing anything.

So, removing that, it now works.
 
Level 12
Joined
Aug 22, 2008
Messages
911
You're leaking a unit group.
Simply take the criteria for the unit group and put them into a variable like this:
  • Set unitgroup = <Criteria>
After that, when using the pick every unit function, refer to the variable:
  • Unit Group - Pick every unit in unitgroup and do (All Actions)
Last step, remove the unit group after it is used so no leak will be left:
  • Custom script: call DestroyGroup(udg_unitgroup)
Pay attention that these actions are all within the For loop boundaries.
 
Status
Not open for further replies.
Top