help with farm buildings that generate gold based on condition

Level 4
Joined
Jul 25, 2024
Messages
13
i want to have a system where you can build a farm or a windmill that cant generate gold by itself but can start to based on how many of a specific type of building (something like farmlands) you build in a certain range around it and if those buildings get destroyed it will detract from the gold being generated or even go back to 0 if there are none left
 
Level 4
Joined
Jul 25, 2024
Messages
13
Here you go, a GUI friendly system that does as you described. I'm on the latest patch so you'll need to be up to date to use it (be warned of any new patch bugs).

I can post the triggers if you can't open the map.
thanks, i figured out how to change the gold generated message to floating text and so far its working perfectly !!! just one question, does the unit indexer have to be map init or can it just be at time elapsed 0? idk if having multiple map init triggers is bad or not
 
Level 18
Joined
Dec 20, 2012
Messages
269
thanks, i figured out how to change the gold generated message to floating text and so far its working perfectly !!! just one question, does the unit indexer have to be map init or can it just be at time elapsed 0? idk if having multiple map init triggers is bad or not
I have a couple of triggers that run on map init. It doesn't cause any problems for me.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
thanks, i figured out how to change the gold generated message to floating text and so far its working perfectly !!! just one question, does the unit indexer have to be map init or can it just be at time elapsed 0? idk if having multiple map init triggers is bad or not
Do NOT mess with the Unit Indexer, it's designed to work a specific way. Just make sure that you only ever have one Unit Indexer in your map at a time.

That being said, I've heard RUMORS that there's some kind of limit you can reach if you use the "Map Initialization" Event too many times. However, I've never experienced this issue and cannot confirm it. It sounds like something that may only affect a ridiculously large map that's managing it's triggers poorly.

I personally design my systems to use the "Elapsed time 0" Event and for my own maps I Run my "Setup" triggers from one central trigger like so:
  • Events
    • Time - Elapsed game time is 0.00 seconds
  • Conditions
  • Actions
    • Trigger - Run Setup Players (ignoring conditions)
    • Trigger - Run Setup Units (ignoring conditions)
    • Trigger - Run Setup Tower Data (ignoring conditions)
    • Trigger - Run Setup Enemy Wave Data (ignoring conditions)
^ I highly recommend this design which gives you total control and cleaner organization. Also, I recommend using Timers instead of Elapsed Time events when dealing with triggers that do something after "X seconds". You'll thank yourself in the future when you decide to change when things should happen, IE: Delaying the first creep wave by 5 seconds.
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Can you post the triggers? I'm interested too :grin:
Sorry, I somehow missed this before. I posted the most up to date triggers below.

