• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

[GUI] Custom Resource Harvest System 1.05

Custom Resource Harvest System

Description
Oil harvesting like in Warcraft 2. Oil Tankers go to Oil Platforms, extract oil, and return it to the closest Oil Refinery.
  • Configure multiple tanker, refinery and platform types.
  • Tankers automatically find the nearest platform/refinery after returning/harvesting.
  • Smart targeting - you can right-click a platform to harvest. Also works for newly trained units to mine from their rally point.
  • Can easily be configured to represent a resource other than oil.
  • Includes Oil Display System (not required) - to display oil resource for all players (multiple resources types coming soon)
  • Includes Oil Usage System (not required) - to manage using oil resource for training units (structures, items and purchased units functionality coming soon)
  • Coming soon: ability to define any number of resource types.

The oil resource is tracked per player by the OHS_OilResource[] integer variable.

Installation
Pre-requisite: Bribe's Unit Indexer (included)

1. Copy the Oil Harvest System trigger categories into your map.
2. Make the necessary units and abilities in the object editor.
Abilities:
Harvest Oil - Ability that can target your oil platform.
Return Oil - Ability that can target your oil refinery.
Units:
Oil Tanker - Unit that will harvest the oil. Give your Harvest Oil ability to this unit.
Oil Refinery - Unit that will act as the drop-off point for tankers.
Oil Platform - Unit that will be the oil deposit.
3. Set these units in the variables in the OHS Config Trigger.

