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

[Solved] Unit's mana determining level of abiltiy

Status
Not open for further replies.
Level 4
Joined
Feb 9, 2010
Messages
48
Greetings chaps,

I'm trying to create a certain mechanic for group of units:
They generate mana when taking damage and dealing damage (Hidden searing arrow and mana shield), and have minus mana regeneartion, so over time their mana is decreasing.

Based on how much mana they have, I want them to have:
  • 0 - 100 mana, units have: -15% damage, +2 armor
  • 100 - 200 mana, units have no bonuses
  • 200 - 400 mana, units have: +25% damage, -2 armor
For the damage and armor bonus, I've made a hidden item armor bonus and command aura with 3 levels, each of the abilities being hidden aswell (Via spellbook). On level 1 they increase armor and decrease damage, level 2 no benefits, level 3 increased damage and reduced armor.

However, I'm having trouble with triggers detecting their mana level.
This is an example of trigger that adds the trained unit type to the second trigger which detects mana level:
  • Rage On Train
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Owner of (Trained unit)) Equal to Player 7 (Green)
    • Actions
      • Unit - Order (Trained unit) to Neutral Naga Sea Witch - Activate Mana Shield
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Unit-type of (Trained unit)) Equal to Dragonrider [Corrupted]
              • (Unit-type of (Trained unit)) Equal to Orc Crossbowman [Corrupted]
              • (Unit-type of (Trained unit)) Equal to Grunt [Corrupted]
              • (Unit-type of (Trained unit)) Equal to Wolfrider [Corrupted]
              • (Unit-type of (Trained unit)) Equal to Warchief [Corrupted]
              • (Unit-type of (Trained unit)) Equal to Ravager [Corrupted]
        • Then - Actions
          • Trigger - Add to Rage Paths mana <gen> the event (Unit - (Trained unit)'s mana becomes Greater than or equal to 100.00)
          • Trigger - Add to Rage Paths mana <gen> the event (Unit - (Trained unit)'s mana becomes Greater than or equal to 200.00)
          • Trigger - Add to Rage Paths mana <gen> the event (Unit - (Trained unit)'s mana becomes Less than or equal to 200.00)
          • Trigger - Add to Rage Paths mana <gen> the event (Unit - (Trained unit)'s mana becomes Less than or equal to 100.00)
        • Else - Actions
The second trigger which detects the mana level and changes the level of abilities:
  • Rage Paths mana
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Mana of (Triggering unit)) Less than 100.00
        • Then - Actions
          • Unit - Set level of Rage Bonus Damage Aura for (Triggering unit) to 1
          • Unit - Set level of Rage Armor Bonus [Rage Path] for (Triggering unit) to 1
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • (Mana of (Triggering unit)) Less than 200.00
              • (Mana of (Triggering unit)) Greater than or equal to 100.00
        • Then - Actions
          • Unit - Set level of Rage Bonus Damage Aura for (Triggering unit) to 2
          • Unit - Set level of Rage Armor Bonus [Rage Path] for (Triggering unit) to 2
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Mana of (Triggering unit)) Greater than or equal to 200.00
        • Then - Actions
          • Unit - Set level of Rage Bonus Damage Aura for (Triggering unit) to 3
          • Unit - Set level of Rage Armor Bonus [Rage Path] for (Triggering unit) to 3
        • Else - Actions
The problem is that the system is not working very well. It's very chaotic, sometimes it works, sometimes not. When unit's mana becomes higher than 200, it executes well the part for level 3 ability, however when it becomes less than 200 sometimes it doesn't switch the level of abilities, sometimes it does. Same for 100 mana.

Got any ideas how to fix the problem?

Also I have this question, will such triggers cause lag problems? With a map's size comparable to Azeroth Wars/LTA and it's type of gameplay?
 
Last edited:
Level 25
Joined
May 11, 2007
Messages
4,651
Don't take screenshots of your triggers, follow this link instead:
How to easily post triggers

Your first trigger has the flaw that it orders ALL units that are trained by player 7 to use the Mana shield. Move the ordering down into the if case where you add the trigger events.

Your if case for Rage path mana has some logical flaws in the conditions:
When you set the level to 2, there's no need for the AND condition since the if (all conditions are true) already checks ALL conditions, just a small thingy.

Try removing the abilities and then adding them and setting their level instead of just setting their level, if I remember the game has some trouble with reducing ability levels.

-----------------------------------------------------------------------
Your best solution to this would just to have a unit group that everytime a unit is trained of one of the unit types, that unit is added to the unit group.

Then have a seperate trigger that runs with a timer about every 0.5 second, checking the units in the unit group and their mana level, and set the mana level.

And a third trigger that removes the unit if it dies so it's no longer being checked for it's mana level.

Events - "a unit dies"
conditions: unit is in unit group
actions: unit group - remove unit from unit group.
 
Last edited:
Level 4
Joined
Feb 9, 2010
Messages
48
Don't take screenshots of your triggers, follow this link instead:
How to easily post triggers

Your first trigger has the flaw that it orders ALL units that are trained by player 7 to use the Mana shield. Move the ordering down into the if case where you add the trigger events.

Your if case for Rage path mana has some logical flaws in the conditions:
When you set the level to 2, there's no need for the AND condition since the if (all conditions are true) already checks ALL conditions, just a small thingy.

Try removing the abilities and then adding them and setting their level instead of just setting their level, if I remember the game has some trouble with reducing ability levels.

-----------------------------------------------------------------------
Your best solution to this would just to have a unit group that everytime a unit is trained of one of the unit types, that unit is added to the unit group.

Then have a seperate trigger that runs with a timer about every 0.5 second, checking the units in the unit group and their mana level, and set the mana level.

And a third trigger that removes the unit if it dies so it's no longer being checked for it's mana level.

Events - "a unit dies"
conditions: unit is in unit group
actions: unit group - remove unit from unit group.

I've went with:
  • Rage Paths mana
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Mana of (Triggering unit)) Less than 100.00
        • Then - Actions
          • Unit - Remove Rage Armor Bonus [Rage Path] from (Triggering unit)
          • Unit - Remove Rage Bonus Damage (Spell book invisible lvl1) from (Triggering unit)
          • Unit - Add Rage Bonus Damage (Spell book invisible lvl1) to (Triggering unit)
          • Unit - Add Rage Armor Bonus [Rage Path] to (Triggering unit)
          • Unit - Set level of Rage Bonus Damage Aura for (Triggering unit) to 1
          • Unit - Set level of Rage Armor Bonus [Rage Path] for (Triggering unit) to 1
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • (Mana of (Triggering unit)) Less than 200.00
              • (Mana of (Triggering unit)) Greater than or equal to 100.00
        • Then - Actions
          • Unit - Remove Rage Armor Bonus [Rage Path] from (Triggering unit)
          • Unit - Remove Rage Bonus Damage (Spell book invisible lvl1) from (Triggering unit)
          • Unit - Add Rage Bonus Damage (Spell book invisible lvl1) to (Triggering unit)
          • Unit - Add Rage Armor Bonus [Rage Path] to (Triggering unit)
          • Unit - Set level of Rage Bonus Damage Aura for (Triggering unit) to 2
          • Unit - Set level of Rage Armor Bonus [Rage Path] for (Triggering unit) to 2
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Mana of (Triggering unit)) Greater than or equal to 200.00
        • Then - Actions
          • Unit - Remove Rage Armor Bonus [Rage Path] from (Triggering unit)
          • Unit - Remove Rage Bonus Damage (Spell book invisible lvl1) from (Triggering unit)
          • Unit - Add Rage Bonus Damage (Spell book invisible lvl1) to (Triggering unit)
          • Unit - Add Rage Armor Bonus [Rage Path] to (Triggering unit)
          • Unit - Set level of Rage Bonus Damage Aura for (Triggering unit) to 3
          • Unit - Set level of Rage Armor Bonus [Rage Path] for (Triggering unit) to 3
        • Else - Actions
