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

Gold Mine without a homebase!

Status
Not open for further replies.

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,578
What does that mean exactly? When they exit the Gold Mine would you receive the gold immediately? Do they even need to enter the Gold Mine?

What I would do:
Create a hidden Channeling ability that your Heroes can cast on Gold Mines. Basically, if you right click the Gold Mine with your Hero then you would order it instead cast this ability on the Gold Mine. Then once they begin channeling the ability you would periodically subtract gold from the mine and add it to the caster. A Unit Indexer + Unit Group + Periodic Interval could get the job done.
 
Last edited:
Level 7
Joined
Feb 13, 2022
Messages
86
What does that mean exactly? When they exit the Gold Mine would you receive the gold immediately? Do they even need to enter the Gold Mine?

What I would:
Create a hidden Channeling ability that your Heroes can cast on Gold Mines. Basically, if you right click the Gold Mine with your Hero then you would order it instead cast this ability on the Gold Mine. Then once they begin channeling the ability you would periodically subtract gold from the mine and add it to the caster. A Unit Indexer + Unit Group + Periodic Interval could get the job done.
Exactly! When they are done collecting the gold they would receive the gold immediately! They don't need to enter the gold mine. I will attempt to make those triggers for the hidden channeling ability, any chance you could make those triggers so I could copy them? If not, your suggestion has helped plenty!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,578
If you're on the latest version of Warcraft 3 then I can throw something together for you. But just to clarify, would they channel the ability forever and then let's say every 5 seconds of channeling receive the gold? That would make the most sense to me. And of course if the Gold Mine is out of gold they will stop and be unable to target it anymore.
 
Level 7
Joined
Feb 13, 2022
Messages
86
If you're on the latest version of Warcraft 3 I can throw something together for you. But just to clarify, would they channel forever and let's say every 5 seconds of channeling receive the gold? That would make the most sense to me. And of course if the Gold Mine is out of gold they will stop and be unable to target it anymore.
Yes it would be forever unless the player starts to move, build, or activate another hero ability, it would be every 5 seconds equals 10 gold from the mine. Thanks dude I appreciate the help a ton, you are going to save me a ton of time! I have the latest version of Warcraft 3 reforged if that makes a difference.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,578
Here you go, hopefully it's to your liking. If you already have a Unit Indexer in your map then DO NOT add another one! They often come with imported systems / custom spells but all you need is one since they all do the same thing.
 

Attachments

  • Hero Mine Gold 1.w3m
    25.8 KB · Views: 6
Last edited:
Level 7
Joined
Feb 13, 2022
Messages
86
Here you go, hopefully it's to your liking. If you already have a Unit Indexer in your map then DO NOT add another one! They often come with imported systems / custom spells but all you need is one since they all do the same thing.
Wow this system works awesomely, thank you it is exactly what I'm looking for! Im having trouble implementing this system into my map. I'm still a novice when it comes to custom script and indexes. Could you take a look at your system in my current map? Here is a link to the current map: Broken CheeseMine in Rat Maze
Instead of the generic gold mines, I want this to work only for my Cheese-Mines (basically normal gold mines with a yellow tint to them), and I want only the Rat Heroes to be able harvest gold no other heroes. To find your system in my triggers, go under the Initialization folder, then open the Utility/Misc folder, and finally you will find your system in a folder called RatGoldHarvest. Once again thank you again for all the help, you are an awesome moderator!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,578
Step 1: You'll see in my map I have an ability called Hero Mine Gold. You need to copy and paste this into your map. Then give it to any Hero that you want to be able to harvest gold.

Step 2: In the Trigger Editor you'll want to copy and paste both folders into your map, Unit Indexer and Hero Gold Mine. If you've already imported a Unit Indexer into your map then you don't need another one. Also, if you're ever setting Custom Value in your triggers then know that this will conflict with the Unit Indexer, however, a Unit Indexer provides a much better alternative solution that makes setting Custom Value unnecessary.

Step 3: Looking through the triggers you should see Conditions that 1) Check for a standard Gold Mine and 2) Check for the Hero Mine Gold ability. HOWEVER, since you've imported this into your map these references can get messed up and you may need to update them. So anything that was checking the (Ability being cast) should reference your Hero Mine Gold ability and anything that's referencing a standard Gold Mine should be checking for your Cheese-Mines instead.

These fixes should be fairly simple and straightforward. Also, I'm pretty sure on your version this is already enabled by default but there's a World Editor Preference called "Automatically create unknown variables..." which should be enabled from the File menu. This can help a lot when importing triggers into your map and should be enabled before doing so.

Edit: See these conditions, note how they're referencing an Unknown ability. That should be Hero Mine Gold.
  • Hero Mine Gold Order
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • (Level of Unknown (CHNL) for (Ordered unit)) Equal to 1
      • (Issued order) Equal to (Order(smart))
    • Actions
  • Hero Mine Gold Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Unknown (CHNL)
    • Actions
Also, a random bit of advice after glossing over your triggers. You should rarely need to make a unique trigger/variable for each individual player. You can generally achieve everything in a single trigger. For example, creating the Speed Potions for the Rats after 300.00 seconds:
  • fiveminpotion
    • Events
      • Time - Elapsed game time is 300.00 seconds
    • Conditions
    • Actions
      • Unit Group - Pick every unit in RatGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Life of (Picked unit)) Greater than or equal to 1.00
            • Then - Actions
              • Item - Create Potion of Speed at (Position of (Picked unit))
            • Else - Actions
