tuantai120
Cool Member
- Reaction score
- 1
please have a look at my code , specially the code SetUnitFlyHeight after d.time > 4 , i want to when d.time >4 then SetUnitFlyeHeight of p and d.dummy to 0 , but it's doesn't work , please help me fix that bug (
JASS:
scope sphere initializer Init
globals
private constant integer SID = 039;A000039;
private constant integer DID = 039;h000039;
private constant integer Fly = 039;Amrf039;
private constant string SFX = "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl"
private constant real Height = 500
private constant real Period = 0.04
private constant real SPHERE_HEIGHT = 500
private constant real SPHERE_FLY_SPEED = 200
private constant real SPHERE_FALL_SPEED = 2500
private constant real TARGET_MAX_HEIGHT = 400
private constant real TARGET_MIN_HEIGHT = 350
private constant real TARGET_FLY_SPEED = 150
private constant real TARGET_FALL_SPEED = 2300
private integer TEMPINT
endglobals
private function SphereC takes nothing returns boolean
return GetSpellAbilityId() == SID
endfunction
private struct sp
unit c
unit dummy
real time
integer tick
group g
endstruct
private function SphereF takes nothing returns boolean
local sp d = TEMPINT
local unit f = GetFilterUnit()
local boolean ok = false
if IsUnitEnemy(f,GetOwningPlayer(d.c)) == true then
if IsUnitType(f,UNIT_TYPE_STRUCTURE) == false then
if IsUnitType(f,UNIT_TYPE_MAGIC_IMMUNE) == false then
if IsUnitInGroup(f,d.g) == false then
set ok = true
endif
endif
endif
endif
set f = null
return ok
endfunction
private function SphereT takes nothing returns nothing
local timer ti = GetExpiredTimer()
local sp d = GetTimerData(ti)
local real x = GetUnitX(d.dummy)
local real y = GetUnitY(d.dummy)
local real px
local real py
local unit p
local group g = CreateGroup()
set TEMPINT = d
call UnitAddAbility(d.dummy,Fly)
call SetUnitFlyHeight(d.dummy,SPHERE_HEIGHT,SPHERE_FLY_SPEED)
call GroupEnumUnitsInRange(g,x,y,400,function SphereF)
set d.time = d.time + Period
loop
set p = FirstOfGroup(g)
exitwhen p == null
call GroupRemoveUnit(g,p)
call GroupAddUnit(d.g,p)
set px = GetUnitX(p)
set py = GetUnitY(p)
call UnitAddAbility(p,Fly)
call PauseUnit(p,true)
call SetUnitFlyHeight(p,GetRandomReal(TARGET_MAX_HEIGHT,TARGET_MIN_HEIGHT),TARGET_FLY_SPEED)
if d.time >= 4 then
set d.tick = d.tick + 1
call SetUnitFlyHeight(p,GetUnitDefaultFlyHeight(p),TARGET_FALL_SPEED)
call SetUnitFlyHeight(d.dummy,GetUnitDefaultFlyHeight(d.dummy),SPHERE_FALL_SPEED)
if d.tick >=10 then
call UnitRemoveAbility(d.dummy,Fly)
call UnitRemoveAbility(p,Fly)
call KillUnit(d.dummy)
call DestroyEffect(AddSpecialEffect(SFX,px,py))
call PauseUnit(p,false)
call DestroyGroup(d.g)
call ReleaseTimer(ti)
call d.destroy()
endif
endif
endloop
call DestroyGroup(g)
set p = null
endfunction
private function SphereA takes nothing returns nothing
local sp d = sp.create()
local timer ti = NewTimer()
local unit c = GetTriggerUnit()
local real x = GetSpellTargetX()
local real y = GetSpellTargetY()
local unit dummy = CreateUnit(GetOwningPlayer(c),DID,x,y,0)
local real time = 0
call SetTimerData(ti,d)
set d.c = c
set d.dummy = dummy
set d.time = time
set d.tick = 0
set d.g = CreateGroup()
call TimerStart(ti,Period,true,function SphereT)
call BJDebugMsg("done")
set c = null
set dummy = null
endfunction
private function Init takes nothing returns nothing
local trigger ts = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(ts,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(ts,Condition(function SphereC))
call TriggerAddAction(ts,function SphereA)
endfunction
endscope