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

Set Unit Position

Status
Not open for further replies.
The purpose of this spell is to locate any friendly unit with a buff and move it to a random point within a range of the caster. A special effect is created at both the starting and ending point of the moved unit.

Currently I get "cannot convert location to real"

  • Dark Mark Summon
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Dark Summoning
    • Actions
      • Set Dark_Mark_Point_A = (Position of (Triggering unit))
      • Set Dark_Mark_Group = (Units owned by (Owner of (Triggering unit)) matching (((Matching unit) has buff Dark Mark ) Equal to True))
      • Unit Group - Pick every unit in Dark_Mark_Group and do (Actions)
        • Loop - Actions
          • Custom script: local unit Dark_Mark_Unit_A = GetEnumUnit()
          • Set Dark_Mark_Point_B = (Dark_Mark_Point_A offset by (Random real number between 0.00 and 175.00) towards (Random angle) degrees)
          • Custom script: call SetUnitX(Dark_Mark_Unit_A, udg_Dark_Mark_Point_B)
          • Custom script: call SetUnitY(Dark_Mark_Unit_A, udg_Dark_Mark_Point_B)
          • Custom script: set udg_Dark_Mark_Point_C = GetUnitLoc(Dark_Mark_Unit_A)
          • Unit - Create 1 Dummy (Dark Mark) for Neutral Passive at Dark_Mark_Point_B facing Default building facing degrees
          • Unit - Create 1 Dummy (Dark Mark) for Neutral Passive at Dark_Mark_Point_C facing Default building facing degrees
          • Custom script: set Dark_Mark_Unit_A = null
          • Custom script: call RemoveLocation (udg_Dark_Mark_Point_C)
          • Custom script: call RemoveLocation (udg_Dark_Mark_Point_B)
      • Custom script: call DestroyGroup(udg_Dark_Mark_Group)
      • Custom script: call RemoveLocation (udg_Dark_Mark_Point_A)
 
Level 3
Joined
Dec 31, 2003
Messages
42
I hope I didn't remove any functionality, but I would store the initial location, create the effect, remove the location and then store the new location, move the unit and remove the location. Finally get the new position (in case the unit winded up somewhere different because of pathing) of the unit, create the effect and remove that location.

  • Unit Group - Pick every unit in Dark_Mark_Group and do (Actions)
  • Loop - Actions
  • Set Dark_Mark_Point_B = (Position of GetEnumUnit())
  • Unit - Create 1 Dummy (Dark Mark) for Neutral Passive at Dark_Mark_Point_B facing Default building facing degrees
  • Custom script: call RemoveLocation(udg_Dark_Mark_Point_B)
  • Set Dark_Mark_Point_B = (Dark_Mark_Point_A offset by (Random real number between 0.00 and 175.00) towards (Random angle) degrees)
  • Unit - Move GetEnumUnit() to udg_Dark_Mark_Point_B
  • Custom script: call RemoveLocation(udg_Dark_Mark_Point_B)
  • Set Dark_Mark_Point_B = (Position of GetEnumUnit())
  • Unit - Create 1 Dummy (Dark Mark) for Neutral Passive at Dark_Mark_Point_B facing Default building facing degrees
  • Custom script: call RemoveLocation(udg_Dark_Mark_Point_B)
Using SetUnitX/Y is mostly useful when you move the same unit repeatedly You can then use the JASS function Atan2(y2 - y1, x2 - x1) to get the angle between the two points, and then move towards that angle with distance*Cos(a) and distance*Sin(a). It is basically what the GUI functions do when getting new locations like that.

If you're interested, this should roughly be the above code in JASS, without using locations and cleaned up. Replace 'unit' with the unit type id of your effect thingy
JASS:
local unit u = GetEnumUnit()
local player p = Player(PLAYER_NEUTRAL_PASSIVE)
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local real a = GetRandomReal(0, 2*bj_PI)
local real dist = GetRandomReal(0, 175)

call CreateUnit(p, 'unit', x, y, 0)
call SetUnitPosition(u, x + dist*Cos(a), y + dist*Sin(a))
call CreateUnit(p, 'unit', GetUnitX(u), GetUnitY(u), 0)

set u=null
set p=null

I realise I'm rambling now but maybe someone found it useful :)
 
Last edited:
  • Like
Reactions: Kam
Status
Not open for further replies.
Top