• 🏆 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] Swap a unit with another units position (Change position of unit)

Status
Not open for further replies.
Level 4
Joined
Nov 19, 2010
Messages
54
Hello,

I am looking for a way to make a "Tower Swap" ability for my Tower Defense game. Just swapping / changing the location with the currently selected unit/tower with a unit/tower that is being clicked on and swap / change their positions with 1/2 time usage.

I created a unit named "swap tower" and i am trying to create a trigger for it that when used, the positions change with each other but i am unable to find anything for that in actions.
I haven't edited trigger in a while and i tried searching in the action triggers and also on the forum here but i couldn't find a topic that seems what i am looking for.

I also think i need to swap the "unit" with a "ability" to use for my towers.

  • Tower Swap Ability
    • Events
    • Conditions
      • (Unit-type of (Sold unit)) Equal to Swap Tower
    • Actions
      • Unit - Move (Triggering unit) instantly to (Mouse Position for Triggered Mouse Event)
      • Selection - Select (Triggering unit) for (Owner of (Triggering unit))
This is what i got so far with my trigger and that it is selected afterwards and moving it to the mouse position but it is more that i am looking for a select option and able to select the unit i want to swap the location with the current selected tower....

I don't know if someone can put me in the right direction with this?
 
Last edited:
Level 19
Joined
Feb 27, 2019
Messages
580
I have a simple untested idea. Have a targeted dummy ability that can target buildings. When a target is selected, turn off collision and swap places, then turn on collision.

If turning off collision does not work then move the first of the buildings to another location, move the other to the position of the first and then move the first to the position of the second.

This would only work if they have the same collision size.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,510
Hide one of the units prior to swapping their positions. Unhide after they're finished moving.

  • Untitled Trigger 001
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Set VariableSet SwapPoints[0] = (Position of (Triggering unit))
      • Set VariableSet SwapPoints[1] = (Position of (Target unit of ability being cast))
      • Unit - Hide (Target unit of ability being cast)
      • Unit - Move (Triggering unit) instantly to SwapPoints[1]
      • Unit - Move (Target unit of ability being cast) instantly to SwapPoints[0]
      • Unit - Unhide (Target unit of ability being cast)
      • Custom script: call RemoveLocation (udg_SwapPoints[0])
      • Custom script: call RemoveLocation (udg_SwapPoints[1])
