HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

On second teleport the target is moved too

02-28-2010, 03:21 AM#1
Saishy
I have a spell that blinks the unit twice to a target unit, stunning the first time and damaging on second blink, to not interrupt animations, I'm using SetUnitX/Y and preplacing a footman.

But, on the second blink (after timer) the target is also moved away!, wtf?

Collapse JASS:
scope SouRyuSen initializer Init_Souryusen

globals
    private constant integer ID = 'A01M'
    private constant integer DUMMY = 'hfoo'
    private constant integer STUN = 'A03B'
    private constant real RANGE = 600
    private constant string EFFECT = "Abilities\\Weapons\\LordofFlameMissile\\LordofFlameMissile.mdl"
    private constant string MESSAGE = "Sou Ryu Sen!"
endglobals

private struct souryusen_data
    unit caster
    unit target
    player play
    integer level
    real damage
    real x
    real y
endstruct

function Souryusen_Conditions takes nothing returns boolean
    return (GetSpellAbilityId() == ID)
endfunction

function Souryusen_Repeat takes nothing returns nothing
    local souryusen_data s = GetTimerData(GetExpiredTimer())
    local unit tu
    local real x = GetUnitX(s.target)
    local real y = GetUnitY(s.target)
       
    call DisplayText(s.caster, MESSAGE, 1)
    set tu = CreateUnit(s.play, DUMMY, x, y, 0)
    set x = GetUnitX(tu)
    set y = GetUnitY(tu)
    call RemoveUnit(tu)
    call SetUnitX(s.caster, x)
    call SetUnitY(s.caster, y)
    
    if TargetCheck(s.caster, s.target) then
        if SpellHit(s.caster, s.target, ID) then
            call UnitDamageTargetEx(s.caster, s.target, s.damage, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_SPELL, false, false)
        endif
    endif
                
    set tu = null
    set s.caster = null
    set s.target = null
    set s.play = null
    call s.destroy()
    call ReleaseTimer(GetExpiredTimer())
endfunction

function Souryusen_Actions takes nothing returns nothing
    local souryusen_data s = souryusen_data.create()
    local timer t
    local unit tu
    local unit minunit = null
    local group ngroup = CreateGroup()
    local real x
    local real y
    local real dist
    local real mindist = RANGE
    local xecast xc
    set s.caster = GetTriggerUnit()
    set s.target = GetSpellTargetUnit()
    set s.level = GetUnitAbilityLevel(s.caster, ID)
    set s.damage = GetHeroAgi(s.caster, true)
    set s.play = GetOwningPlayer(s.caster)
    set x = GetUnitX(s.target)
    set y = GetUnitY(s.target)
      
    set tu = CreateUnit(s.play, DUMMY, x, y, 0)
    set x = GetUnitX(tu)
    set y = GetUnitY(tu)
    call RemoveUnit(tu)
    call SetUnitX(s.caster, x)
    call SetUnitY(s.caster, y)
    set s.x = GetUnitX(s.caster)
    set s.y = GetUnitY(s.caster)
        
    if TargetCheck(s.caster, s.target) then
        if SpellHit(s.caster, s.target, ID) then
            set xc = xecast.createBasicA(STUN, 852095, s.play)
            set xc.level = s.level
            set xc.recycledelay = 1
            call xc.castOnTarget(s.target)
        endif
    endif
    
    call GroupEnumUnitsInRange(ngroup, s.x, s.y, RANGE, null)
    loop
        set tu = FirstOfGroup(ngroup)
        exitwhen tu == null
        if (tu != s.target) and IsUnitType(tu, UNIT_TYPE_HERO) and TargetCheck(s.caster, tu) and IsUnitVisible(tu, s.play) and SpellHit(s.caster, tu, ID) then
            set x = GetUnitX(tu) - s.x
            set y = GetUnitY(tu) - s.y
            set dist = SquareRoot(x * x + y * y)
            if (dist < mindist) then
                set minunit = tu
                set mindist = dist
            endif
        endif
        call GroupRemoveUnit(ngroup, tu)
    endloop
    
    if (minunit != null) then
        set s.target = minunit
    endif
    
    call DestroyGroup(ngroup)
    set ngroup = null
    set minunit = null
    
    set t = NewTimer()
    call SetTimerData(t, s)
    call TimerStart(t, 0.1, false, function Souryusen_Repeat)
endfunction

//===========================================================================
function Init_Souryusen takes nothing returns nothing
    local trigger trg_Souryusen = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(trg_Souryusen, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(trg_Souryusen, Condition(function Souryusen_Conditions))
    call TriggerAddAction(trg_Souryusen, function Souryusen_Actions )
    set trg_Souryusen = null
endfunction

endscope

Thanks in advance