- Joined
- Aug 14, 2020
- Messages
- 118
this is pyroblast jass spell,it works fine I need some one explain this for me, what is the job of each part.
Code:
function Pyroblast_Cond takes nothing returns boolean
return GetSpellAbilityId()=='A005'
endfunction
function Pyroblast_Move takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer h = GetHandleId(t)
local unit pyroblast = LoadUnitHandle(Hash,h,1)
local unit target = LoadUnitHandle(Hash,h,2)
local unit caster = LoadUnitHandle(Hash,h,3)
local real X1 = GetUnitX(pyroblast)
local real X2 = GetUnitX(target)
local real Y1 = GetUnitY(pyroblast)
local real Y2 = GetUnitY(target)
local real angle = Atan2(Y2 - Y1, X2 - X1)
local player PlayerCaster = GetOwningPlayer(caster)
local integer data = GetUnitUserData(caster)
local real damage = DamagePyroblast[0][data]
local real damageLow = DamagePyroblastRect[0][data]
local real dist = SquareRoot((X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1))
local real distance = 200
if GetWidgetLife( target ) >.405 then
call SetUnitFacing(pyroblast, angle*bj_RADTODEG)
call SetUnitFlyHeight(pyroblast,GetUnitFlyHeight(target),dist)
call SetUnitX(pyroblast, X1 + 2.5 * Cos(angle))
call SetUnitY(pyroblast, Y1 + 2.5 * Sin(angle))
if dist <= 10.00 then
local group G = CreateGroup()
local unit enemy
local player player1
call GroupEnumUnitsInRange(G, X1, Y1, distance, null)
loop
set enemy = FirstOfGroup(G)
player1 = GetOwningPlayer(enemy)
if IsPlayerEnemy(player1, PlayerCaster) and enemy != target then
call UnitDamageTarget( caster, enemy, damageLow, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_FIRE, null )
endif
call GroupRemoveUnit(G,enemy)
exitwhen enemy == null
endloop
call UnitDamageTarget( caster, target, damage, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_FIRE, null )
call KillUnit(pyroblast)
call GroupClear(G)
call DestroyGroup(G)
call FlushChildHashtable(Hash,h)
call PauseTimer(t)
call DestroyTimer(t)
set G = null
set player1 = null
endif
else
call UnitRemoveAbility( caster, 'A005' )
call UnitAddAbility( caster, 'A005' )
call KillUnit(pyroblast)
call FlushChildHashtable(Hash,h)
call PauseTimer(t)
call DestroyTimer(t)
endif
set t = null
set pyroblast = null
set caster = null
set target = null
endfunction
function Pyroblast_Scale takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer h = GetHandleId(t)
local unit pyroblast = LoadUnitHandle(Hash,h,1)
local unit array dummy
local unit target = LoadUnitHandle(Hash,h,2)
local unit caster = LoadUnitHandle(Hash,h,3)
local real scale = LoadReal(Hash,h,4)
local real face = GetUnitFacing(caster)
local real X1 = GetUnitX(caster) + 75 * Cos(face* bj_DEGTORAD)
local real x1 = GetUnitX(caster)
local real X2 = GetUnitX(target)
local real Y1 = GetUnitY(caster) + 75 * Sin(face* bj_DEGTORAD)
local real Y2 = GetUnitY(target)
local integer n = 0
local boolean spell = GetUnitCurrentOrder(caster) == 852119
if spell == true and IsUnitType(caster, UNIT_TYPE_STUNNED) == false or GetWidgetLife( caster ) >.405 then
local real dist = 1.50
set scale = scale + 0.05
call SetUnitScale( pyroblast, scale, scale, scale )
call SetUnitPosition(pyroblast, X1, Y1)
call SetUnitFacing(pyroblast,face)
if scale >= dist then
local timer tick = CreateTimer()
local integer l = GetHandleId(tick)
call UnitRemoveAbility( caster, 'Amrf' )
loop
exitwhen (n == 11)
set dummy[n] = LoadUnitHandle(Hash,h,5+n)
call KillUnit(dummy[n])
set dummy[n] = null
set n = n + 1
endloop
call SaveUnitHandle(Hash,l,1,pyroblast)
call SaveUnitHandle(Hash,l,2,target)
call SaveUnitHandle(Hash,l,3,caster)
call TimerStart(tick,.01,true,function Pyroblast_Move)
call FlushChildHashtable(Hash,h)
call PauseTimer(t)
call DestroyTimer(t)
set tick = null
else
call SaveReal(Hash,h,4,scale)
if scale == 0.65 then
call SetUnitAnimationByIndex(caster,5)
QueueUnitAnimation(caster,"stand")
endif
endif
set pyroblast = null
set target = null
set caster = null
set t = null
else
call UnitRemoveAbility( caster, 'A005' )
call UnitAddAbility( caster, 'A005' )
loop
exitwhen (n == 11)
set dummy[n] = LoadUnitHandle(Hash,h,5+n)
call KillUnit(dummy[n])
set dummy[n] = null
set n = n + 1
endloop
call KillUnit(pyroblast)
call FlushChildHashtable(Hash,h)
call PauseTimer(t)
call DestroyTimer(t)
set pyroblast = null
set target = null
set caster = null
set t = null
endif
endfunction
function Pyroblast takes nothing returns nothing
local unit caster = GetTriggerUnit()
local unit target = GetSpellTargetUnit()
local timer t = CreateTimer()
local integer h = GetHandleId(t)
local real face = GetUnitFacing(caster)
local player PlayerCaster = GetOwningPlayer(caster)
local real scale = 1.0
local real x = GetUnitX(caster) + 75 * Cos(face* bj_DEGTORAD)
local real x1 = GetUnitX(caster)
local real y = GetUnitY(caster) + 75 * Sin(face* bj_DEGTORAD)
local real y1 = GetUnitY(caster)
local unit pyroblast = CreateUnit( PlayerCaster, 'h001', x, y, face )
local unit array dummy
local integer i = 'h007'
local integer l = 0
loop
exitwhen (l == 11)
if (l == GetPlayerId(PlayerCaster) and GetLocalPlayer() == PlayerCaster) then
i = 'h004'
endif
set dummy[l] = CreateUnit( Player(l), i, x, y, face )
call SetUnitTimeScale( dummy[l], 0.50 )
call SetUnitScale( dummy[l], 1.5, 1, 1 )
call SaveUnitHandle(Hash,h,5+l,dummy[l])
set i = 'h007'
set dummy[l] = null
set l = l + 1
endloop
call SetUnitPathing( pyroblast, false )
call SetUnitScale( pyroblast, scale, scale, scale )
call SaveUnitHandle(Hash,h,1,pyroblast)
call SaveUnitHandle(Hash,h,2,target)
call SaveUnitHandle(Hash,h,3,caster)
call TimerStart(t,.05,true,function Pyroblast_Scale)
set t = null
set pyroblast = null
set caster = null
set target = null
endfunction
//===========================================================================
function InitTrig_Pyroblast takes nothing returns nothing
set gg_trg_Pyroblast = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Pyroblast, EVENT_PLAYER_UNIT_SPELL_CHANNEL )
call TriggerAddCondition( gg_trg_Pyroblast, Condition( function Pyroblast_Cond ) )
call TriggerAddAction( gg_trg_Pyroblast, function Pyroblast )
endfunction [\CODE]