• 🏆 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] Merging Buildings

Status
Not open for further replies.
Level 1
Joined
Jan 29, 2021
Messages
3
I'm creating a td where you can merge a tower when you have at least two of the same kind.

I made this trigger:
  • UpgradeWhiteT1
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Merge
      • (Unit-type of (Casting unit)) Equal to [Tier 1] White Tower
    • Actions
      • For each (Integer A) from 1 to (Number of units in (Units currently selected by (Owner of (Casting unit)))), do (Actions)
        • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Triggering unit)) Equal to [Tier 1] White Tower
          • (Number of units in (Units owned by (Owner of (Casting unit)) of type [Tier 1] White Tower)) Greater than or equal to 2
        • Then - Actions
          • Unit - Remove (Random unit from (Random 1 units from (Units owned by (Owner of (Casting unit)) of type [Tier 1] White Tower))) from the game
          • Unit - Replace (Casting unit) with a [Tier 2] White Tower using The new unit's default life and mana
        • Else - Actions
But it is not working.
It allows you to upgrade a tower without removing the other.
And you can also upgrade the tower when you dont have 2 of its kind.

Can you guys help me?

Thanks anyway!
 
Last edited:
Level 12
Joined
Nov 3, 2013
Messages
989
Does your ability let you target a unit? If so just check if unit type of (Triggering Unit) and (Target of Ability Being Cast) are the same.


Even if you don't, I imagine it's better if there's targeting, since that way the player can choose which towers merge.
 
Level 1
Joined
Jan 29, 2021
Messages
3
No, you cant target the other unit.
Since you have a lot of towers, i am trying to create this trigger.

I will consider your option and i will add it to my game.
Do you imagine any other way to do this?

Thanks!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,535
Your trigger doesn't work because it's using the wrong Event Responses and your For Loop (For each integer A) is empty, none of the Actions are actually inside of it.

It wouldn't work properly anyway because you're removing 1 random unit, which could be the casting unit, and then trying to replace the casting unit. Nothing is preventing the casting unit from also being the removed random unit.

You're also leaking 3 Unit Groups.

Here's how you can merge towers instantly, no target required:
  • Merge Towers Instant
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Set VariableSet TempGroup = (Units owned by (Triggering player) matching ((Unit-type of (Matching unit)) Equal to Guard Tower).)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in TempGroup) Greater than or equal to 2
        • Then - Actions
          • Unit Group - Remove (Triggering unit) from TempGroup.
          • Unit - Replace (Triggering unit) with a Cannon Tower using The old unit's relative life and mana
          • Unit - Remove (Random unit from TempGroup) from the game
        • Else - Actions
      • Custom script: call DestroyGroup (udg_TempGroup)
Here's how you can merge towers targeting a unit:
  • Merge Towers Target
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Unit - Replace (Triggering unit) with a Cannon Tower using The old unit's relative life and mana
      • Unit - Remove (Target unit of ability being cast) from the game
I left out the ability being cast/unit-type Conditions, so make sure to add those back in.

Also, why wouldn't you be able to target the other unit? That sounds like a Targets Allowed issue that you can fix.
 
Level 1
Joined
Jan 29, 2021
Messages
3
Thank you so much!

The trigger is working almost perfect, but: when i have more than 1 tower in my selection it doesnt work properly.
For example:
If i have 7 towers in my selection, the trigger replaces 4 of them instead of 3.
I tried to add a for each selected unit but its not working.

Thank you so much!
 
Status
Not open for further replies.
Top