• 🏆 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] Hero levels more than once

Status
Not open for further replies.
Level 4
Joined
Aug 16, 2013
Messages
75
I have a trigger which makes a hero lose -1 skill point for each level that hero gains. The hero only gains +1 skill points at levels 10, 20, 30, 40, 50, and up to 100 by going by tens. The hero is meant to keep the skill point at level 1, and the next skill points should be at 10, 20, etc.

The thing I am having trouble with, is that when the hero levels more than once at the same time, so for example, the hero kills a unit and then that hero gains enough EXP to go from level 1 to level 4, that hero will gain additional skill points.

I am looking for something that will make it so if that hero levels more than once from a single enemy, he will only get skill points at levels 1, 10, 20, and up to 100 by tens.

The trigger doesn't reoccur more than once from multiple levels gained at the same time, unfortunately.

  • Hero Leveling
    • Events
      • Unit - A unit Gains a level
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to /w Nothing
          • (Unit-type of (Triggering unit)) Equal to /w Broadsword
          • (Unit-type of (Triggering unit)) Equal to /w Aqua Sword
          • (Unit-type of (Triggering unit)) Equal to /w Claymore
          • (Unit-type of (Triggering unit)) Equal to /w Flame Saber
          • (Unit-type of (Triggering unit)) Equal to /w Battle Axe
          • (Unit-type of (Triggering unit)) Equal to /w Thunder Axe
          • (Unit-type of (Triggering unit)) Equal to /w Boulder Hammer
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Hero level of (Triggering unit)) Greater than or equal to 1
        • Then - Actions
          • Hero - Modify unspent skill points of (Triggering unit): Subtract 1 points
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Hero level of (Triggering unit)) Equal to 10
        • Then - Actions
          • Hero - Modify unspent skill points of (Triggering unit): Add 1 points
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Hero level of (Triggering unit)) Equal to 20
            • Then - Actions
              • Hero - Modify unspent skill points of (Triggering unit): Add 1 points
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Hero level of (Triggering unit)) Equal to 30
                • Then - Actions
                  • Hero - Modify unspent skill points of (Triggering unit): Add 1 points
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Hero level of (Triggering unit)) Equal to 40
                    • Then - Actions
                      • Hero - Modify unspent skill points of (Triggering unit): Add 1 points
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Hero level of (Triggering unit)) Equal to 50
                        • Then - Actions
                          • Hero - Modify unspent skill points of (Triggering unit): Add 1 points
                        • Else - Actions
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
Strange. That triggers works for me just fine. What you could do is to start a 0 second timer and after its expiration you would subtract one skill point from the unit.

Your trigger is inefficient though. You always remove that one skill point and then you give it back if hero reached level 10/20/30/40/50.
Also, your hero's level IS ALWAYS greater than 1, hence the first If/Then/Else (ITE) is unneeded, because it never reaches the "Else" block.
You nest ITEs way too much. If you look at your nested ITEs, they're all same! The only difference is in condition but for that you can use the same approach you use for the trigger's condition - an OR statement.
So your trigger could look like this:
  • Reaction
    • Events
      • Unit - A unit Gains a level
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Unit_A
          • (Unit-type of (Triggering unit)) Equal to Unit_B
          • (Unit-type of (Triggering unit)) Equal to Unit_C
    • Actions
      • Hero - Modify unspent skill points of (Triggering unit): Subtract 1 points
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Hero level of (Triggering unit)) Equal to 10
              • (Hero level of (Triggering unit)) Equal to 20
              • (Hero level of (Triggering unit)) Equal to 30
              • (Hero level of (Triggering unit)) Equal to 40
              • (Hero level of (Triggering unit)) Equal to 50
        • Then - Actions
          • Hero - Modify unspent skill points of (Triggering unit): Add 1 points
        • Else - Actions
But let's take a look at what you want to do from other perspective: If you think about it, what you want to do is "Subtract skill point for every level except levels 10, 20, 30, 40 and 50". So a trigger for that could look like this:
  • Reaction
    • Events
      • Unit - A unit Gains a level
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Unit_A
          • (Unit-type of (Triggering unit)) Equal to Unit_B
          • (Unit-type of (Triggering unit)) Equal to Unit_C
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Hero level of (Triggering unit)) Not equal to 10
          • (Hero level of (Triggering unit)) Not equal to 20
          • (Hero level of (Triggering unit)) Not equal to 30
          • (Hero level of (Triggering unit)) Not equal to 40
          • (Hero level of (Triggering unit)) Not equal to 50
        • Then - Actions
          • Hero - Modify unspent skill points of (Triggering unit): Subtract 1 points
        • Else - Actions
Notice I changed it from "Hero's level EQUAL to X" to "Hero's level NOT EQUAL to X", removed it from OR block and put it into the (default) AND block.
So if hero's level is not 10/20/30/40/50, it will subtract 1 skill point, else it will do nothing (since it does nothing, it does not subtract the point, so hero is left with 1 skill point).

Now taking another look at the conditions, they're "level not equal to 10/20/30/40/50". But those numbers are a sequence of multiples of ten. Those five conditions can be merged simply into one by using modulo function and checking the remainder of the operation.
A 10 mod 2 is 0 --> 10/2 = 5, remainder is 0. A 10 mod 3 is 1 --> 10/3 = 3, remainder 1.
In our case, the dividend is hero's level and divisor is number 10 (since 10/20/30/40/50 are multiples of ten). Then we check the remainder of the operation and if it is greater than 0 we ca subtract skill point (since remainder 0 is only for the multiples of ten). So what we get is this:
  • Reaction
    • Events
      • Unit - A unit Gains a level
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Unit_A
          • (Unit-type of (Triggering unit)) Equal to Unit_B
          • (Unit-type of (Triggering unit)) Equal to Unit_C
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Hero level of (Triggering unit)) mod 10) Not equal to 0
        • Then - Actions
          • Hero - Modify unspent skill points of (Triggering unit): Subtract 1 points
        • Else - Actions
Now, there's no need to leave the last ITE, right? Since nothing happens in the trigger otherwise, because everything is depended on the condition in the ITE (the level checking condition), we can change the trigger into its final form by putting that condition into the trigger's condition block:
  • Reaction
    • Events
      • Unit - A unit Gains a level
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Unit_A
          • (Unit-type of (Triggering unit)) Equal to Unit_B
          • (Unit-type of (Triggering unit)) Equal to Unit_C
      • ((Hero level of (Triggering unit)) mod 10) Not equal to 0
    • Actions
      • Hero - Modify unspent skill points of (Triggering unit): Subtract 1 points
This final version does work for me. It should work for you as well unless some other trigger is colliding with this one. In any case, you can see that with different approach, you can minimize the amount of operations and thus greatly optimize your triggers. The trigger you posted had 6 ITEs, 6 conditions (and 6 actions). It could get minimized into trigger without any ITE, only 1 condition and 1 action.
 
Status
Not open for further replies.
Top