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

Need help with bonus xp trigger

Status
Not open for further replies.
Level 6
Joined
Jul 12, 2017
Messages
139
Hi, I wanna create a trigger that if a unit equips this item, he/she will gain bonus xp but mine seem to leak and cause lag so I need help here.

There are 3 levels of this equipment so I separate its trigger to 3 but I think there might be a better way to do this? Any suggestion?

  • Boots of Experience 1
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Dying unit) belongs to an enemy of Neutral Hostile) Equal to True
      • (Random integer number between 1 and 100) Less than or equal to 20
    • Actions
      • Set UnitGroup1 = (Units in (Playable map area))
      • Unit Group - Pick every unit in UnitGroup1 and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) has an item of type Boots of Experience) Equal to True
            • Then - Actions
              • Hero - Add 10 experience to (Picked unit), Hide level-up graphics
            • Else - Actions
      • Custom script: call DestroyGroup(udg_UnitGroup1)
There is also an item where it gives gold as well which is similar to this one and I think it need help as well since I think it also causes lag?

  • Golden Boots 1
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Dying unit) belongs to an enemy of Neutral Hostile) Equal to True
      • (Random integer number between 1 and 100) Less than or equal to 75
    • Actions
      • Set UnitGroup1 = (Units in (Playable map area))
      • Unit Group - Pick every unit in UnitGroup1 and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) has an item of type Golden Boots) Equal to True
            • Then - Actions
              • Player - Add 1 to (Owner of (Picked unit)) Current gold
            • Else - Actions
      • Unit Group - Pick every unit in UnitGroup1 and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Dying unit) belongs to an enemy of Neutral Hostile) Equal to True
              • ((Dying unit) is A Hero) Equal to True
              • ((Picked unit) has an item of type Golden Boots) Equal to True
            • Then - Actions
              • Set Point1 = (Position of (Picked unit))
              • Player - Add 25 to (Owner of (Picked unit)) Current gold
              • Floating Text - Create floating text that reads |c00FFFF00+25 Gold!... at Point1 with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
              • Set Floating_Text10 = (Last created floating text)
              • Floating Text - Set the velocity of Floating_Text10 to 64.00 towards 90.00 degrees
              • Floating Text - Change Floating_Text10: Disable permanence
              • Floating Text - Change the lifespan of Floating_Text10 to 5.00 seconds
              • Floating Text - Change the fading age of Floating_Text10 to 2.50 seconds
              • Custom script: call RemoveLocation(udg_Point1)
            • Else - Actions
      • Custom script: call DestroyGroup(udg_UnitGroup1)
 
You don't need to set all units in the map as a unit group all the time. Do like this instead:

  • Bonus
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Killing unit) has an item of type Bonus XP Item) Equal to True
        • Then - Actions
          • Hero - Add 10 experience to (Killing unit), Hide level-up graphics
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Killing unit) has an item of type Bonus Gold Item) Equal to True
        • Then - Actions
          • Player - Set (Owner of (Killing unit)) Current gold to (((Owner of (Killing unit)) Current gold) + 50)
        • Else - Actions
Also in your second trigger there's only a 75% chance to get the gold bonus. Is that intentional?

Another thing to note is that all of the units with said item in their inventory will trigger the bonus in your triggers. I'm not sure if that's intentional or not?
 
Last edited:
Level 6
Joined
Jul 12, 2017
Messages
139
1. The 75% chance to get gold is intentional due to it may be too OP
2. That is also intentional as well. All heroes with this item will gain bonus as well

Well, the thing is, I don't want only the killing unit to gain xp bonus but also the holder of the item.

The owner of this item may be a support type character who rarely get kills which makes them fall behind in term of resources so I want this item to help them.
 
I don't see anything that leaks here, or anything that might cause lag except for the fact that you always pick every single unit in the map every time a unit dies. Try narrowing down your set unit group variable a bit, like so:

  • Set TempGroup = (Units in (Playable map area) matching ((((Unit-type of (Matching unit)) is A Hero) Equal to True) and (((Matching unit) has an item of type Your Item) Equal to True)))
See if that helps with the lag.

EDIT: Ah, also include a check to see if the units you save to TempGroup are alive, or else you will add every single unit that has died, unless they have been properly removed.
 
Level 8
Joined
May 21, 2019
Messages
435
1. The 75% chance to get gold is intentional due to it may be too OP
2. That is also intentional as well. All heroes with this item will gain bonus as well

Well, the thing is, I don't want only the killing unit to gain xp bonus but also the holder of the item.

The owner of this item may be a support type character who rarely get kills which makes them fall behind in term of resources so I want this item to help them.
It kinda seems like you want the holder of the item to be the only one getting bonus exp/gold.
What you need to do, is select all units within the shared EXP radius of the dying target owned by an ally of the killing player (Currently enemy of neutral hostile, but that would actually give you exp when friendly units die).
Then you cycle through those units and give units holding the bonus exp/gold items the desired bonuses.
 
Level 6
Joined
Jul 12, 2017
Messages
139
It kinda seems like you want the holder of the item to be the only one getting bonus exp/gold.
What you need to do, is select all units within the shared EXP radius of the dying target owned by an ally of the killing player (Currently enemy of neutral hostile, but that would actually give you exp when friendly units die).
Then you cycle through those units and give units holding the bonus exp/gold items the desired bonuses.

I kinda get what you're saying, but can I get an example of that kind of trigger? You mean I need to use like unit group/radius of units around dying unit?
 
