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

If anyone unit hits 0 mana

Status
Not open for further replies.
Level 1
Joined
Jan 23, 2015
Messages
160
Hey gang, got help to make a little movement = mana loss system and it is working good. Uh, I noticed no easy way to do a "generic unit event" that would detect when any unit is at 1/4 mana or 0 mana and then use a dummy to apply a negative effect.

Also using Bribe's Unit Indexer and Movement detection.

  • Mana Zero
    • Events
    • Conditions
    • Actions
      • -------- Loop Through registered Units --------
      • Unit Group - Pick every unit in ManaZero_Group and do (Actions)
        • Loop - Actions
          • Set ManaZero_Individual_Location = (Position of (Picked unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Integer((Mana of (Picked unit)))) Less than or equal to ((Integer((Max mana of (Picked unit)))) / 4)
              • ((Picked unit) has buff Cripple) Equal to False
            • Then - Actions
              • Unit - Create 1 Dummy for Player 9 (Gray) at ManaZero_Individual_Location facing Default building facing degrees
              • Unit - Order (Last created unit) to Undead Necromancer - Cripple (Picked unit)
              • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
            • Else - Actions
I have this fire whenever movement or stopping movement is detected using Bribe's system which is janky because the effect isn't applied mid-movement, only if they start a new direction or stop moving. How can I make it so any unit reaching a certain mana level will get this, even in mid movement? Thanks for your help
 
Level 39
Joined
Feb 27, 2007
Messages
4,992
Integer division in this case is unnecessary since mana is a real amount anyway.

As long as your map isn't about having a massive number of units on it at once then you can periodically loop through every unit on the map and check their mana. Maybe a 0.5 or 0.3 timeout timer.
 
Level 1
Joined
Jan 23, 2015
Messages
160
How much would you say is massive for unit count? I'm thinking maybe 200 to 250 units present on the map at most
 
Level 39
Joined
Feb 27, 2007
Messages
4,992
Honestly you'll have to see for yourself by trying.

For reference: an average melee unit uses 2-3 food and melee players have a 100 food cap, so 200-250 units is about a 4-6 player melee game with every player at full food capacity. Sounds like a lot to me but what do I know.
 
Level 1
Joined
Jan 23, 2015
Messages
160
  • Mana Quarter Penalty
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • -------- Loop Through registered Units --------
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Mana of (Picked unit)) Less than ((Max mana of (Picked unit)) / 4.00)
          • ((Picked unit) has buff Cripple) Equal to False
        • Then - Actions
          • Unit - Create 1 Dummy for Player 8 (Pink) at (Position of (Picked unit)) facing Default building facing degrees
          • Unit - Order (Last created unit) to Undead Necromancer - Cripple (Picked unit)
          • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
        • Else - Actions
Any ideas why this is not working at all?
 
Level 1
Joined
Jan 23, 2015
Messages
160
If block isn’t inside the loop section. You can drag it in there. You’re also leaking a unit group each time the trigger runs: Units in (Playable Map Area).

Damn that's embarrassing. Ok, moved to be inside the loop and it is working. About the leak, I don't know how to assign every unit to a variable like that. Any advice?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,510
Damn that's embarrassing. Ok, moved to be inside the loop and it is working. About the leak, I don't know how to assign every unit to a variable like that. Any advice?
Someone can correct me if i'm wrong, but I was told that this doesn't leak:
  • Untitled Trigger 001
    • Events
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup=true
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • -------- Do stuff --------
          • Custom script: call RemoveLocation (udg_ManaZero_Individual_Location)
Also, this:
  • Untitled Trigger 001
    • Events
    • Conditions
    • Actions
      • Set Spawn_UG = (Units in (Playable map area))
      • Unit Group - Pick every unit in Spawn_UG and do (Actions)
        • Loop - Actions
          • -------- Do stuff --------
          • Custom script: call RemoveLocation (udg_ManaZero_Individual_Location)
      • Custom script: call DestroyGroup(udg_Spawn_UG)
Also, you want to destroy your Point/UG when you're done with them/before you create them again. The trigger above shows you an example of destroying them. Also, instead of creating the dummy at the "position of unit", instead, set the position of the unit to a Point variable, then create the dummy at that Point variable, and then finally destroy it once you're done.

Another thing, you don't to have pick every unit in playable map area. Store the units that have this mana draining effect on them inside a UG, and then run a timer every 0.03 or 0.05 seconds that will check on them. So every 0.03 seconds, Pick every unit in Mana Drain UG and do "If picked unit's mana <= 25%" then "create a dummy, cast cripple, do whatever else you want". Then you can remove the unit from the UG so it doesn't repeatedly get crippled.
 
Last edited:
Level 39
Joined
Feb 27, 2007
Messages
4,992
Dead units can stay in the unit group forever (even after decay) and cause unnecessary operations (effectively performance loss). You will need to manually clear them from the group over time, or destroy the group, create a new one, and add units to it again.

The set bj_wantDestroy... method will immediately destroy the group so don’t use it if you don’t want that to happen.
 
Status
Not open for further replies.
Top