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

Resource Upkeep

Status
Not open for further replies.
Level 13
Joined
Jul 2, 2015
Messages
872
For my "Tiriath Civil War" map I need upkeep system (if one dosent yet exist in vanilla) that slowly drains lumber (in my case Oil) based on how many armored vehicles are present (for example 3 tanks that all slowly drain 1 oil) Any help or advice on how to make this?
 
Level 39
Joined
Feb 27, 2007
Messages
4,992
What happens if the player doesn't have any lumber to pay the upkeep? Something like this rudimentary trigger should work.
  • -------- Events, every 1 second of game-time --------
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in (Playable Map Area) matching (Unit-type of (Matching Unit) equal to TANK) and do (Actions)
    • Loop - Actions
      • Player - Modify (Owner of (Picked Unit)) current lumber: subtract 1
The above trigger subracts 1 oil per tank per second, but if you change the number subtracted or the event repeat period you can change the amount of upkeep. This trigger is can also be slightly abused when run at slower frequencies by timing your lumber expenses to happen just before the upkeep lumber is subtracted. I wouldn't really worry about that since it's not a huge deal but if you find people abusing it there are ways to resolve it.
 
Level 13
Joined
Jul 2, 2015
Messages
872
What happens if the player doesn't have any lumber to pay the upkeep? Something like this rudimentary trigger should work.
  • -------- Events, every 1 second of game-time --------
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in (Playable Map Area) matching (Unit-type of (Matching Unit) equal to TANK) and do (Actions)a
    • Loop - Actions
      • Player - Modify (Owner of (Picked Unit)) current lumber: subtract 1
The above trigger subracts 1 oil per tank per second, but if you change the number subtracted or the event repeat period you can change the amount of upkeep. This trigger is can also be slightly abused when run at slower frequencies by timing your lumber expenses to happen just before the upkeep lumber is subtracted. I wouldn't really worry about that since it's not a huge deal but if you find people abusing it there are ways to resolve it.
Thanks, is there a way to add that when the oil runs out, the player cant construct more vehicles?
 
Level 39
Joined
Feb 27, 2007
Messages
4,992
First, make a new unit called "More Oil" and make sure every vehicle your players can build has the "More Oil" unit listed as a "techtree requirement". You'll make 1 of these units for all players in a hidden part of the map (the units should have no model, attack, etc. and either Ghost (visible) or Locust abilities) and change their owner to Neutral Passive at any time they shouldn't be able to build because they're out of oil, then change the owner back when they should. While NP owns the unit it doesn't work as a tech requirement so you can't build any oil-needing things.

Another sort of periodic trigger with a higher frequency (say, every 0.25 seconds) can run this.
  • -------- In a Map Init Trigger --------
  • Set OIL_POINT = Center of (Oil spot <gen>)
  • Player Group - Pick every player in (All Players) and do (Actions)
    • Loop - Actions
      • Set OIL_PLAYER = (Picked Player)
      • Set TempInt = (Player number of OIL_PLAYER)
      • Set HasOil[TempInt] = true
      • Unit - Create 1 OIL_DUMMY for (Picked Player) at OIL_POINT facing Default Building Facing degrees
      • Set OilUIUnit[TempInt] = (last created unit)
  • Custom script: call RemoveLocation(udg_OIL_POINT)
  • -------- Periodic Actions --------
  • Player Group - Pick every player in (All Players) and do (Actions)
    • Loop - Actions
      • Set OIL_PLAYER = (Picked Player)
      • Set TempInt = (Player number of OIL_PLAYER)
      • Set OIL_AMOUNT = (OIL_PLAYER current lumber)
      • If (All conditions are true) then do (Actions) else (actions)
        • If - Conditions
          • OIL_AMOUNT less than OIL_THRESH //maybe this is 1, idk
          • HasOil[TempInt] equal to true
        • Then - Actions
          • Set HasOil[TempInt] = false
          • Unit - Change owner of OilUIUnit[TempInt] to (Neutral Passive) without changing color
        • Else - Actions
          • If (All conditions are true) then do (Actions) else (actions)
            • If - Conditions
              • HasOil[TempInt] equal to false
              • ((Picked Player) current lumber) greater than LUMBER_THRESH //maybe this is 1, idk Then - Actions
              • Set HasOil[TempInt] = true
              • Unit - Change owner of OilUIUnit[TempInt] to OIL_PLAYER without changing color
 
Level 13
Joined
Jul 2, 2015
Messages
872
First, make a new unit called "More Oil" and make sure every vehicle your players can build has the "More Oil" unit listed as a "techtree requirement". You'll make 1 of these units for all players in a hidden part of the map (the units should have no model, attack, etc. and either Ghost (visible) or Locust abilities) and change their owner to Neutral Passive at any time they shouldn't be able to build because they're out of oil, then change the owner back when they should. While NP owns the unit it doesn't work as a tech requirement so you can't build any oil-needing things.

