Spell problem

tuantai120

Cool Member
Reaction score
1
How to get angle from caster unit to picked unit in this case ?
JASS:
scope thunderclap initializer Init
globals
    private constant integer SID = 'A000'
    private constant integer SDID = 'A001'
    private constant integer DID = 'h000'
    private constant string SFX = "Abilities\\Weapons\\AncientProtectorMissile\\AncientProtectorMissile.mdl"
    private constant string Order = "firebolt"
    private constant real DamageBase = 100.
endglobals

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SID
endfunction

//=====================

private function TJGetPPX takes real x, real dist, real angle returns real
    return x + dist * Cos(angle * bj_DEGTORAD)
endfunction

private function TJGetPPY takes real y, real dist, real angle returns real
    return y + dist * Sin(angle * bj_DEGTORAD)
endfunction
function AngleBetweenUnits takes unit A, unit B returns real
    return bj_RADTODEG * Atan2(GetUnitY(B) - GetUnitY(A), GetUnitX(B) - GetUnitX(A))
endfunction

//=====================

private struct tc
    unit caster
    timer t
    real dist
    real angle
    integer tick
endstruct

private function PickUnit takes nothing returns boolean
    local tc d = GetTimerData(GetExpiredTimer())
    local unit f = GetFilterUnit()
    local boolean b = IsUnitType(f,UNIT_TYPE_STRUCTURE) == false and IsUnitEnemy(f,GetOwningPlayer(d.caster)) == true and IsUnitType(f,UNIT_TYPE_FLYING) == false
    set f = null
    return b
endfunction

private function KnockBack takes nothing returns nothing
    local tc d = GetTimerData(GetExpiredTimer())
    local real x = GetUnitX(d.caster)
    local real y = GetUnitY(d.caster)
    local real px
    local real py
    local real pxx
    local real pyy
    local unit p
    local group g 
    call GroupEnumUnitsInRange(g,x,y,300,Condition(function PickUnit))
    loop
        set p = FirstOfGroup(g)
        exitwhen p == null
        set px = GetUnitX(p)
        set py = GetUnitY(p)
        set pxx = TJGetPPX(px,d.dist,d.angle)
        set pyy = TJGetPPY(py,d.dist,d.angle)
        call SetUnitPosition(p,pxx,pyy)
        call DestroyEffect(AddSpecialEffect(SFX,px,py))
        set p = null
        set d.tick = d.tick -1
        if d.tick == 0 then
            call ReleaseTimer(d.t)
            call tc.destroy(d)
        endif
    endloop
endfunction

private function Actions takes nothing returns nothing
    local tc d
    local unit caster = GetSpellAbilityUnit()
    local real x = GetUnitX(caster)
    local real y = GetUnitY(caster)
    local real dist = 300
    local real angle
    set d = tc.create()
    call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl",x,y))
    set d.caster = caster
    set d.tick = 25
    set d.dist = dist
    set d.angle = angle
    set d.t = NewTimer()
    call TimerStart(d.t,0.04,true,function KnockBack)
    set caster = null
endfunction

private function Init takes nothing returns nothing
    local trigger thunder = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(thunder,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(thunder , Condition(function Conditions))
    call TriggerAddAction(thunder,function Actions)
endfunction
endscope
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
[ljass]57.2958 * Atan2(GetUnitY(caster) - GetUnitY(picked unit), GetUnitX(caster) - GetUnitX(picked unit)) [/ljass]
 

tuantai120

Cool Member
Reaction score
1
i think pick group has wrong , it doesnt move pick unit :(
JASS:
scope thunderclap initializer Init
globals
    private constant integer SID = 'A000'
    private constant integer SDID = 'A001'
    private constant integer DID = 'h000'
    private constant string SFX = "Abilities\\Weapons\\AncientProtectorMissile\\AncientProtectorMissile.mdl"
    private constant string Order = "firebolt"
    private constant real DamageBase = 100.
endglobals

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SID
endfunction

//=====================

private function TJGetPPX takes real x, real dist, real angle returns real
    return x + dist * Cos(angle * bj_DEGTORAD)
endfunction

private function TJGetPPY takes real y, real dist, real angle returns real
    return y + dist * Sin(angle * bj_DEGTORAD)
endfunction
function AngleBetweenUnits takes unit A, unit B returns real
    return bj_RADTODEG * Atan2(GetUnitY(B) - GetUnitY(A), GetUnitX(B) - GetUnitX(A))
endfunction

//=====================

private struct tc
    unit caster
    unit dummy
    timer t
    real dist
    real angle
    integer tick
endstruct

private function PickUnit takes nothing returns boolean
    local tc d = GetTimerData(GetExpiredTimer())
    local unit f = GetFilterUnit()
    if IsUnitType(f,UNIT_TYPE_FLYING) == false and IsUnitType(f,UNIT_TYPE_STRUCTURE) == false and IsUnitEnemy(f,GetOwningPlayer(d.caster)) then
    set f = null
    return true
    endif
    return false
endfunction

private function KnockBack takes nothing returns nothing
    local tc d = GetTimerData(GetExpiredTimer())
    local unit p
    local real x = GetUnitX(d.caster)
    local real y = GetUnitY(d.caster)
    local real px
    local real py
    local real pxx
    local real pyy
    local group g 
    call GroupEnumUnitsInRange(g,x,y,300,Condition(function PickUnit))
    loop
        set p = FirstOfGroup(g)
        exitwhen p == null
        set px = GetUnitX(p)
        set py = GetUnitY(p)
        set d.angle = Atan2(y-py,x-px)
        set pxx = TJGetPPX(px,d.dist,d.angle)
        set pyy = TJGetPPY(py,d.dist,d.angle)
        call SetUnitPosition(p,pxx,pyy)
        call DestroyEffect(AddSpecialEffect(SFX,px,py))
        set p = null
        call GroupRemoveUnit(g,p)
        set d.tick = d.tick -1
        if d.tick <= 0 then
            call ReleaseTimer(d.t)
            call tc.destroy(d)
        endif
    endloop
endfunction

private function Actions takes nothing returns nothing
    local tc d
    local unit caster = GetTriggerUnit()
    local real x = GetUnitX(caster)
    local real y = GetUnitY(caster)
    local real dist = 300
    set d = tc.create()
    call BJDebugMsg("done")
    call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl",x,y))
    set d.caster = caster
    set d.tick = 25
    set d.dist = dist
    set d.t = NewTimer()
    call TimerStart(d.t,0.04,true,function KnockBack)
    set caster = null
endfunction

private function Init takes nothing returns nothing
    local trigger thunder = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(thunder,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(thunder , Condition(function Conditions))
    call TriggerAddAction(thunder,function Actions)
endfunction
endscope
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top