• 🏆 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] Add Passive Ability to Random units of Player...

Status
Not open for further replies.
Level 4
Joined
Aug 16, 2013
Messages
75
Owning 1 unit = 1 Food Used (from your third resource next to your lumber). Maximum limit is 100.

Item called "Food" has charges and the maximum charges it can have is 1000.

You lose charges of your item "Food" by the Food Used amount every 60 seconds. (So if you have 30 Food Used, you lose 30 charges of your item called "Food" every 60 seconds).


What I want this trigger to do, is reduce the Food charges amount by the Food Used and add/remove the Starvation ability according to how much Food charges you have to feed your units.

So if you have 20 Food Charges and have 30 Food Used, then 10 random units of yours should get the starvation ability. If you have 10 units who already have the ability and this trigger occurs again, then those 10 units should still have the ability as well as 20 more randomly selected units of yours to gain the ability since you have 0 Food Charges now. (Which means all your units have the starvation ability now, 30 Food Used = you have 30 units).

However

If you have 40 Food Charges and have 30 Food Used with 5 of your units already having the Starvation ability, then you will be down to 10 Food Charges with those 5 units not having the ability anymore.

If you have 28 Food Charges and have 30 Food Used with 5 of your units having Starvation already, then 3 out of the 5 units with Starvation will be randomly selected to have their Starvation ability removed.



I am really struggling trying to achieve ^ the above. This is pretty difficult I feel. I spent a few hours trying to make this work.





  • Every 60 seconds
    • Events
      • Time - Every 60.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units of type Resource Supply Center) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Owner of (Picked unit)) Food used) Less than or equal to (Charges remaining in (Item carried by Resource_Center[(Player number of (Owner of (Picked unit)))] of type Food))
            • Then - Actions
              • Unit Group - Pick every unit in (Random Starved_Unit[(Player number of (Owner of (Picked unit)))] units from (Units owned by (Owner of (Picked unit)) matching ((((Matching unit) is A structure) Equal to False) and (((Unit-type of (Matching unit)) Not equal to King) and ((Level of Starvation and do (Actions)
                • Loop - Actions
                  • Unit - Remove Starvation from (Picked unit)
                  • Set Starved_Unit[(Player number of (Owner of (Picked unit)))] = (Starved_Unit[(Player number of (Owner of (Picked unit)))] - 1)
                  • Game - Display to (All players) the text: Starvation Removed.
              • Game - Display to (All players) the text: Reduce charges.
              • Item - Set charges remaining in (Item carried by Resource_Center[(Player number of (Owner of (Picked unit)))] of type Food) to ((Charges remaining in (Item carried by Resource_Center[(Player number of (Owner of (Picked unit)))] of type Food)) - ((Owner of (Picked unit)) Food used))
            • Else - Actions
              • Unit Group - Pick every unit in (Random ((Charges remaining in (Item carried by Resource_Center[(Player number of (Owner of (Picked unit)))] of type Food)) - ((Owner of (Picked unit)) Food used)) units from (Units owned by (Owner of (Picked unit)) matching (((Unit-type of (Matching unit)) N and do (Actions)
                • Loop - Actions
                  • Set Starved_Unit[(Player number of (Owner of (Picked unit)))] = (Starved_Unit[(Player number of (Owner of (Picked unit)))] + 1)
                  • Unit - Add Starvation to (Picked unit)
                  • Game - Display to (All players) the text: Starvation Added
              • Game - Display to (All players) the text: Charges reduced to ...
              • Item - Set charges remaining in (Item carried by Resource_Center[(Player number of (Owner of (Picked unit)))] of type Food) to 0
 
Last edited:
Since you're running on just one timer, you would enumerate all the units (that are units) belonging to a certain player. If the unit has the starvation ability, and the food is greater than 0, then you deduct the amount of food by 1 and remove the ability from the unit. If the unit does not have the starvation ability, check if the food is greater than 0. If it is, just deduct the amount of food by 1; otherwise, add the starvation ability.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
You need 2 separate per player unit groups...
Hungry_Units
Starving_Units
Add all units that consume food to Hungry_Units. When there is not enough food then you add the missing food to the number of units in Starving_Units. If this value is negative then pick the negative of the value worth of random units from Hungry_Units, give them starvation debuff and add them to Starving_Units. If the value is positive then you pick the value worth of random units from Starving_Units, remove the starvation debuff and then then remove them from Starving_Units group. If there is enough food then pick all units in Starving_Units, remove the starvation debuff and after processing all the units clear the Starving_Units group.
 
Status
Not open for further replies.
Top