Another sort of periodic trigger with a higher frequency (say, every 0.25 seconds) can run this.
  • -------- In a Map Init Trigger --------
  • Set OIL_POINT = Center of (Oil spot <gen>)
  • Player Group - Pick every player in (All Players) and do (Actions)
    • Loop - Actions
      • Set OIL_PLAYER = (Picked Player)
      • Set TempInt = (Player number of OIL_PLAYER)
      • Set HasOil[TempInt] = true
      • Unit - Create 1 OIL_DUMMY for (Picked Player) at OIL_POINT facing Default Building Facing degrees
      • Set OilUIUnit[TempInt] = (last created unit)
  • Custom script: call RemoveLocation(udg_OIL_POINT)
  • -------- Periodic Actions --------
  • Player Group - Pick every player in (All Players) and do (Actions)
    • Loop - Actions
      • Set OIL_PLAYER = (Picked Player)
      • Set TempInt = (Player number of OIL_PLAYER)
      • Set OIL_AMOUNT = (OIL_PLAYER current lumber)
      • If (All conditions are true) then do (Actions) else (actions)
        • If - Conditions
          • OIL_AMOUNT less than OIL_THRESH //maybe this is 1, idk
          • HasOil[TempInt] equal to true
        • Then - Actions
          • Set HasOil[TempInt] = false
          • Unit - Change owner of OilUIUnit[TempInt] to (Neutral Passive) without changing color
        • Else - Actions
          • If (All conditions are true) then do (Actions) else (actions)
            • If - Conditions
              • HasOil[TempInt] equal to false
              • ((Picked Player) current lumber) greater than LUMBER_THRESH //maybe this is 1, idk Then - Actions
              • Set HasOil[TempInt] = true
              • Unit - Change owner of OilUIUnit[TempInt] to OIL_PLAYER without changing color
Ok, I'll try to use this when I get back, thanks!
 
Level 13
Joined
Jul 2, 2015
Messages
872
First, make a new unit called "More Oil" and make sure every vehicle your players can build has the "More Oil" unit listed as a "techtree requirement". You'll make 1 of these units for all players in a hidden part of the map (the units should have no model, attack, etc. and either Ghost (visible) or Locust abilities) and change their owner to Neutral Passive at any time they shouldn't be able to build because they're out of oil, then change the owner back when they should. While NP owns the unit it doesn't work as a tech requirement so you can't build any oil-needing things.

Another sort of periodic trigger with a higher frequency (say, every 0.25 seconds) can run this.
  • -------- In a Map Init Trigger --------
  • Set OIL_POINT = Center of (Oil spot <gen>)
  • Player Group - Pick every player in (All Players) and do (Actions)
    • Loop - Actions
      • Set OIL_PLAYER = (Picked Player)
      • Set TempInt = (Player number of OIL_PLAYER)
      • Set HasOil[TempInt] = true
      • Unit - Create 1 OIL_DUMMY for (Picked Player) at OIL_POINT facing Default Building Facing degrees
      • Set OilUIUnit[TempInt] = (last created unit)
  • Custom script: call RemoveLocation(udg_OIL_POINT)
  • -------- Periodic Actions --------
  • Player Group - Pick every player in (All Players) and do (Actions)
    • Loop - Actions
      • Set OIL_PLAYER = (Picked Player)
      • Set TempInt = (Player number of OIL_PLAYER)
      • Set OIL_AMOUNT = (OIL_PLAYER current lumber)
      • If (All conditions are true) then do (Actions) else (actions)
        • If - Conditions
          • OIL_AMOUNT less than OIL_THRESH //maybe this is 1, idk
          • HasOil[TempInt] equal to true
        • Then - Actions
          • Set HasOil[TempInt] = false
          • Unit - Change owner of OilUIUnit[TempInt] to (Neutral Passive) without changing color
        • Else - Actions
          • If (All conditions are true) then do (Actions) else (actions)
            • If - Conditions
              • HasOil[TempInt] equal to false
              • ((Picked Player) current lumber) greater than LUMBER_THRESH //maybe this is 1, idk Then - Actions
              • Set HasOil[TempInt] = true
              • Unit - Change owner of OilUIUnit[TempInt] to OIL_PLAYER without changing color
Can you send a map file with this as an example? I don't really get what you mean... xd
 
Level 39
Joined
Feb 27, 2007
Messages
4,992
The trigger you see in this map is literally the same as what I typed out.... It's all in the "oil" trigger. Type greedisgood to give yourself lumber and once you hit 10 lumber or less you can no longer build peasants at the farms I preplaced. It will be greyed out and require more oil.
 

Attachments

  • Gah.w3x
    148.3 KB · Views: 29
Level 13
Joined
Jul 2, 2015
Messages
872
The trigger you see in this map is literally the same as what I typed out.... It's all in the "oil" trigger. Type greedisgood to give yourself lumber and once you hit 10 lumber or less you can no longer build peasants at the farms I preplaced. It will be greyed out and require more oil.
Thanks, but why doesn't the Oil start draining when I have peasants?

Also do you know what I could do to make it that Vehicles cant move when lumber/oil has ran out?
 