Note that moving a unit in response to casting an ability will interrupt the cast. So if you wanted the swap ability to go on cooldown then you would need to manually start the cooldown yourself (there's an action for this). Might not be an issue for a building-type unit.
 
Last edited:
Level 4
Joined
Nov 19, 2010
Messages
54
Hide one of the units prior to swapping their positions. Unhide after they're finished moving.

  • Untitled Trigger 001
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Set VariableSet SwapPoints[0] = (Position of (Triggering unit))
      • Set VariableSet SwapPoints[1] = (Position of (Target unit of ability being cast))
      • Unit - Hide (Target unit of ability being cast)
      • Unit - Move (Triggering unit) instantly to SwapPoints[1]
      • Unit - Move (Target unit of ability being cast) instantly to SwapPoints[0]
      • Custom script: call RemoveLocation (udg_SwapPoints[0])
      • Custom script: call RemoveLocation (udg_SwapPoints[1])
Note that moving a unit in response to casting an ability will interrupt the cast. So if you wanted the swap ability to go on cooldown then you would need to manually start the cooldown yourself (there's an action for this).
Thanks alot again uncle for help.
It took me a while before i got it setup, it has been a while creating an actual trigger again.

I created a new global variable (Type: Point) named "Swappoints" and set Array for 2.

This is the trigger i created so far:
  • Tower Swap Ability
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Swap Tower
    • Actions
      • Set VariableSet Swappoints[0] = (Position of (Triggering unit))
      • Set VariableSet Swappoints[1] = (Position of (Target unit of ability being cast))
      • Unit - Hide (Target unit of ability being cast)
      • Unit - Move (Triggering unit) instantly to Swappoints[1]
      • Unit - Move (Target unit of ability being cast) instantly to Swappoints[0]
      • Unit - Unhide (Triggering unit)
      • Custom script: call RemoveLocation (udg_Swappoints[0])
      • Custom script: call RemoveLocation (udg_Swappoints[1])
The unit i have selected does move to the tower location that i click on and gets hidden but for some reason it does not get unhidden afterwards.

I tried several of the unit unhide posiblities that i thought it could be but it still doesn't "unhide" the last targeted unit so i cannot see it it getting swapped to the another tower last position.

I have tried the following:
  • Unit - Unhide (Target unit of ability being cast)
  • Unit - Unhide (Casting unit)
  • Unit - Unhide (Targeted unit)
And the one from above then

@[db]east Thanks for your help i had bit of a idea until i saw the response of uncle
 
Level 4
Joined
Nov 19, 2010
Messages
54
Ah, I forgot to Unhide it in my original trigger (fixed it).

Target unit of ability being cast should work. If it doesn't, try storing the Target as a variable:
  • Set Variable SwapTarget = Target unit of ability being cast
Then reference that variable instead.
Thanks for the quick reply Uncle!

I made a variable now because it didn't work with that "Target unit of ability being cast"
i need to test it a bit further out tomorrow evening but it seems to be not working completely correct yes some times it works (first few times at least it worked then i hosted the game and it did not work anymore...and if not work then it puts onto the position of the targeted unit but the another one does not hide / move to the old position of the moved tower


Edit: Ok i edited it a bit and tried again and now it works again.... i am gonna start a few games again and try it out and test it tomorrow evening better.
Thanks for the help!!

This is my final trigger i had made:
  • Actions
    • Set VariableSet SwapTarget = (Target unit of ability being cast)
    • Set VariableSet Swappoints[0] = (Position of (Triggering unit))
    • Set VariableSet Swappoints[1] = (Position of (Target unit of ability being cast))
    • Unit - Hide SwapTarget
    • Unit - Move (Triggering unit) instantly to Swappoints[1]
    • Unit - Move SwapTarget instantly to Swappoints[0]
    • Unit - Unhide SwapTarget
    • Custom script: call RemoveLocation (udg_Swappoints[0])
    • Custom script: call RemoveLocation (udg_Swappoints[1])
Edit: The variable for the Swap unit was type Unit and no array i used
 
Last edited:
Level 4
Joined
Nov 19, 2010
Messages
54
Well i played a bit tonight with my brother and we noticed a bug in the trigger, i edited a bit of text below the trigger from the previouis post about my swaptarget variable

With Legion TD, the towers become actual fighters and start attack-move to the creeps that come each round.
With the current trigger setup the towers do move and get switched and seem to work well but once the "towers" become an actual fighter and they start moving, they keep glitching in between the positions of the targeted tower and the last location, they do seem to attack and then move back to the another location and that keeps going on...

It seems also when we don't even use the swap tower button (we restarted the game and said lets not use the button) it was already happening once the round starts and the fighters starts to move again while we did not even press the button, so i turned off the trigger so we could play decent again without that glitchy bug.

Anyone might have an idea what that is?

I did not add the "swap tower" ability yet towards the fighters I only added them towards the towers "buildings" and not the fighters, might that be a issue ?

Since it is not really "needed" at the fighter towers, the swap tower ability because they get swapped when they are building during the "build round" before the creeps come and next to that i copied over the "inner fire" ability and made that my "ability" for swap tower after changing the setting ( it has a autocast ability but it is not turned on ) i don't know if that can cause a issue?

Because each time i make a actual new "ability" i cannot find the right settings like in the old editor some "data fields" are not available (visible) or i cannot seem to see a way to select what data fields i need when creating a new ability or even a unit some times so i copy one over that i think that might work for it
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,510
So you're saying it has nothing to do with the swap tower trigger? I'm confused.

It sounds like you have other issues that need to be sorted out. I don't really know what you're doing exactly in the map so I can't say for certain. If you want you can send me the map and I can try and find the issue.
 
Level 4
Joined
Nov 19, 2010
Messages
54
So you're saying it has nothing to do with the swap tower trigger? I'm confused.

It sounds like you have other issues that need to be sorted out. I don't really know what you're doing exactly in the map so I can't say for certain. If you want you can send me the map and I can try and find the issue.

Yeah sorry, i wrote it last night before i went to bed haha i thought i put a reply up and later i thought maybe a bit confusing.

It is confusing me2 but it has to do with the swap tower ability trigger yes, since i did not even use the "swap tower" ability yet and when they start to as when the rounds start and the creeps are coming in and they start to attack and then the swapping is happening ( I attached a gif of it and you can see the ogre is moving and a gnoll too ) and the ability has not been used yet, As soon as i turn off my trigger for the swap ability everything is fine again...

  • Tower Swap Ability
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Swap Tower
    • Actions
      • Set VariableSet SwapTarget = (Target unit of ability being cast)
      • Set VariableSet Swappoints[0] = (Position of (Triggering unit))
      • Set VariableSet Swappoints[1] = (Position of (Target unit of ability being cast))
      • Unit - Hide SwapTarget
      • Unit - Move (Triggering unit) instantly to Swappoints[1]
      • Unit - Move SwapTarget instantly to Swappoints[0]
      • Unit - Unhide SwapTarget
      • Custom script: call RemoveLocation (udg_Swappoints[0])
      • Custom script: call RemoveLocation (udg_Swappoints[1])
This is still the same trigger as i posted before and it should start working when a unit starts to cast it and equal to the "Swap tower" ability.

I thought maybe a gif helps so you can see what is happening, maybe you get an idea then else i wouldn't mind sending it if you don't mind looking at it but i can tell ya, the triggers are messy with organizing ( i didn't set them up like that ) and i didn't really do a cleanup yet only grouped my own triggers since i do not dare to touch some of them
 

Attachments

  • ezgif-2-6efb432690a3.gif
    ezgif-2-6efb432690a3.gif
    2.8 MB · Views: 37
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,510
Oh right, aren't you using Inner Fire as your base ability for Swap Tower? The towers are casting the ability on their own. When making custom abilities that use triggers for their effects you should use the Channel ability. Search for some tutorials on how to setup Channel, you can customize it to function how you want.

I believe these are the settings you want:
Options: Visible
Targeting Type: Unit
Follow Through Time: 0.00
Disable Other Abilities: False
Targets Allowed: Not Self, Player Owned, Structures
 
Level 4
Joined
Nov 19, 2010
Messages
54
Oh right, aren't you using Inner Fire as your base ability for Swap Tower? The towers are casting the ability on their own. When making custom abilities that use triggers for their effects you should use the Channel ability. Search for some tutorials on how to setup Channel, you can customize it to function how you want.

I believe these are the settings you want:
Options: Visible
Targeting Type: Unit
Follow Through Time: 0.00
Disable Other Abilities: False
Targets Allowed: Not Self, Player Owned, Structures
Thanks Once again Uncle for the help!

Yes it is true i was using inner fire as my base ability for it that why i was mentioning it because worried the autocast was causing it since i know about possible bug with that in the old editor, but the creating ability is different now with the world editor at reforged, i have looked up a tutorial about this and changed the settings and made a new "channel" ability named Swap Tower and changed the following options:

Data - Options: Tick Visible
Data - Target Type: Unit Target
Data - Follow Through Time: 0.00
Disable Other Abilities: False
Stats - Targets Allowed: Not Self, Player Owned, Structures

I tested it out with 1 game and it seems to be working so far but i will have to test it better in the weekend!
I will edit later about the results, Thanks again!

Edit: It works well (tested it until round 15 so it is good ) after changing from my own "inner fire" ability to a "channel" based ability when creating a new ability.

Thanks for the help!
 
Last edited:
Status
Not open for further replies.
Top