• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

Need help with trigger to limit units from different players

Level 7
Joined
Sep 10, 2023
Messages
112
So I have player 1, player 2, player 3, player 4, player 5 and player 6. When player 1 uses a spell it spawns a unit for player 2 that when it finishes the building it changes ownership to player 3. The same thing can happen for player 4, it spawns a unit for player 5 that changes ownership to player 6.

I need to limit the amount of unit type X for player 2 and 3 (separately) and for player 5 and 6 too.

Im trying to make it work but it doesnt works when the unit gets killed, it prevents me from making a new structure when the building gets destroyed, Ive tried with changing triggering unit to dying unit too. Any help?


  • Begins Ob
    • Events
      • Unit - A unit Begins construction
    • Conditions
      • (Unit-type of (Constructing structure)) Equal to Ritual Obelisk
    • Actions
      • Set VariableSet TempObInt = (Player number of (Owner of (Triggering unit)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ObeliskCount[TempObInt] Greater than or equal to 2
        • Then - Actions
          • Unit - Remove (Constructing structure) from the game
          • Game - Display to Zombieshareupggroup for 30.00 seconds the text: |cffb4002aMaximum L...
        • Else - Actions
          • Set VariableSet ObeliskCount[TempObInt] = (ObeliskCount[TempObInt] + 1)
          • Hashtable - Save TempObInt as 0 of (Key (Constructing structure).) in HashOb.

  • Obelisk Dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Ritual Obelisk
    • Actions
      • Set VariableSet TempObInt = (Load 0 of (Key (Triggering unit).) from HashOb.)
      • Set VariableSet ObeliskCount[TempObInt] = (ObeliskCount[TempObInt] + 1)
 
So as I understand, you are using spells like 'Build tiny farm', etc. to build structures?
If so, in your "Begins Ob" trigger increment ObeliskCount[] value, check if you hit the limit and if so, use the 'Player - Enable/Disable Ability' action to disable the spell itself. Same with structure being destroyed: Decrement ObeliskCount[] and enable the ability back again.
For example here I limit Farms to only 2:
  • Begins Construction
    • Events
      • Unit - A unit Begins construction
    • Conditions
      • (Unit-type of (Constructing structure)) Equal to Farm
    • Actions
      • Set VariableSet PN = (Player number of (Triggering player))
      • Set VariableSet Counters[PN] = (Counters[PN] + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Counters[PN] Equal to 2
        • Then - Actions
          • Player - Disable Build Tiny Farm for (Triggering player)
        • Else - Actions
  • Destroyed
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Farm
    • Actions
      • Set VariableSet PN = (Player number of (Triggering player))
      • Set VariableSet Counters[PN] = (Counters[PN] - 1)
      • Player - Enable Build Tiny Farm for (Triggering player)
 
So as I understand, you are using spells like 'Build tiny farm', etc. to build structures?
If so, in your "Begins Ob" trigger increment ObeliskCount[] value, check if you hit the limit and if so, use the 'Player - Enable/Disable Ability' action to disable the spell itself. Same with structure being destroyed: Decrement ObeliskCount[] and enable the ability back again.
For example here I limit Farms to only 2:
  • Begins Construction
    • Events
      • Unit - A unit Begins construction
    • Conditions
      • (Unit-type of (Constructing structure)) Equal to Farm
    • Actions
      • Set VariableSet PN = (Player number of (Triggering player))
      • Set VariableSet Counters[PN] = (Counters[PN] + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Counters[PN] Equal to 2
        • Then - Actions
          • Player - Disable Build Tiny Farm for (Triggering player)
        • Else - Actions
  • Destroyed
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Farm
    • Actions
      • Set VariableSet PN = (Player number of (Triggering player))
      • Set VariableSet Counters[PN] = (Counters[PN] - 1)
      • Player - Enable Build Tiny Farm for (Triggering player)
No, im using regular building
 
Don't you want to reduce the amount of obelisks when they get destroyed?
Because currently you do this:
Set VariableSet ObeliskCount[TempObInt] = (ObeliskCount[TempObInt] + 1)
instead of:
Set VariableSet ObeliskCount[TempObInt] = (ObeliskCount[TempObInt] - 1)
 
No, im using regular building
If so, then you can set construction limit of a building for a player via 'Player - Limit Training Of Unit-Type' action.
Set hard limit into variable (e.g. "StructureLimit"). When unit begins construction and you change owner of the constructing building, then increment count for player and call the action for limiting unit-type. set new limit as "StructureLimit - count". Same formula works when structure is destroyed after you decrement structure count for player.

For example, this limits farm to 3 for Player 1 (Red), even when the farm changes ownership during construction to Player 2 (Blue) and then to Player 3 (Teal) upon finishing construction.

  • Map Ini
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet FarmLimit = 3
      • -------- ---- --------
      • Player - Limit training of Farm to FarmLimit for Player 1 (Red)
      • -------- ---- --------
      • Player - Make Player 1 (Red) treat Player 2 (Blue) as an Ally with shared vision
      • Player - Make Player 1 (Red) treat Player 3 (Teal) as an Ally with shared vision
      • -------- ---- --------
      • Player - Make Player 2 (Blue) treat Player 1 (Red) as an Ally with shared vision
      • Player - Make Player 2 (Blue) treat Player 3 (Teal) as an Ally with shared vision
      • -------- ---- --------
      • Player - Make Player 3 (Teal) treat Player 1 (Red) as an Ally with shared vision
      • Player - Make Player 3 (Teal) treat Player 2 (Blue) as an Ally with shared vision
      • -------- ---- --------
      • Set VariableSet OwnershipChain[(Player number of Player 1 (Red))] = Player 2 (Blue)
      • Set VariableSet OwnershipChain[(Player number of Player 2 (Blue))] = Player 3 (Teal)
      • Set VariableSet OwnershipChain[(Player number of Player 3 (Teal))] = Player 1 (Red)
  • Farm Constructing
    • Events
      • Unit - A unit Begins construction
    • Conditions
      • (Unit-type of (Constructing structure)) Equal to Farm
    • Actions
      • Set VariableSet PN = (Player number of (Triggering player))
      • Unit - Change ownership of (Constructing structure) to OwnershipChain[PN] and Change color
      • Set VariableSet FarmCounts[PN] = (FarmCounts[PN] + 1)
      • Player - Limit training of Farm to (FarmLimit - FarmCounts[PN]) for (Triggering player)
  • Farm Constructed
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Constructed structure)) Equal to Farm
    • Actions
      • Set VariableSet PN = (Player number of (Owner of (Constructed structure)))
      • Unit - Change ownership of (Constructed structure) to OwnershipChain[PN] and Change color
  • Farm Destroyed
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Farm
    • Actions
      • Set VariableSet PN = (Player number of (Triggering player))
      • Set VariableSet OriginalOwner = OwnershipChain[PN]
      • Set VariableSet PN = (Player number of OriginalOwner)
      • Set VariableSet FarmCounts[PN] = (FarmCounts[PN] - 1)
      • Player - Limit training of Farm to (FarmLimit - FarmCounts[PN]) for OriginalOwner
 
If so, then you can set construction limit of a building for a player via 'Player - Limit Training Of Unit-Type' action.
Set hard limit into variable (e.g. "StructureLimit"). When unit begins construction and you change owner of the constructing building, then increment count for player and call the action for limiting unit-type. set new limit as "StructureLimit - count". Same formula works when structure is destroyed after you decrement structure count for player.

For example, this limits farm to 3 for Player 1 (Red), even when the farm changes ownership during construction to Player 2 (Blue) and then to Player 3 (Teal) upon finishing construction.

  • Map Ini
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet FarmLimit = 3
      • -------- ---- --------
      • Player - Limit training of Farm to FarmLimit for Player 1 (Red)
      • -------- ---- --------
      • Player - Make Player 1 (Red) treat Player 2 (Blue) as an Ally with shared vision
      • Player - Make Player 1 (Red) treat Player 3 (Teal) as an Ally with shared vision
      • -------- ---- --------
      • Player - Make Player 2 (Blue) treat Player 1 (Red) as an Ally with shared vision
      • Player - Make Player 2 (Blue) treat Player 3 (Teal) as an Ally with shared vision
      • -------- ---- --------
      • Player - Make Player 3 (Teal) treat Player 1 (Red) as an Ally with shared vision
      • Player - Make Player 3 (Teal) treat Player 2 (Blue) as an Ally with shared vision
      • -------- ---- --------
      • Set VariableSet OwnershipChain[(Player number of Player 1 (Red))] = Player 2 (Blue)
      • Set VariableSet OwnershipChain[(Player number of Player 2 (Blue))] = Player 3 (Teal)
      • Set VariableSet OwnershipChain[(Player number of Player 3 (Teal))] = Player 1 (Red)
  • Farm Constructing
    • Events
      • Unit - A unit Begins construction
    • Conditions
      • (Unit-type of (Constructing structure)) Equal to Farm
    • Actions
      • Set VariableSet PN = (Player number of (Triggering player))
      • Unit - Change ownership of (Constructing structure) to OwnershipChain[PN] and Change color
      • Set VariableSet FarmCounts[PN] = (FarmCounts[PN] + 1)
      • Player - Limit training of Farm to (FarmLimit - FarmCounts[PN]) for (Triggering player)
  • Farm Constructed
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Constructed structure)) Equal to Farm
    • Actions
      • Set VariableSet PN = (Player number of (Owner of (Constructed structure)))
      • Unit - Change ownership of (Constructed structure) to OwnershipChain[PN] and Change color
  • Farm Destroyed
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Farm
    • Actions
      • Set VariableSet PN = (Player number of (Triggering player))
      • Set VariableSet OriginalOwner = OwnershipChain[PN]
      • Set VariableSet PN = (Player number of OriginalOwner)
      • Set VariableSet FarmCounts[PN] = (FarmCounts[PN] - 1)
      • Player - Limit training of Farm to (FarmLimit - FarmCounts[PN]) for OriginalOwner
Thanks for the system, ill try using it and see how it goes
 
Back
Top