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

Allies share food

Status
Not open for further replies.
Level 7
Joined
Apr 17, 2017
Messages
316
There are 3 things that change the food amount. These are:
Training a unit
When a unit dies
And using some transformation spells like possession, charm or resurrection.

Dying part is easy. However Training detection will be a bit painful. The thing is we can detect the food cost when a unit finishes training a unit, but not when it begins. So I recommend you to use training detection system which can be found here if your map doesn't rely on heroes. Here is the link: TrainingDetection v3.1

We can only detect the food of trained unit with "A unit finishes training a unit" event. But we need detect it when a unit begins training a unit. Luckily, there is a way to do that, by using order id's. Every unittype has an integer as an id which can either be rawcode or just integer. We also use order ids to order a unit to do something or detect what he's doing. If you order a unit to use unittype-id of footman ('hfoo' in this case), it just trains that unit!. That way you can detect the food of that unit by using hashtables.

I am not sure if there is a better way to do it, but to me this gets the job done. You also need some kind of indexing to keep track of all units in the queue, this is not a mui solution so you need to make it mui.
 

Attachments

  • BindFood.w3x
    21.6 KB · Views: 35
Food is a resource of player, it is done more simple by using playerstate events with food cap and food used becoming equal to 0 and not equl to 0 so it will fire on any food change.
Inside such an event disable the current trigger (to prevent triggering it your self inside the syncing) and add the change to all allies.

could look like that.
  • Food changeMax
    • Events
    • Conditions
    • Actions
      • Trigger - Turn off (This trigger)
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked player) is an ally of (Triggering player)) Equal to True
            • Then - Actions
              • Player - Set (Picked player) Food cap to ((Triggering player) Food cap)
            • Else - Actions
      • Trigger - Turn on (This trigger)
  • Food change
    • Events
    • Conditions
    • Actions
      • Trigger - Turn off (This trigger)
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked player) is an ally of (Triggering player)) Equal to True
            • Then - Actions
              • Player - Set (Picked player) Food used to ((Triggering player) Food used)
            • Else - Actions
      • Trigger - Turn on (This trigger)
  • Food Sync Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Trigger - Add to Food change <gen> the event (Player - (Picked player)'s Food used becomes Not equal to 0.00)
          • Trigger - Add to Food change <gen> the event (Player - (Picked player)'s Food used becomes Equal to 0.00)
          • Trigger - Add to Food changeMax <gen> the event (Player - (Picked player)'s Food cap becomes Not equal to 0.00)
          • Trigger - Add to Food changeMax <gen> the event (Player - (Picked player)'s Food cap becomes Equal to 0.00)
If your map has units using/providing food and beeing created before setting up this trigger you have to sum the food cap/usage manualy, the events will fail you on this preplaced unis.
 
Level 2
Joined
Jun 3, 2018
Messages
17
Tasyen, those triggers don't seem to do anything, I copied them exactly and there's no preplaced units. I made a trigger create a worker after game time elapsed 1 second. Am I missing something?
 
Level 2
Joined
Jun 3, 2018
Messages
17
How would I destroy all players player group? Here's the triggers
 

Attachments

  • asdf.png
    asdf.png
    18.4 KB · Views: 48
  • wedf.png
    wedf.png
    20 KB · Views: 46
  • werw.png
    werw.png
    17.6 KB · Views: 51
Level 2
Joined
Jun 3, 2018
Messages
17
can not see a misstake, wierd it works for me.

Are your players allied and the slots of the players beeing used?
As I remember corretly all Players only contains used slots.
That would be the problem then. The slots are left open and shared control lets me see their food. Would testing it with computers in the slots work? If players leave will the trigger stop working? If I leave slots open/closed when hosting will the triggers not work?
 
yeah, bots are valid used slots. You can see their resources when selecting a building owned by that bot.

I think it will remaing to work even after a player has left game, but I did not test that.

If you want to be 100% safe you could swap the player group loop to an player(index) loop, That would also include not used slots.
Although for a team based game with fixed teams it would be even better to create a playergroup array and each team using the index beeing its team nr, which is provided by warcraft 3 (the team nr).
 
Last edited:
Status
Not open for further replies.
Top