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

[Solved] Hunger System

Status
Not open for further replies.
Level 3
Joined
Apr 20, 2021
Messages
19
So I've been trying to develop this sort of hunger system in which organic units will take 1 HP of damage every 1 second of game time for the longest time now. So far, this is the trigger that I have come up with:

1618908592651.png


This works fine apart from the fact that literally every single thing with a health bar has their health deplete. Could I have some advice on how to create a condition such that the game differentiates organic units from buildings/mechanical ones?
 
Last edited:
Level 21
Joined
Mar 29, 2020
Messages
1,237
you could deal with it the way you are doing (with the right condition) all in one trigger and delete the unit group you are creating each time (to avoid memory leaks), but that is kind of inefficient. there is no reason to keep creating and destroying unit groups every second. the following solution uses three triggers, but it is still pretty simple and I think it is a better way to do the same thing:

  • first units
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet organic_units = (Units in (Playable map area) matching (((Matching unit) is Mechanical) Equal to False))
  • added units
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • ((Triggering unit) is Mechanical) Equal to False
    • Actions
      • Unit Group - Add (Triggering unit) to organic_units
  • periodic damager
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in organic_units and do (Actions)
        • Loop - Actions
          • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) - 1.00)
(the first trigger deals with the preplaced units and the second trigger deals with the units that are built/created throughout the game )

good luck!
 
Level 3
Joined
Apr 20, 2021
Messages
19
you could deal with it the way you are doing (with the right condition) all in one trigger and delete the unit group you are creating each time (to avoid memory leaks), but that is kind of inefficient. there is no reason to keep creating and destroying unit groups every second. the following solution uses three triggers, but it is still pretty simple and I think it is a better way to do the same thing:

  • first units
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet organic_units = (Units in (Playable map area) matching (((Matching unit) is Mechanical) Equal to False))
  • added units
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • ((Triggering unit) is Mechanical) Equal to False
    • Actions
      • Unit Group - Add (Triggering unit) to organic_units
  • periodic damager
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in organic_units and do (Actions)
        • Loop - Actions
          • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) - 1.00)
(the first trigger deals with the preplaced units and the second trigger deals with the units that are built/created throughout the game )

good luck!
Holy crap. This is the first time I've actually asked for help and I can't believe I didn't think of this sooner. Thank you for the help! Truly appreciated.
 
Status
Not open for further replies.
Top