This made all units have their ability set on level 1, regardless of mana level. Summing up, it didn't help, only made it worse.

Edit: It's still the same as before without the addition and removal of abilities. I've kinda tested the unit and I've came to conlucions:
- When the unit gains 100 mana (but less than 200), triggers works fine, it changes the abilities lvl to 2
- When the unit gains 200 mana, triggers also works fine, changes the abilities level to 3
- When unit's mana degenerates to less than 200 (More than 100), the trigger doesnt work, and stays on level 3. When it degenerates futher to less than 100, the trigger changes the ability of level to 2 (Instead of 1)
- When unit with level 3 ability, uses mana on spell -> 300 - 150 (Mana cost of spell) = 150, then trigger works fine, and changes level of ability to 2
- When unit with level 2 ability, uses mana on spell -> 170 - 150 (Mana cost of spell) = 20, then trigger works fine, and changes level of ability to 1

So summing up, the problem is when unit's mana goes below 200/100, and without a 'heavy spike'. When it degenerates at unit's mana regen rate (-1.1 mana per second) it makes the trigger mess up. When it degenerates at (-9.1 mana per second, with immolation spell on) it also messes up and doesn't change the level of ability correctly.

----

The other solution you proposed with a 'Every 0.5 second of the game' event is certainly not an option. This would cause way too many lags in the map. I'm trying to not implement any events that would be heavily affecting the map's stability, and when I want to use 'every X seconds' I make a dummy-timer unit and have a trigger detecting when it dies.
 