Level 13
Joined
May 10, 2009
Messages
868
All heroes with this item will gain bonus as well
Here's an example

  • Acquiring EXP
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
      • (Item-type of (Item being manipulated)) Equal to Knowledge is Power // *Ahem*... Boots of Experience
    • Actions
      • Unit Group - Add (Triggering unit) to Item_KiP_Group
  • Units Dies EXP
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Not equal to Neutral Hostile
    • Actions
      • Unit Group - Pick every unit in Item_KiP_Group and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Random integer number between 1 and 10) Less than or equal to 2
              • ((Picked unit) is dead) Equal to False
            • Then - Actions
              • Hero - Add 10 experience to (Picked unit), Hide level-up graphics
            • Else - Actions
  • Dropping EXP
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
      • (Item-type of (Item being manipulated)) Equal to Knowledge is Power
    • Actions
      • Unit Group - Remove (Triggering unit) from Item_KiP_Group
This way you don't need to worry about enumerating units that do not have such item. Also, the unit group is permanent.

It's worth noting that the filter needs to be improved as you could potentially earn XP from your own units (including structures).
 
Level 6
Joined
Jul 12, 2017
Messages
139
Here's an example

  • Acquiring EXP
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
      • (Item-type of (Item being manipulated)) Equal to Knowledge is Power // *Ahem*... Boots of Experience
    • Actions
      • Unit Group - Add (Triggering unit) to Item_KiP_Group
  • Units Dies EXP
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Not equal to Neutral Hostile
    • Actions
      • Unit Group - Pick every unit in Item_KiP_Group and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Random integer number between 1 and 10) Less than or equal to 2
              • ((Picked unit) is dead) Equal to False
            • Then - Actions
              • Hero - Add 10 experience to (Picked unit), Hide level-up graphics
            • Else - Actions
  • Dropping EXP
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
      • (Item-type of (Item being manipulated)) Equal to Knowledge is Power
    • Actions
      • Unit Group - Remove (Triggering unit) from Item_KiP_Group
This way you don't need to worry about enumerating units that do not have such item. Also, the unit group is permanent.

It's worth noting that the filter needs to be improved as you could potentially earn XP from your own units (including structures).

Thanks! I wanna ask that if I have 3 levels of this item, do I need to make this trigger 3 times and will it leak anything?
 
Level 8
Joined
May 21, 2019
Messages
435
I kinda get what you're saying, but can I get an example of that kind of trigger? You mean I need to use like unit group/radius of units around dying unit?

Don't have a map editor on me… but... it'd be something like:
  • EVENTS
  • A unit dies
  • CONDITIONS
  • Unit is a structure equal to false
  • ACTIONS
  • Set Group = Units within XXX yards of dying unit.
  • For every unit in Group, do actions:
  • (
  • If picked unit = (carrying item)
  • If picked unit is an ally of killing unit
  • If dying unit is owned by owner of killing unit equal to false
  • )
  • THEN
  • (
  • Add Y amount of experience to picked unit
  • )
  • Custom script to delete Group to fix memory leak
That's how you'd go about giving experience to allies of the killing unit holding the item that are within the exp sharing range. If you want the item to work globally, you can just skip the range part of the select.
I appologize for the pseudo-code, but I am on the go right now, so I kinda had to wing it. :D
Do ask if the general concept isn't clear enough.
 
Last edited:
Level 6
Joined
Jul 12, 2017
Messages
139
Don't have a map editor on me… but... it'd be something like:
  • EVENTS
  • A unit dies
  • CONDITIONS
  • Unit is a structure equal to false
  • ACTIONS
  • Set Group = Units within XXX yards of dying unit.
  • For every unit in Group, do actions:
  • If picked unit = (carrying item)
  • If picked unit is an ally of killing unit
  • If dying unit is owned by owner of killing unit equal to false
  • THEN
  • Add Y amount of experience to picked unit
  • Custom script to delete Group to fix memory leak
That's how you'd go about giving experience to allies of the killing unit holding the item that are within the exp sharing range. If you want the item to work globally, you can just skip the range part of the select.
I appologize for the pseudo-code, but I am on the go right now, so I kinda had to wing it. :D
Do ask if the general concept isn't clear enough.

Thanks! I'm gonna try this and see if this helps my map to work better. +rep for both of you and I'll ask further more if there's any progress or problem.
 
Level 1
Joined
Dec 4, 2019
Messages
7
I know this isn't really what you asked, but it may serve to help you in some way. This is the (unfinished but effective) script i'm using to award exp to my hero-units, so no matter how many i have in range, they all still earn the right amount. You could easily add more "ifs" to limit it to certain players, or add an additional bonus to units holding your orb. Just trying to offer some options that work for me :D

Basically what it's doing is adding exp to the main character when you or your ally kill something, and half as much to every "hero" around it. The main chara exp can be further boosted by changing the multiplier variable. I set default exp to 0% so this trigger is the exclusive generator of exp on my map.

Edit: this probably has one or more leaks in it, which for me isn't a huge concern at the moment. If your map is going to go on for a long time though, you might wanna clean it up a bit first.

  • Exp
    • Events
      • Unit - A unit Dies
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Owner of (Killing unit)) Equal to Player 22 (Snow)
          • (Owner of (Killing unit)) Equal to Player 21 (Coal)
    • Actions
      • Unit Group - Pick every unit in (Units within 1500.00 of (Position of (Dying unit))) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to MainHeroType
            • Then - Actions
              • Hero - Add ((Point-value of (Dying unit)) / (4 x ExpMultiplier)) experience to (Picked unit), Show level-up graphics
            • Else - Actions
              • Hero - Add ((Point-value of (Dying unit)) / 8) experience to (Picked unit), Show level-up graphics
 
Status
Not open for further replies.
Top