Triggers

  • OHS Config
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set OHS_CheckHashtable = (Last created hashtable)
      • -------- ----- --------
      • -------- Set the Harvest and Return abilities. --------
      • -------- ----- --------
      • Set OHS_HarvestAbility = Harvest Oil
      • Set OHS_ReturnAbility = Return Oil
      • -------- ----- --------
      • Set OHS_OilHarvestAmount = 10
      • Set OHS_FloatingTextColour = |cff404080
      • -------- ----- --------
      • -------- Set the unit types the system will use --------
      • -------- ----- --------
      • Set OHS_SaveUnitType = Oil Tanker
      • Set OHS_SaveResourceType = oil
      • Set OHS_SaveFunctionType = worker
      • Trigger - Run OHS Save Type <gen> (ignoring conditions)
      • -------- ----- --------
      • Set OHS_SaveUnitType = Oil Refinery
      • Set OHS_SaveResourceType = oil
      • Set OHS_SaveFunctionType = base
      • Trigger - Run OHS Save Type <gen> (ignoring conditions)
      • -------- ----- --------
      • Set OHS_SaveUnitType = Oil Platform
      • Set OHS_SaveResourceType = oil
      • Set OHS_SaveFunctionType = mine
      • Set OHS_SaveOilRemaining = 5000
      • Trigger - Run OHS Save Type <gen> (ignoring conditions)
      • -------- ----- --------
      • -------- ----- --------
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • Set tempUnit = (Picked unit)
          • Trigger - Run OHS Check Group Register <gen> (ignoring conditions)
  • OHS Save Type
    • Events
    • Conditions
    • Actions
      • Custom script: set udg_tempInt = udg_OHS_SaveUnitType
      • Hashtable - Save OHS_SaveFunctionType as 0 of tempInt in OHS_CheckHashtable
      • Hashtable - Save OHS_SaveResourceType as 1 of tempInt in OHS_CheckHashtable
      • Hashtable - Save OHS_SaveOilRemaining as 3 of tempInt in OHS_CheckHashtable
  • OHS Smart
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • (Issued order) Equal to (Order(smart))
    • Actions
      • Set tempUnitTrigger = (Triggering unit)
      • Set tempUnitTarget = (Target unit of issued order)
      • -------- Check if ordered unit is a harvester --------
      • Set OHS_LoadUnitType = (Unit-type of tempUnitTrigger)
      • Custom script: set udg_tempInt = udg_OHS_LoadUnitType
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Load 0 of tempInt from OHS_CheckHashtable) Equal to worker
        • Then - Actions
          • -------- Check if target unit is a base or mine --------
          • Set OHS_LoadUnitType = (Unit-type of tempUnitTarget)
          • Custom script: set udg_tempInt = udg_OHS_LoadUnitType
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • (Load 0 of tempInt from OHS_CheckHashtable) Equal to base
                  • (Load 0 of tempInt from OHS_CheckHashtable) Equal to mine
            • Then - Actions
              • Unit - Order tempUnitTrigger to Neutral Dark Ranger - Charm tempUnitTarget
            • Else - Actions
        • Else - Actions
  • OHS Trained Smart
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
    • Actions
      • Set tempUnit = (Trained unit)
      • Set tempUnitTrigger = (Triggering unit)
      • Set tempUnitTarget = (Rally-Point of tempUnitTrigger as a unit)
      • Set OHS_LoadUnitType = (Unit-type of tempUnit)
      • Custom script: set udg_tempInt = udg_OHS_LoadUnitType
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Load 0 of tempInt from OHS_CheckHashtable) Equal to worker
        • Then - Actions
          • Set OHS_LoadUnitType = (Unit-type of tempUnitTarget)
          • Custom script: set udg_tempInt = udg_OHS_LoadUnitType
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Load 0 of tempInt from OHS_CheckHashtable) Equal to mine
            • Then - Actions
              • Unit - Order tempUnit to Right-Click tempUnitTarget
            • Else - Actions
        • Else - Actions
  • OHS Register New Units
    • Events
      • Game - UnitIndexEvent becomes Equal to 1.00
    • Conditions
    • Actions
      • Set tempUnit = UDexUnits[UDex]
      • Trigger - Run OHS Check Group Register <gen> (ignoring conditions)
  • OHS Check Group Register
    • Events
    • Conditions
    • Actions
      • Set tempId = (Custom value of tempUnit)
      • Set OHS_LoadUnitType = (Unit-type of tempUnit)
      • Custom script: set udg_tempInt = udg_OHS_LoadUnitType
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Load 0 of tempInt from OHS_CheckHashtable) Equal to base
              • (Load 0 of tempInt from OHS_CheckHashtable) Equal to mine
        • Then - Actions
          • Unit Group - Add tempUnit to OHS_CheckUnitGroup
          • -------- Set starting resource for mines --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Load 0 of tempInt from OHS_CheckHashtable) Equal to mine
            • Then - Actions
              • Set OHS_OilRemaining[tempId] = (Load 3 of tempInt from OHS_CheckHashtable)
            • Else - Actions
        • Else - Actions
  • OHS Remove Check Group
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is in OHS_CheckUnitGroup) Equal to True
    • Actions
      • Unit Group - Remove (Triggering unit) from OHS_CheckUnitGroup
  • OHS Harvest
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to OHS_HarvestAbility
    • Actions
      • Set tempUnitTrigger = (Triggering unit)
      • Set tempUnitTarget = (Target unit of ability being cast)
      • Set tempPlayer = (Owner of tempUnitTrigger)
      • -------- ------ --------
      • Set OHS_LoadUnitType = (Unit-type of tempUnitTrigger)
      • Custom script: set udg_tempInt = udg_OHS_LoadUnitType
      • -------- Save the worker's resource type --------
      • Set OHS_CheckResourceType = (Load 1 of tempInt from OHS_CheckHashtable)
      • -------- Compare with the target's resource type --------
      • Set OHS_LoadUnitType = (Unit-type of tempUnitTarget)
      • Custom script: set udg_tempInt = udg_OHS_LoadUnitType
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Load 1 of tempInt from OHS_CheckHashtable) Equal to OHS_CheckResourceType
        • Then - Actions
          • -------- Remove resource from mine --------
          • Set tempId = (Custom value of tempUnitTarget)
          • Set OHS_OilRemaining[tempId] = (OHS_OilRemaining[tempId] - OHS_OilHarvestAmount)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • OHS_OilRemaining[tempId] Less than or equal to 0
            • Then - Actions
              • Unit - Kill tempUnitTarget
            • Else - Actions
          • -------- Show remaining oil --------
          • Set tempForce = (Player group((Owner of tempUnitTrigger)))
          • Floating Text - Create floating text that reads (OHS_FloatingTextColour + ((String(OHS_OilRemaining[tempId])) + |r)) above tempUnitTarget
  • with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
    • Floating Text - Hide (Last created floating text) for (All players)
    • Floating Text - Show (Last created floating text) for tempForce
    • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
    • Floating Text - Change (Last created floating text): Disable permanence
    • Floating Text - Change the lifespan of (Last created floating text) to 5.00 seconds
    • Floating Text - Change the fading age of (Last created floating text) to 4.00 seconds
    • Custom script: call DestroyForce(udg_tempForce)
    • -------- Switch harvest/return abilities --------
    • Unit - Remove OHS_HarvestAbility from tempUnitTrigger
    • Unit - Add OHS_ReturnAbility to tempUnitTrigger
    • -------- Now search for base --------
    • Set OHS_SearchResourceType = OHS_CheckResourceType
    • Set OHS_SearchFunctionType = base
    • -------- Find nearest base --------
    • Set tempUnitPicked = No unit
    • Trigger - Run OHS Search <gen> (ignoring conditions)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • tempUnitPicked Not equal to No unit
      • Then - Actions
        • Unit - Order tempUnitTrigger to Neutral Dark Ranger - Charm tempUnitPicked
      • Else - Actions
    • Else - Actions
  • OHS Return
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to OHS_ReturnAbility
    • Actions
      • Set tempUnitTrigger = (Triggering unit)
      • Set tempUnitTarget = (Target unit of ability being cast)
      • Set tempPlayer = (Owner of tempUnitTarget)
      • -------- Determine what resource type the worker is carrying for the next check --------
      • Set OHS_LoadUnitType = (Unit-type of tempUnitTrigger)
      • Custom script: set udg_tempInt = udg_OHS_LoadUnitType
      • Set OHS_CheckResourceType = (Load 1 of tempInt from OHS_CheckHashtable)
      • -------- Check if the base matches the resource being returned by the worker --------
      • Set OHS_LoadUnitType = (Unit-type of tempUnitTarget)
      • Custom script: set udg_tempInt = udg_OHS_LoadUnitType
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • (Load 1 of tempInt from OHS_CheckHashtable) Equal to OHS_CheckResourceType
              • (Load 0 of tempInt from OHS_CheckHashtable) Equal to base
        • Then - Actions
          • -------- Add resources --------
          • Set OHS_OilResource[tempId] = (OHS_OilResource[tempId] + OHS_OilHarvestAmount)
          • Set tempForce = (Player group((Owner of tempUnitTrigger)))
          • Floating Text - Create floating text that reads ((OHS_FloatingTextColour + +) + ((String(OHS_OilHarvestAmount)) + oil|r)) above
  • tempUnitTrigger with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
    • Floating Text - Hide (Last created floating text) for (All players)
    • Floating Text - Show (Last created floating text) for tempForce
    • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
    • Floating Text - Change (Last created floating text): Disable permanence
    • Floating Text - Change the lifespan of (Last created floating text) to 5.00 seconds
    • Floating Text - Change the fading age of (Last created floating text) to 4.00 seconds
    • Custom script: call DestroyForce(udg_tempForce)
    • -------- ------- --------
    • Set OHS_SearchResourceType = OHS_CheckResourceType
    • Set OHS_SearchFunctionType = mine
    • -------- Find nearest mine --------
    • Trigger - Run OHS Search <gen> (ignoring conditions)
    • Unit - Remove OHS_ReturnAbility from tempUnitTrigger
    • Unit - Add OHS_HarvestAbility to tempUnitTrigger
    • Unit - Order tempUnitTrigger to Neutral Dark Ranger - Charm tempUnitPicked
    • Unit Group - Remove all units from tempGroup
    • Else - Actions
  • OHS Search
    • Events
    • Conditions
    • Actions
      • Set tempGroup = (Units owned by tempPlayer matching (((Matching unit) is in OHS_CheckUnitGroup) Equal to True))
      • Set tempLoc = (Position of tempUnitTrigger)
      • Set tempDistance = 90000.00
      • Set tempUnitPicked = No unit
      • Unit Group - Pick every unit in tempGroup and do (Actions)
        • Loop - Actions
          • Set OHS_LoadUnitType = (Unit-type of (Picked unit))
          • Custom script: set udg_tempInt = udg_OHS_LoadUnitType
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Load 0 of tempInt from OHS_CheckHashtable) Equal to OHS_SearchFunctionType
                  • (Load 1 of tempInt from OHS_CheckHashtable) Equal to OHS_SearchResourceType
            • Then - Actions
              • Set tempLoc2 = (Position of (Picked unit))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between tempLoc and tempLoc2) Less than or equal to tempDistance
                • Then - Actions
                  • Set tempDistance = (Distance between tempLoc and tempLoc2)
                  • Set tempUnitPicked = (Picked unit)
                • Else - Actions
              • Custom script: call RemoveLocation(udg_tempLoc2)
            • Else - Actions
      • Custom script: call RemoveLocation(udg_tempLoc)


  • OHS Display Config
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Set Oil icon for multiboard --------
      • Set OHS_DisplayOilIcon = ReplaceableTextures\CommandButtons\BTNPotionOfDivinity.blp
      • -------- ------- --------
      • Wait 0.25 seconds
      • -------- Create board for every player. --------
      • -------- If you want to create for only one player, set tempId = that player's player number and run OHS Display Create Board --------
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Set tempId = (Player number of (Picked player))
          • Trigger - Run OHS Create Board <gen> (ignoring conditions)
  • OHS Create Board
    • Events
    • Conditions
    • Actions
      • Player Group - Add (Player(tempId)) to OHS_PlayersUsingDisplaySystem
      • Multiboard - Create a multiboard with 1 columns and 1 rows, titled Resources
      • Set OHS_Multiboard[tempId] = (Last created multiboard)
      • Multiboard - Set the icon for OHS_Multiboard[tempId] item in column 1, row 1 to OHS_DisplayOilIcon
      • Multiboard - Set the width for OHS_Multiboard[tempId] item in column 1, row 1 to 6.00% of the total screen width
      • Multiboard - Set the text for OHS_Multiboard[tempId] item in column 1, row 1 to 0
      • Multiboard - Hide OHS_Multiboard[tempId]
      • Multiboard - Show OHS_Multiboard[tempId]
  • Events
    • Time - Every 0.10 seconds of game time


  • OHS Usage Config
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set OHS_UsageHashtable = (Last created hashtable)
      • -------- ----- --------
      • -------- Set costs of unit types --------
      • -------- saveOilCost - the amount of oil the chosen unit type should cost --------
      • -------- To add more unit types, copy the following 4 lines, and change the OHS_SaveUnitType and OHS_SaveOilCost variables for the new unit --------
      • -------- ----- --------
      • Set OHS_SaveUnitType = Oil Tanker
      • Set OHS_SaveOilCost = 50
      • Custom script: set udg_tempInt = udg_OHS_SaveUnitType
      • Hashtable - Save OHS_SaveOilCost as 0 of tempInt in OHS_UsageHashtable
      • -------- ----- --------
  • OHS Unit Train
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
    • Actions
      • -------- Load values for the trained unit --------
      • Set tempUnit = (Triggering unit)
      • Set tempPlayer = (Owner of tempUnit)
      • Set OHS_LoadUnitType = (Unit-type((String((Issued order)))))
      • Custom script: set udg_tempInt = udg_OHS_LoadUnitType
      • Set OHS_LoadOilCost = (Load 0 of tempInt from OHS_UsageHashtable)
      • -------- Check if the trained unit uses oil --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • OHS_LoadOilCost Greater than 0
        • Then - Actions
          • Set tempId = (Player number of tempPlayer)
          • -------- Check if player has enough oil --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • OHS_OilResource[tempId] Greater than or equal to OHS_LoadOilCost
            • Then - Actions
              • -------- Player has enough oil; subtract the cost from them --------
              • Set OHS_OilResource[tempId] = (OHS_OilResource[tempId] - OHS_LoadOilCost)
            • Else - Actions
              • -------- Player doesn't have enough oil, cancel training and display an error message --------
              • Unit Group - Add tempUnit to OHS_CancelTrainingGroup
              • Set tempForce = (Player group(tempPlayer))
              • Game - Display to tempForce the text: |cffff0000Error|r -...
              • Custom script: call DestroyForce(udg_tempForce)
              • Set tempId = (Custom value of tempUnit)
              • Set OHS_CancelTrainingStack[tempId] = (OHS_CancelTrainingStack[tempId] + 1)
        • Else - Actions
  • OHS Cancel Training
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in OHS_CancelTrainingGroup and do (Actions)
        • Loop - Actions
          • Set tempId = (Custom value of (Picked unit))
          • Trigger - Turn off OHS Refund <gen>
          • Custom script: call IssueImmediateOrderById( GetEnumUnit(), 851976 )
          • Trigger - Turn on OHS Refund <gen>
          • Set OHS_CancelTrainingStack[tempId] = (OHS_CancelTrainingStack[tempId] - 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • OHS_CancelTrainingStack[tempId] Equal to 0
            • Then - Actions
              • Unit Group - Remove (Picked unit) from OHS_CancelTrainingGroup
            • Else - Actions
  • OHS Refund
    • Events
      • Unit - A unit Cancels training a unit
    • Conditions
    • Actions
      • -------- Load values for the cancelled --------
      • Set tempPlayer = (Owner of tempUnit)
      • Set OHS_LoadUnitType = (Trained unit-type)
      • Custom script: set udg_tempInt = udg_OHS_LoadUnitType
      • Set OHS_LoadOilCost = (Load 0 of tempInt from OHS_UsageHashtable)
      • -------- Check if the trained unit uses oil --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • OHS_LoadOilCost Greater than 0
        • Then - Actions
          • Set tempId = (Player number of tempPlayer)
          • -------- Check if training isn't being cancelled by triggers --------
          • -------- Refund the player --------
          • Set OHS_OilResource[tempId] = (OHS_OilResource[tempId] + OHS_LoadOilCost)
        • Else - Actions
  • OHS Start Building
    • Events
      • Unit - A unit Begins construction
    • Conditions
    • Actions
      • -------- Load values for the building --------
      • Set tempUnit = (Constructing structure)
      • Set tempPlayer = (Owner of tempUnit)
      • Set OHS_LoadUnitType = (Unit-type of (Constructing structure))
      • Custom script: set udg_tempInt = udg_OHS_LoadUnitType
      • Set OHS_LoadOilCost = (Load 0 of tempInt from OHS_UsageHashtable)
      • -------- Check if the trained unit uses oil --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • OHS_LoadOilCost Greater than 0
        • Then - Actions
          • Set tempId = (Player number of tempPlayer)
          • -------- Check if player has enough oil --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • OHS_OilResource[tempId] Greater than or equal to OHS_LoadOilCost
            • Then - Actions
              • -------- Player has enough oil; subtract the cost from them --------
              • Set OHS_OilResource[tempId] = (OHS_OilResource[tempId] - OHS_LoadOilCost)
            • Else - Actions
              • -------- Player doesn't have enough oil, cancel training and display an error message --------
              • Set tempForce = (Player group(tempPlayer))
              • Game - Display to tempForce the text: |cffff0000Error|r -...
              • Custom script: call DestroyForce(udg_tempForce)
              • Unit - Remove tempUnit from the game
              • -------- Refund --------
              • Player - Add (Load 1 of tempInt from OHS_UsageHashtable) to tempPlayer Current gold
              • Player - Add (Load 2 of tempInt from OHS_UsageHashtable) to tempPlayer Current lumber
        • Else - Actions


Credits
Laercio - Inspiration
Bribe - Unit Indexer.

Changelog
1.04
  • Fixed bases being destroyed when targeted by empty workers
  • Added refunds for cancelled units
  • Changed training cancellation to use a loop and a stack instead of "Begins training" event
1.05
  • Now also works for buildings.

Keywords:
oil, oil harvest, harvest, resource, oil resource, oil system, oil harvest system, warcraft 2, resource harvest,
Contents

Custom Resource Harvest System 1.05 (Map)

Reviews
12:11, 18th Nov 2012 Magtheridon96: Changes made. Approved. This is well coded and deserves a very solid 4/5 :>
I'm asking for help. I tried using it on my map, typing everything correctly, and everything works, except for the unit training issue.
I get the "Not enough oil" error when I have too much oil.
 
Back
Top