- Joined
- Mar 9, 2023
- Messages
- 75
Hi! I have a really bizarre problem with my code and I'm hoping that someone might see an issue.
This function simply activates when an ability casts, then finds a target. The unit variable is returned and a dummy is created to cast a sleep spell on the target. It correctly finds a target, so the debugging properly triggers (e.g. target unit: 'generic hero'), and "dummy created".
Here is the ability:
Here's the FindClosestEnemy function in case that's the problem:
,
There is nothing wrong with the dummy either, it has 3.0 turn rate and works perfectly for everything else. I have also tried some other abilities for the dummy to cast but nothing has worked yet. Help is appreciated!
This function simply activates when an ability casts, then finds a target. The unit variable is returned and a dummy is created to cast a sleep spell on the target. It correctly finds a target, so the debugging properly triggers (e.g. target unit: 'generic hero'), and "dummy created".
JASS:
function DoomLordSleep_Actions takes nothing returns nothing
local unit caster = GetTriggerUnit()
local unit dammy
local unit target
local real x
local real y
set x = GetUnitX(caster)
set y = GetUnitY(caster)
set target = FindClosestEnemy(caster)
if target != null then
call DisplayTextToForce(GetPlayersAll(), "Target unit: " + GetUnitName(target))
set dammy = CreateUnit(GetOwningPlayer(caster), 'n00S', x, y, GetUnitFacing(target))
if dammy != null then
call DisplayTextToForce( GetPlayersAll(), ( "Dummy created" ) )
endif
call UnitAddAbility(dammy,'A00J')
call IssueTargetOrder(dammy,"sleep",target)
call UnitApplyTimedLifeBJ(3.00, 'BTLF', dammy)
endif
set caster = null
set target = null
set dammy = null
endfunction
Here is the ability:
Here's the FindClosestEnemy function in case that's the problem:
,
JASS:
function FindClosestEnemy takes unit caster returns unit
local unit target
local unit result
local group g = CreateGroup()
local real x = GetUnitX(caster)
local real y = GetUnitY(caster)
local real minDistance = 9999.0
local real distance
call GroupEnumUnitsInRange(g, x, y, 6000, function AGRO)
loop
set target = FirstOfGroup(g)
exitwhen target == null
set distance = SquareRoot(Pow(x - GetUnitX(target), 2) + Pow(y - GetUnitY(target), 2))
if distance < minDistance then
set minDistance = distance
set result = target
endif
call GroupRemoveUnit(g, target)
endloop
call DestroyGroup(g)
if result != null then
call DisplayTextToForce( GetPlayersAll(), ( "There is a target" ) )
endif
return result
endfunction
There is nothing wrong with the dummy either, it has 3.0 turn rate and works perfectly for everything else. I have also tried some other abilities for the dummy to cast but nothing has worked yet. Help is appreciated!