I also just realized that I made a mistake in the original map that would cause issues if a Gen/Node was destroyed while still under construction. I fixed it and attached the updated map down below.
  • Gold Generator Setup
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • -------- DEFINE THESE: --------
      • -------- --------
      • -------- Abilities used to determine which units act as generators and which act as nodes: --------
      • Set VariableSet GG_Generator__Ability = Gold Generator (Generator)
      • Set VariableSet GG_Node__Ability = Gold Generator (Node)
      • -------- --------
      • -------- Distance that a node must be within a generator to provide it with power (+gold): --------
      • Set VariableSet GG__Minimum_Distance = 512.00
      • -------- --------
      • -------- How much gold is earned PER node every X seconds: --------
      • Set VariableSet GG__Gold_Rewarded = 10
      • -------- --------
      • -------- DON'T TOUCH THIS: --------
      • -------- (It's necessary to ensure that things are initialized properly in the Finish Build trigger) --------
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Set VariableSet GG_PN = (Player number of (Picked player))
          • Custom script: set udg_GG_Generator_Group[udg_GG_PN] = null
          • Custom script: set udg_GG_Node_Group[udg_GG_PN] = null
  • Gold Generator Begin Build
    • Events
      • Unit - A unit Begins construction
    • Conditions
    • Actions
      • -------- Mark the unit as under construction: --------
      • Set VariableSet GG_Is_Constructing[(Custom value of (Triggering unit))] = True
  • Gold Generator Finish Build
    • Events
      • Unit - A unit Finishes construction
    • Conditions
    • Actions
      • Set VariableSet GG_Unit = (Triggering unit)
      • Set VariableSet GG_CV = (Custom value of GG_Unit)
      • -------- --------
      • -------- Mark the unit as no longer under construction: --------
      • Set VariableSet GG_Is_Constructing[GG_CV] = False
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of GG_Generator__Ability for GG_Unit) Greater than 0
        • Then - Actions
          • -------- You built a generator: --------
          • Set VariableSet GG_PN = (Player number of (Owner of GG_Unit))
          • -------- --------
          • Custom script: if udg_GG_Generator_Group[udg_GG_PN] == null then
          • Player Group - Add (Owner of GG_Unit) to GG_Player_Group
          • Custom script: set udg_GG_Generator_Group[udg_GG_PN] = CreateGroup()
          • Trigger - Turn on Gold Generator Income <gen>
          • Custom script: endif
          • -------- --------
          • -------- Track it in a group: --------
          • Unit Group - Add GG_Unit to GG_Generator_Group[GG_PN]
          • -------- --------
          • -------- Add nearby nodes to this generator: --------
          • Set VariableSet GG_Point[0] = (Position of GG_Unit)
          • Unit Group - Pick every unit in GG_Node_Group[GG_PN] and do (Actions)
            • Loop - Actions
              • Set VariableSet GG_Unit = (Picked unit)
              • Set VariableSet GG_Point[1] = (Position of GG_Unit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between GG_Point[0] and GG_Point[1]) Less than or equal to GG__Minimum_Distance
                • Then - Actions
                  • Set VariableSet GG_Generator_Node_Count[GG_CV] = (GG_Generator_Node_Count[GG_CV] + 1)
                • Else - Actions
              • Custom script: call RemoveLocation( udg_GG_Point[1] )
          • Custom script: call RemoveLocation( udg_GG_Point[0] )
        • Else - Actions
          • -------- You built a node: --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of GG_Node__Ability for GG_Unit) Greater than 0
            • Then - Actions
              • Set VariableSet GG_PN = (Player number of (Owner of GG_Unit))
              • -------- --------
              • Custom script: if udg_GG_Node_Group[udg_GG_PN] == null then
              • Player Group - Add (Owner of GG_Unit) to GG_Player_Group
              • Custom script: set udg_GG_Node_Group[udg_GG_PN] = CreateGroup()
              • Custom script: endif
              • -------- --------
              • -------- Track it in a group: --------
              • Unit Group - Add GG_Unit to GG_Node_Group[GG_PN]
              • -------- --------
              • -------- Add 1 node to nearby generators: --------
              • Set VariableSet GG_Point[0] = (Position of GG_Unit)
              • Unit Group - Pick every unit in GG_Generator_Group[GG_PN] and do (Actions)
                • Loop - Actions
                  • Set VariableSet GG_Unit = (Picked unit)
                  • Set VariableSet GG_Point[1] = (Position of GG_Unit)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Distance between GG_Point[0] and GG_Point[1]) Less than or equal to GG__Minimum_Distance
                    • Then - Actions
                      • Set VariableSet GG_CV = (Custom value of GG_Unit)
                      • Set VariableSet GG_Generator_Node_Count[GG_CV] = (GG_Generator_Node_Count[GG_CV] + 1)
                    • Else - Actions
                  • Custom script: call RemoveLocation( udg_GG_Point[1] )
              • Custom script: call RemoveLocation( udg_GG_Point[0] )
            • Else - Actions
  • Gold Generator Death
    • Events
      • Unit - A unit Dies
    • Conditions
      • GG_Is_Constructing[(Custom value of (Triggering unit))] Equal to False
    • Actions
      • Set VariableSet GG_Unit = (Triggering unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of GG_Generator__Ability for GG_Unit) Greater than 0
        • Then - Actions
          • -------- A generator died: --------
          • Set VariableSet GG_PN = (Player number of (Owner of GG_Unit))
          • Set VariableSet GG_CV = (Custom value of GG_Unit)
          • -------- --------
          • -------- Stop tracking it in a group: --------
          • Unit Group - Remove GG_Unit from GG_Generator_Group[GG_PN].
          • -------- --------
          • -------- Reset it's node count to 0 (unit indexer can recycle custom values and share this with future units): --------
          • Set VariableSet GG_Generator_Node_Count[GG_CV] = 0
        • Else - Actions
          • -------- A node died: --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of GG_Node__Ability for GG_Unit) Greater than 0
            • Then - Actions
              • Set VariableSet GG_PN = (Player number of (Owner of GG_Unit))
              • -------- --------
              • -------- Stop tracking it in a group: --------
              • Unit Group - Remove GG_Unit from GG_Node_Group[GG_PN].
              • -------- --------
              • -------- Subtract 1 node from nearby generators: --------
              • Set VariableSet GG_Point[0] = (Position of GG_Unit)
              • Unit Group - Pick every unit in GG_Generator_Group[GG_PN] and do (Actions)
                • Loop - Actions
                  • Set VariableSet GG_Unit = (Picked unit)
                  • Set VariableSet GG_Point[1] = (Position of GG_Unit)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Distance between GG_Point[0] and GG_Point[1]) Less than or equal to GG__Minimum_Distance
                    • Then - Actions
                      • Set VariableSet GG_CV = (Custom value of GG_Unit)
                      • Set VariableSet GG_Generator_Node_Count[GG_CV] = (GG_Generator_Node_Count[GG_CV] - 1)
                    • Else - Actions
                  • Custom script: call RemoveLocation( udg_GG_Point[1] )
              • Custom script: call RemoveLocation( udg_GG_Point[0] )
            • Else - Actions
  • Gold Generator Income
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in GG_Player_Group and do (Actions)
        • Loop - Actions
          • Set VariableSet GG_PN = (Player number of (Picked player))
          • Unit Group - Pick every unit in GG_Generator_Group[GG_PN] and do (Actions)
            • Loop - Actions
              • Set VariableSet GG_Unit = (Picked unit)
              • Set VariableSet GG_CV = (Custom value of GG_Unit)
              • -------- --------
              • -------- Calculate gold rewarded: --------
              • Set VariableSet GG_Reward = (GG__Gold_Rewarded x GG_Generator_Node_Count[GG_CV])
              • -------- --------
              • -------- If above 0, reward it: --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • GG_Reward Greater than 0
                • Then - Actions
                  • Player - Add GG_Reward to (Player(GG_PN)).Current gold
                  • Game - Display to (All players) for 1.00 seconds the text: ((Player + ((String(GG_PN)) + generated: )) + (String(GG_Reward)))
                • Else - Actions
These triggers rely on two custom abilities based on Storm Hammers, Gold Generator (Node) and Gold Generator (Generator). They have their Art - Button positions set to X: 0, Y: -11 which makes them hidden from sight. These abilities are being used as custom Classifications, in other words, we use them in our triggers to ask the question "Are you a Generator?" and "Are you a Node?". This design works nicely since it means we can have an unlimited number of different Generators/Nodes that all work together. Another thing, if you recreate these Variables make sure that their Variable names are EXACTLY the same as mine, otherwise any Custom Script that references them will fail to work and throw an error.
 

Attachments

  • Gold Generator 2.w3m
    27.7 KB · Views: 4
Last edited:
Top