• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Moving unit and changin persetage hp

Status
Not open for further replies.
Level 26
Joined
Dec 3, 2018
Messages
874
This should inter-change the units' position and persentage hp.
Instead it just kills the caster and moves the target at it's position.
Any ideas how should i make this work?


  • Change Leader
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Change Leader
    • Actions
      • Set VariableSet Trollpoint = (Position of (Target unit of ability being cast))
      • Wait 0.50 seconds
      • Unit - Move (Target unit of ability being cast) instantly to (Position of (Triggering unit)), facing 260.00 degrees
      • Unit - Move (Triggering unit) instantly to Trollpoint, facing 260.00 degrees
      • Wait 0.50 seconds
      • Unit - Set life of (Triggering unit) to (Percentage life of (Target unit of ability being cast))%
      • Wait 0.50 seconds
      • Unit - Set life of (Target unit of ability being cast) to (Percentage life of (Triggering unit))%
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,660
You can't use Waits like that. Most Event Responses are lost after a Wait or act like global variables which means that their value can easily be changed to something else during the Waiting period. Waits are also imprecise and can continue even while the game is paused (I think Wait game-time fixes that issue).

You should learn how to use techniques like Unit Indexing, Dynamic Indexing, Hashtables, Timers, Shadowing, Local variables, etc.
This will allow you to make more advanced triggers that work without issues. I have links in my signature.

But are the Waits even necessary. This should work fine:
  • Set Variable Caster = (Triggering unit)
  • Set Variable Target = (Target unit of ability being cast)
  • Set Variable CasterHP (Percentage life of Caster)
  • Set Variable TargetHP = (Percentage life of Target)
  • Set Variable CasterPoint = (Position of Caster)
  • Custom script: call SetUnitX(udg_Caster, GetUnitX(udg_Target))
  • Custom script: call SetUnitY(udg_Caster, GetUnitY(udg_Target))
  • Unit - Move Target instantly to CasterPoint, facing 270.00 degrees
  • Unit - Make Caster face 270.00 over 0.00 seconds
  • Unit - Set life of Caster to TargetHP
  • Unit - Set life of Target to CasterHP
  • Custom script: call RemoveLocation(udg_CasterPoint)
Other issues with your trigger...

You're swapping the % life totals incorrectly. You need to store them in variables before making any changes to the unit's life:
  • Set Variable CasterHP (Percentage life of Caster)
  • Set Variable TargetHP = (Percentage life of Target)
In your trigger the caster's life is set to the target's life, then the target's life is set to the caster's life which has just been changed. You want to reference the original values.

Moving a unit on top of another unit will displace it due to pathing. You can use the SetUnitX() and SetUnitY() functions to avoid this:
  • Custom script: call SetUnitX(udg_Caster, GetUnitX(udg_Target))
  • Custom script: call SetUnitY(udg_Caster, GetUnitY(udg_Target))
  • Unit - Move Target instantly to CasterPoint, facing 270.00 degrees
X/Y coordinates are less accessible in the GUI editor but using Custom script you can gain access to them. A Point is literally a pair of X/Y coordinates (it has Z as well).

You forgot to clean up your memory leak:
  • Custom script: call RemoveLocation(udg_CasterPoint)
 
Last edited:
Status
Not open for further replies.
Top