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

[Trigger] max 2 tower spawn

Status
Not open for further replies.
Level 17
Joined
Aug 19, 2007
Messages
1,380
Hi there, I need some help with a bugged trigger. I want to make it that I can only spawn max 2 towers and that when I spawn a third tower 1 tower is destroyed and that one is not equal to the one I summoned/spawned. The thing is, when I use the following trigger, sometimes it doesn't destroy a tower at all :confused::

  • max two towers
    • Events
      • Unit - A unit Spawns a summoned unit
    • Conditions
      • ((Unit-type of (Summoned unit)) Equal to Weapon: Small Dagger (lvl1))
      • (Count structures controlled by (Owner of (Summoning unit)) (Include incomplete structures)) Equal to 3
    • Actions
      • Unit - Kill (Random unit from (Units owned by (Owner of (Summoned unit)) matching ((((Unit-type of (Matching unit)) Equal to Weapon: Small Dagger (lvl1)) and ((Matching unit) Not equal to (Summoned unit))
 
Level 12
Joined
Dec 10, 2008
Messages
850
I do believe there is a GUI function that allows you to limit construction of buildings, and when you hit that max, it removes it from the menue. I'll post it in a few...

EDIT: Under players, its called Player - Limit training of unit-type Use it to limit the training
 
Level 8
Joined
Dec 9, 2009
Messages
397
Add the towers to a unit group array TowerGroup
When your trigger is about to create the next tower do
if units in tower group = 2
pick random unit in unit group and kill unit
Then spawn the tower, and add it to TowerGroup
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
This saves buildings that are built and spawned to an array. The older of the two is destroyed when a third begins to be built or is spawned. It's MPI.

  • Untitled Trigger 056
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Scout Tower
    • Actions
      • Set Temp_Integer_1 = ((Player number of (Owner of (Triggering unit))) x 2)
      • Unit - Kill Temp_Unit_Aray[Temp_Integer_1]
      • Set Temp_Unit_Aray[Temp_Integer_1] = Temp_Unit_Aray[(Temp_Integer_1 - 1)]
      • Set Temp_Unit_Aray[(Temp_Integer_1 - 1)] = (Triggering unit)
 
Level 17
Joined
Aug 19, 2007
Messages
1,380
Add the towers to a unit group array TowerGroup
When your trigger is about to create the next tower do
if units in tower group = 2
pick random unit in unit group and kill unit
Then spawn the tower, and add it to TowerGroup
This saves buildings that are built and spawned to an array. The older of the two is destroyed when a third begins to be built or is spawned. It's MPI.
, which size do I need to use for the Temp_Unit_Aray, 2?
 
Level 17
Joined
Aug 19, 2007
Messages
1,380
You don't need to set initial sizes for arrays.

This system uses

[1] and [2] for player 1
[3] and [4] for player 2

and so on.
, I actually meant the size of the array (when I marked array, right of it I can set the size of it). I'm bit confused, since I'm new at creating arrays. In the map I will use this trigger for contains 4 players which are playable by users (player1, player2, player6 and player7). Can I use only this trigger?:

  • max two towers
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Weapon: Small Dagger (lvl1)
          • (Unit-type of (Triggering unit)) Equal to Weapon: Arrow (lvl2)
          • (Unit-type of (Triggering unit)) Equal to Weapon: Small Glaive (lvl3)
          • (Unit-type of (Triggering unit)) Equal to Weapon: Ballista Arrow (lvl4)
          • (Unit-type of (Triggering unit)) Equal to Weapon: Large Glaive (lvl5)
          • (Unit-type of (Triggering unit)) Equal to Weapon: Machine Gun (lvl6)
          • (Unit-type of (Triggering unit)) Equal to Weapon: Bunker (lvl7)
    • Actions
      • Set Temp_Integer_1 = ((Player number of (Owner of (Triggering unit))) x 2)
      • Unit - Kill Temp_Unit_Aray[Temp_Integer_1]
      • Set Temp_Unit_Aray[Temp_Integer_1] = Temp_Unit_Aray[(Temp_Integer_1 - 1)]
      • Set Temp_Unit_Aray[(Temp_Integer_1 - 1)] = (Triggering unit)
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
[K40$]-Spectre;1432962 said:
, I actually meant the size of the array (when I marked array, right of it I can set the size of it).

I know. You don't need to set the size, the game engine knows how to allocate memory for the array.

You can use that trigger. But if you have two machine guns and then you start to build an arrow, one of the machine guns will be destroyed.

If you don't want that to happen, then the system needs to be modified to use different kind of indexing based on unit player number and unit types, or use a hashtable.
 
Level 17
Joined
Aug 19, 2007
Messages
1,380
I know. You don't need to set the size, the game engine knows how to allocate memory for the array.

You can use that trigger. But if you have two machine guns and then you start to build an arrow, one of the machine guns will be destroyed.

If you don't want that to happen, then the system needs to be modified to use different kind of indexing based on unit player number and unit types, or use a hashtable.
, since there will be only 1 hero that can cast those towers (if picked, other players can't pick him anymore), this will work? Or do I need to have 4 triggers (1 for each player and each a different variable/array)? Thanks for taking the time btw, I know I'm a pain in the ass when it comes to variables/arrays :p.
 
Status
Not open for further replies.
Top