Level 39
Joined
Feb 27, 2007
Messages
4,992
Thanks, but why doesn't the Oil start draining when I have peasants?
Because I didn't program it to do that, and if you'd looked at the triggers you'd have seen that. I'm not making a system for your map for you dude, I'm helping you get over these speedbumps by throwing code at you that you can implement yourself. 3 of my posts ago in this thread I wrote exactly how to subtract oil for each unit each player has. All you need to change is the "matching" condition to check against Anicents as I've done below, instead of checking its unit type. "Give a man a fish and he's full for a day, teach a man to fish and he is full for a lifetime." I'm teaching you to fish here, bud. If you run into problems add some "Game - Display <message>" commands to help debug what's happening.

You can temporarily disable movement (but still allow attacking and spellcasting) by using the new Blizzard function "Unit - For <unit>, <ability>, Disable ability: True, Hide UI: False" on the "Move" ability. Its rawcode is 'Amov', but GUI doesn't allow you to disable Move, Patrol, Stop, etc. even though you can do it with the JASS Natives, so instead you'll have to save 'Amov' into an ability variable and then use that variable in disable action. When you want a unit to be able to move again, just do the same call but with "Disable ability: False". You will also need a few unit groups to store all the 'vehicles' on your map and you need to pick a unit classification to use for "vehicles" in your. I suggest using Ancient since GUI can let you use that in conditions and as far as I know it only affects wisp building (which you can change). Other option would be Sapper or Tauren, but I don't think GUI can 'see' those.

You need 2 new variables: OIL_MOVEABIL (ability), OIL_DISABLEGROUP (group array, size 29 (this initializes the groups so you don't get crashes)).
  • Events
    • Unit - A unit enters (playable map area)
  • Conditions
    • ((Triggering Unit) is an Ancient) equal to true
  • Actions
    • Set TempUnit = (Triggering Unit)
    • Set OIL_PLAYER = Owner of TempUnit
    • Set TempInt = Player Number of (OIL_PLAYER)
    • If (All conditions are true) then do (Then actions) else do (Else actions)
      • If - Conditions
        • OIL_HAS[TempInt] equal to false
      • Then - Actions
        • Unit - For TempUnit, OIL_MOVEABIL, Disable ability: True, Hide UI: False
        • Unit - Add TempUnit to OIL_DISABLEGROUP[TempInt]
      • Else - Actions
  • -------- also need a death trigger --------
  • Events
    • Unit - A unit dies
  • Conditions
    • ((Triggering Unit) is an Ancient) equal to true
  • Actions
    • Set TempUnit = (Triggering Unit)
    • Set OIL_PLAYER = Owner of TempUnit
    • Set TempInt = Player Number of (OIL_PLAYER)
    • If (All conditions are true) then do (Then actions) else do (Else actions)
      • If - Conditions
        • (TempUnit is in OIL_DISABLEGROUP[TempInt]) equal to true
      • Then - Actions
        • Unit - For TempUnit, OIL_MOVEABIL, Disable ability: false, Hide UI: False
        • Unit - Remove TempUnit from OIL_DISABLEGROUP[TempInt]
      • Else - Actions
  • -------- Need this to be done on map init --------
  • Custom script: set udg_OIL_MOVEABIL = 'Amov' //change the variable name if you don't call it OIL_MOVEABIL like I did
  • -------- Then the periodic trigger again with bits that disable movement --------
  • Player Group - Pick every player in (All players) and do (Actions)
    • Loop - Actions
      • Set OIL_PLAYER = (Picked player)
      • Set TempInt = (Player number of OIL_PLAYER)
      • Set OIL_AMOUNT = (OIL_PLAYER Current lumber)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • OIL_HAS[TempInt] Equal to True
          • OIL_AMOUNT Less than OIL_THRESHOLD
        • Then - Actions
          • Set OIL_HAS[TempInt] = False
          • Unit - Change ownership of OIL_UIUNIT[TempInt] to Neutral Passive and Change color
          • Custom script: set bj_wantDestroyGroup = true //this auto-cleans a group leak in the line below this
          • Unit Group - Pick every unit in (Units Owned by OIL_PLAYER matching (((Matching unit is an Ancient) equal to true)) and ((Matching unit is in group OIL_DISABLEGROUP[TempInt]) equal to false)) and do (Actions)
            • Loop - Actions
              • Unit - For (Picked unit), Ability OIL_MOVEABIL, Disable ability: True, Hide UI: False
              • Unit - Add (Picked unit) to OIL_DISABLEGROUP[TempInt]
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • OIL_HAS[TempInt] Equal to False
              • OIL_AMOUNT Greater than or equal to OIL_THRESHOLD
            • Then - Actions
              • Set OIL_HAS[TempInt] = True
              • Unit - Change ownership of OIL_UIUNIT[TempInt] to OIL_PLAYER and Change color
              • -------- no bj_wantDestroyGroup set here because we don't want to destroy OIL_DISABLEGROUP --------
              • Unit Group - Pick every unit in (OIL_DISABLEGROUP[TempInt]) and do (Actions)
                • Loop - Actions
                  • Unit - For (Picked unit), Ability OIL_MOVEABIL, Disable ability: false, Hide UI: False
              • Unit Group - Clear OIL_DISABLEGROUP[TempInt]
            • Else - Actions
 
Last edited:
Status
Not open for further replies.
Top