^ This one trigger will check the life of each Rat (assuming you've added them to RatGroup) and give each of them their own Speed Potion. Note: If you meant to filter out dead Rats then there's a Boolean Condition for that -> Is unit alive/dead. Checking if Life is >= 1.00 is not guaranteed to work since a unit can have < 1.00 life and still be alive.

Also, a variable can be made to work for multiple units/players as well. This can be done with Variable Arrays and the Unit Indexer to store data to specific units and Player Numbers to store data to specific players. Combine all of those with Unit Groups / Player Groups and you have an easy way to reference every Player + Unit and any data revolving around them at any given moment in a single trigger.

Also, it looks like you aren't addressing memory leaks. It's not the end of the world and your map should run fine as is but it's something you may want to look into in the future if you care about improving game performance. The severity of memory leaks really depends on what you're doing. For example, a trigger which leaks 100 Unit Groups per second would be pretty severe.
 
Last edited:
Level 7
Joined
Feb 13, 2022
Messages
86
Step 1: You'll see in my map I have an ability called Hero Mine Gold. You need to copy and paste this into your map. Then give it to any Hero that you want to be able to harvest gold.

Step 2: In the Trigger Editor you'll want to copy and paste both folders into your map, Unit Indexer and Hero Gold Mine. If you've already imported a Unit Indexer into your map then you don't need another one. Also, if you're ever setting Custom Value in your triggers then know that this will conflict with the Unit Indexer, however, a Unit Indexer provides a much better alternative solution that makes setting Custom Value unnecessary.

Step 3: Looking through the triggers you should see Conditions that 1) Check for a standard Gold Mine and 2) Check for the Hero Mine Gold ability. HOWEVER, since you've imported this into your map these references can get messed up and you may need to update them. So anything that was checking the (Ability being cast) should reference your Hero Mine Gold ability and anything that's referencing a standard Gold Mine should be checking for your Cheese-Mines instead.

These fixes should be fairly simple and straightforward. Also, I'm pretty sure on your version this is already enabled by default but there's a World Editor Preference called "Automatically create unknown variables..." which should be enabled from the File menu. This can help a lot when importing triggers into your map and should be enabled before doing so.

Edit: See these conditions, note how they're referencing an Unknown ability. That should be Hero Mine Gold.
  • Hero Mine Gold Order
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • (Level of Unknown (CHNL) for (Ordered unit)) Equal to 1
      • (Issued order) Equal to (Order(smart))
    • Actions
  • Hero Mine Gold Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Unknown (CHNL)
    • Actions
Also, a random bit of advice after glossing over your triggers. You should rarely need to make a unique trigger/variable for each individual player. You can generally achieve everything in a single trigger. For example, creating the Speed Potions for the Rats after 300.00 seconds:
  • fiveminpotion
    • Events
      • Time - Elapsed game time is 300.00 seconds
    • Conditions
    • Actions
      • Unit Group - Pick every unit in RatGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Life of (Picked unit)) Greater than or equal to 1.00
            • Then - Actions
              • Item - Create Potion of Speed at (Position of (Picked unit))
            • Else - Actions
^ This one trigger will check the life of each Rat (assuming you've added them to RatGroup) and give each of them their own Speed Potion. Note: If you meant to filter out dead Rats then there's a Boolean Condition for that -> Is unit alive/dead. Checking if Life is >= 1.00 is not guaranteed to work since a unit can have < 1.00 life and still be alive.

Also, a variable can be made to work for multiple units/players which will help simplify things. This can be done with Variable Arrays and the Unit Indexer to store data to specific units and Player Numbers to store data to specific players. Combine all of those with Unit Groups / Player Groups and you have an easy way to reference every Player + Unit and any data revolving around them at any given moment in a single trigger.

Also, it looks like you aren't addressing memory leaks. It's not the end of the world and your map should run fine but it's something you may want to look into in the future if you care about improving game performance. There are some rare cases where a user creates a trigger which generates a ton of nasty memory leaks. Something like leaking 100 Unit Groups per second would be quite bad and you'd probably notice better performance if you addressed it.
You are seriously a true gentlemen and a scholar thank you for all the help! Everything works perfectly now thank you so much! How would I make a trigger that kills the gold mines once they hit zero gold? Thank you for pointing that out, It is definitely something I will work on to make my game efficient!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,578
You can track your Gold Mines in a Unit Group and then periodically check the amount of gold left in them:
  • Get Gold Mines
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Set VariableSet GoldMineGroup = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Gold Mine))
  • Check Gold Mines
    • Events
      • Time - Every 0.20 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in GoldMineGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Resource quantity contained in (Picked unit)) Equal to 0
            • Then - Actions
              • Unit Group - Remove (Picked unit) from GoldMineGroup
              • Unit - Kill (Picked unit)
            • Else - Actions
Alternatively, if the ONLY way a Gold Mine will run out of Gold is through the Hero Mine Gold ability then you can do the following:
In my Hero Mine Gold Loop trigger, find the If Then Else statement that checks when the Gold is >= to 10 and Kill the Gold Mine in it's Else - Actions section:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • HMG_Gold Greater than 10
    • Then - Actions
      • Set VariableSet HMG_Gold = 10
    • Else - Actions
      • Unit - Kill HMG_GoldMine[HMG_CV]
OR you could use both of these methods together if you wanted multiple ways to mine gold.
If that's the case then make sure to Remove the Gold Mine from GoldMineGroup before Killing it:
  • Unit Group - Remove HMG_GoldMine[HMG_CV] from GoldMineGroup
  • Unit - Kill HMG_GoldMine[HMG_CV]
 
Last edited:
Status
Not open for further replies.
Top