Last edited:
Level 25
Joined
May 11, 2007
Messages
4,651
Aight, just trying to get a solution, so bear with me.

I'm starting to think it's the Events added that cause the problem, that Trigger - Add to Rage Paths mana <gen> the event (Unit - (Trained unit)'s mana becomes Greater than or equal to 100.00) doesn't really reference to the unit trained, instead it says that

"Everytime a trained unit's mana becomes less than 100 do this", which would only happen once since a unit is only trained once.

Could you add a Game - Display text, with the name of the triggering unit to Rage Paths mana?
Then try it with four different units and see if your first unit that you trained shows up more than once.
 
Level 4
Joined
Feb 9, 2010
Messages
48
Aight, just trying to get a solution, so bear with me.

I'm starting to think it's the Events added that cause the problem, that Trigger - Add to Rage Paths mana <gen> the event (Unit - (Trained unit)'s mana becomes Greater than or equal to 100.00) doesn't really reference to the unit trained, instead it says that

"Everytime a trained unit's mana becomes less than 100 do this", which would only happen once since a unit is only trained once.

Could you add a Game - Display text, with the name of the triggering unit to Rage Paths mana?
Then try it with four different units and see if your first unit that you trained shows up more than once.

Nope, the action which adds units to the 'Rage paths mana' as event 'unit's mana become ...' works fine. I'm also using a diffrent trigger where you choose faction path, and all your units turn into 'corrupted' form, which is the form that uses this mana system. The 'Rage paths mana' works for all those units, not just for one unit. But it works with flaws, as stated in post above, when unit's mana goes below 200 or 100 it detects it, and triggers, but the level of ability is not changed accordingly to the mana of unit.
 
Level 11
Joined
May 16, 2016
Messages
730
I'm trying to create a certain mechanic for group of units:
They generate mana when taking damage and dealing damage (Hidden searing arrow and mana shield), and have minus mana regeneartion, so over time their mana is decreasing.
You shouldn't suffer to make triggers like Unit training unit etc.
You need to add trigger with event: Every (0.01 - 1) sec. of game time
then set group = all units in playble map area
then pick every unit in group and then check every picked unit for mana. If mana is lower than certain value, then add armor bonus, else remove, etc.
 
Level 4
Joined
Feb 9, 2010
Messages
48
You shouldn't suffer to make triggers like Unit training unit etc.
You need to add trigger with event: Every (0.01 - 1) sec. of game time
then set group = all units in playble map area
then pick every unit in group and then check every picked unit for mana. If mana is lower than certain value, then add armor bonus, else remove, etc.

The other solution you proposed with a 'Every 0.5 second of the game' event is certainly not an option. This would cause way too many lags in the map. I'm trying to not implement any events that would be heavily affecting the map's stability, and when I want to use 'every X seconds' I make a dummy-timer unit and have a trigger detecting when it dies.

I do not want to add every X seconds. This trigger will be running like mad during the game. And as I stated, I'm creating a rather large map, where I want to minimize the lags to minimum, triggers with events that are triggered a lot are not an option.
 
Level 11
Joined
May 16, 2016
Messages
730
I do not want to add every X seconds. This trigger will be running like mad during the game. And as I stated, I'm creating a rather large map, where I want to minimize the lags to minimum, triggers with events that are triggered a lot are not an option.
This is the only way. but you may at least increase period time. at least 1 - 2 sec.
Can I see your trigger about dummy timer?
 
Level 4
Joined
Feb 9, 2010
Messages
48
This is the only way. but you may at least increase period time. at least 1 - 2 sec.
Can I see your trigger about dummy timer?

You sure that this is the only way? Have you tried everything else that you are so sure about it?

As for trigger, here's an example of every 20 seconds do something:
  • Overtimedecrease
    • Events
      • Unit - A unit owned by Neutral Passive Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Stag [Elemental Sacrifice]
    • Actions
      • Unit - Create 1 Stag [Elemental Sacrifice] for Neutral Passive at DummyHeaven facing Default building facing degrees
      • Unit - Add a 20.00 second Generic expiration timer to (Last created unit)
      • Set Earth = (Earth - 20)
      • Set Fire = (Fire - 20)
      • Set Storm = (Storm - 20)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Earth Less than 0
        • Then - Actions
          • Set Earth = 0
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Fire Less than 0
        • Then - Actions
          • Set Fire = 0
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Storm Less than 0
        • Then - Actions
          • Set Storm = 0
        • Else - Actions
      • Leaderboard - Change the title of ElementalLeaderboard to (|cff008000Earth|r/|cff0080c0Storm|r/|cffff3737Fire|r: + ((String(Earth)) + (/ + ((String(Storm)) + (/ + (String(Fire)))))))
 
Level 11
Joined
May 16, 2016
Messages
730
You sure that this is the only way? Have you tried everything else that you are so sure about it?

As for trigger, here's an example of every 20 seconds do something:
I hope you've cleaned leaks, because i don't see here any action which removes DummyHeaven location.
Also if your dummy units have locust ability, then pick every unit trigger would pick only units without locust ability.
Of course you may use Set group = all units in playble map area matching conditions Matching unit is alive equal yes etc, so your trigger would pick dead bodies which aren't important.
 
Level 4
Joined
Feb 9, 2010
Messages
48
I hope you've cleaned leaks, because i don't see here any action which removes DummyHeaven location.
Also if your dummy units have locust ability, then pick every unit trigger would pick only units without locust ability.
Of course you may use Set group = all units in playble map area matching conditions Matching unit is alive equal yes etc, so your trigger would pick dead bodies which aren't important.

Dummyheaven is a point variable that is defined at the start of the game and stays like that for the rest of the game. I believe there's no need to remove and add this location each time I'm using it in a trigger? Or am I wrong and it leaks?

I gotta ask this question again, have you tried doing this trigger with the events 'X unit's mana becomes ....' and you are 100% sure that it will not work? Because you dodged my previous question. I'd prefer to have this mechanic be done without the need of sacrifice dummies dying every second.
 
Level 11
Joined
May 16, 2016
Messages
730
Dummyheaven is a point variable that is defined at the start of the game and stays like that for the rest of the game. I believe there's no need to remove and add this location each time I'm using it in a trigger? Or am I wrong and it leaks?
No it doesn't leak then.
I gotta ask this question again, have you tried doing this trigger with the events 'X unit's mana becomes ....' and you are 100% sure that it will not work? Because you dodged my previous question. I'd prefer to have this mechanic be done without the need of sacrifice dummies dying every second.
If you want to avoid periodic, then...
First you need to fix your trigger:
If mana is less than 100 then do action else (if mana is greater or equal 100 and less than 200 then do action else [if mana is greater or equal 200 then do action else do nothing]) something like that.
 
Level 4
Joined
Feb 9, 2010
Messages
48
No it doesn't leak then.

If you want to avoid periodic, then...
First you need to fix your trigger:
If mana is less than 100 then do action else (if mana is greater or equal 100 and less than 200 then do action else [if mana is greater or equal 200 then do action else do nothing]) something like that.
It didn't change anything, however it made me think more about the events. Since the 200 to less and 100 to less wasn't working, I've added another event:
  • Rage On Train
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Owner of (Trained unit)) Equal to Player 7 (Green)
      • ((Trained unit) is An Ancient) Equal to True
    • Actions
      • Unit - Order (Trained unit) to Neutral Naga Sea Witch - Activate Mana Shield
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Unit-type of (Trained unit)) Equal to Dragonrider [Corrupted]
              • (Unit-type of (Trained unit)) Equal to Orc Crossbowman [Corrupted]
              • (Unit-type of (Trained unit)) Equal to Grunt [Corrupted]
              • (Unit-type of (Trained unit)) Equal to Wolfrider [Corrupted]
              • (Unit-type of (Trained unit)) Equal to Warchief [Corrupted]
              • (Unit-type of (Trained unit)) Equal to Ravager [Corrupted]
        • Then - Actions
          • Trigger - Add to Rage Paths mana <gen> the event (Unit - (Trained unit)'s mana becomes Greater than or equal to 100.00)
          • Trigger - Add to Rage Paths mana <gen> the event (Unit - (Trained unit)'s mana becomes Greater than or equal to 200.00)
          • Trigger - Add to Rage Paths mana <gen> the event (Unit - (Trained unit)'s mana becomes Less than or equal to 200.00)
          • Trigger - Add to Rage Paths mana <gen> the event (Unit - (Trained unit)'s mana becomes Less than or equal to 199.00)
          • Trigger - Add to Rage Paths mana <gen> the event (Unit - (Trained unit)'s mana becomes Less than or equal to 100.00)
          • Trigger - Add to Rage Paths mana <gen> the event (Unit - (Trained unit)'s mana becomes Less than or equal to 99.00)
        • Else - Actions
Adding 199 and 99 event fixed the problem. Although the trigger launches twices when unit reaches 100&above or 200&above it's still doing the right thing and setting the ability to correct level.

Thanks everyone involved for helping.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Good job on fixing it, but there is still one aspect that you didnt notice.
There is a difference between "becomes Greater than or equal to" and "becomes Greater than".
One that is not logically defined, but has certain effects on the expected results.

Try having the events use the versions without te equal to (in every case).
 
Level 4
Joined
Feb 9, 2010
Messages
48
Good job on fixing it, but there is still one aspect that you didnt notice.
There is a difference between "becomes Greater than or equal to" and "becomes Greater than".
One that is not logically defined, but has certain effects on the expected results.

Try having the events use the versions without te equal to (in every case).

Nope, this haven't changed anything except for the fact that now it doesn't trigger at 100/200 mana, but above/below that amount. With equal to, it ran at 200 and 100. It still runs the same amount of time as with the equal to.

So, does 'removing equal to' change anything? (Mean map stability, lags or sth like that, the mechanic still works more or less the same)
 
Level 39
Joined
Feb 27, 2007
Messages
5,030
I do not want to add every X seconds. This trigger will be running like mad during the game.
This is really not the case. Many low-timeout (0.02 to 0.5) timers can be run simultaneously without any effect on performance as long as you are doing it intelligently. For example, don't pick every unit in the map and filter/do something with them that often; use a group of the specific units you need and loop through those instead (like you've done). If you're scared of low-timeout periodic timers you're going to find that a lot of triggers are going to be very awkward or nigh impossible to make without them.

If you aren't cleaning your leaks properly then this can be magnified by a timer that runs 2-50 times a second, but in general just having some of these timers running is not going to lag the map. What you do every iteration is much more important.

You could probably be running 100+ timers every 0.5 seconds without a problem.
 
Status
Not open for further replies.
Top