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

Dummy Unit movement

Level 6
Joined
Aug 26, 2016
Messages
109
I'm trying to work with projectiles and came across an error: the projectile does not fly towards the unit that is attached to the cursor. (Marked with the Target variable)


JASS:
function Trig_ShootTest_Actions2 takes nothing returns nothing
local timer TimerAct = GetExpiredTimer()
local integer id = GetHandleId(TimerAct)
local unit marine = LoadUnitHandle(Hash, id, StringHash("marine"))
local unit Target = LoadUnitHandle(Hash, id, StringHash("Target"))

local unit Dummy = LoadUnitHandle(Hash, id, StringHash("Dummy")) 
local real process = LoadReal(Hash, id, StringHash("process")) + LoadReal(Hash, id, StringHash("Speed"))
local group gACT
local unit u = null

 if process > LoadReal(Hash, id, StringHash("maxDist"))  then
 call DestroyGroup(LoadGroupHandle(Hash, id, StringHash("group")))
 call KillUnit(Dummy)
 call FlushChildHashtable(Hash, id)
 call PauseTimer(TimerAct)
 call DestroyTimer(TimerAct)
 
else

 call SaveReal(Hash, id, StringHash("process"), process)
 call SetUnitX(Dummy, GetUnitX(Dummy) + LoadReal(Hash, id, StringHash("Speed")) * Cos(LoadReal(Hash, id, StringHash("angle")) * bj_DEGTORAD))
 call SetUnitY(Dummy, GetUnitY(Dummy) + LoadReal(Hash, id, StringHash("Speed")) * Sin(LoadReal(Hash, id, StringHash("angle")) * bj_DEGTORAD))
 
 set gACT =CreateGroup()
 call GroupEnumUnitsInRange(gACT, GetUnitX(Dummy),GetUnitY(Dummy), LoadReal(Hash, id, StringHash("Aoe")), null )
 
 loop
 
  set u = FirstOfGroup(gACT)
  exitwhen u == null
  
  if GetWidgetLife(u) > 0.405 and not IsUnitInGroup(u, LoadGroupHandle(Hash, id, StringHash("group"))) then
  
      if IsUnitEnemy(u, GetOwningPlayer(marine)) then
         call UnitDamageTarget(marine, u, LoadReal(Hash, id, StringHash("Damege")), false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
         call DestroyEffect(AddSpecialEffectTarget(LoadStr(Hash, id, StringHash("BloodEfect")), u, "chest"))
      else
      
      endif
  
  endif
  
  call GroupRemoveUnit(gACT, u)
  
  endloop
  
   call DestroyGroup(gACT)
   
  endif 
set Target = null
set marine = null
set Dummy = null
set TimerAct = null
set gACT = null

endfunction


function Trig_ShootTest_Copy_Actions takes nothing returns nothing
local unit marine = gg_unit_H000_0003
local unit Target = gg_unit_n000_0005
local real xMarine = GetUnitX(marine)
local real yMarine = GetUnitY(marine)
local real xTarget = GetUnitX(Target)
local real yTarget = GetUnitY(Target)
local real angle = bj_RADTODEG * Atan2(yTarget - yMarine, xTarget - xMarine)
local unit Dummy = CreateUnit(GetOwningPlayer(marine), 'n001', xMarine, yMarine, angle)

local real maxDis = 1200
local real Damege = 50
local real Aoe = 90
local real Speed = 700

local string BloodEfect = "WeaponsandEffect/BloodDamage.mdx"

local timer TimerAct = CreateTimer()
local integer id = GetHandleId(TimerAct)
if xMarine == xTarget and yMarine == yMarine then
        set angle = GetUnitFacing(marine)
    endif

call SetUnitX(Dummy, xMarine + 50 * Cos(angle * bj_DEGTORAD))
call SetUnitY(Dummy, yMarine + 50 * Sin(angle * bj_DEGTORAD))

call SaveUnitHandle(Hash, id, StringHash("marine"), marine)
call SaveUnitHandle(Hash, id, StringHash("Target"), Target)
call SaveUnitHandle(Hash, id, StringHash("Dummy"), Dummy)

call SaveReal(Hash, id, StringHash("Damege"), Damege)
call SaveReal(Hash, id, StringHash("maxDis"), maxDis)
call SaveReal(Hash, id, StringHash("Aoe"), Aoe)
call SaveReal(Hash, id, StringHash("angle"), angle)
call SaveReal(Hash, id, StringHash("Speed"), Speed * 0.03)
call SaveStr(Hash, id, StringHash("BloodEfect"), BloodEfect)
call SaveReal(Hash, id, StringHash("process"), 0)
call SaveGroupHandle(Hash, id, StringHash("group"), CreateGroup())


call TimerStart(TimerAct, 0.03, true, function Trig_ShootTest_Actions2)

set marine = null
set Target = null
set Dummy = null
set TimerAct = null


endfunction

function Trig_ShootTest_Copy_Conditions takes nothing returns boolean  
    return BlzGetTriggerPlayerMouseButton() == MOUSE_BUTTON_TYPE_RIGHT
endfunction


//===========================================================================
function InitTrig_ShootTest_Copy takes nothing returns nothing
    set gg_trg_ShootTest_Copy = CreateTrigger(  )
    call TriggerRegisterPlayerMouseEventBJ( gg_trg_ShootTest_Copy, Player(0), bj_MOUSEEVENTTYPE_DOWN )
    call TriggerAddCondition( gg_trg_ShootTest_Copy, Condition( function Trig_ShootTest_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_ShootTest_Copy, function Trig_ShootTest_Copy_Actions )
    
endfunction
 
Top