- Joined
- Apr 6, 2008
- Messages
- 760
been working on this shit spell for a long time now and i can't get it work properly :/. the problem is that the spell will move the wrong way.
(ignore the codes crappyness)
(ignore the codes crappyness)
JASS:
scope meteor initializer init
private struct Data
unit caster
unit dummy
real PosX
real PosY
real PosZ
real startX
real startY
real startZ
real speedX
real speedY
real speedZ
real endtime
real time
real cos
real sin
static integer array Ar
static integer Total = 0
static timer Time = CreateTimer()
static method create takes unit u,location Tloc returns Data
local Data Dat = Data.allocate()
local real StartX = GetUnitX(u)
local real StartY = GetUnitY(u)
local real StartZ = 500
local real endX = GetLocationX(Tloc)
local real endY = GetLocationY(Tloc)
local real endZ = 0
local real distX = endX - StartX
local real distY = endY - StartY
local real distZ = endZ - StartZ
local real angle = Atan2(distY,distX)
local real dist = SquareRoot((distX*distX)+(distY*distY)+(distZ*distZ))
set Dat.caster = u
set Dat.startX = StartX
set Dat.startY = StartY
set Dat.startZ = 500.
set Dat.endtime = dist/300
set Dat.speedX = distX / Dat.endtime
set Dat.speedY = distY / Dat.endtime
set Dat.speedZ = distZ / Dat.endtime
set Dat.time = 0.
set Dat.cos = Cos(angle)
set Dat.sin = Sin(angle)
set Dat.dummy = CreateUnit(GetOwningPlayer(Dat.caster),'hfoo',StartX,StartY,angle*bj_RADTODEG)
call UnitAddAbility(Dat.dummy,'Amrf')
call SetUnitFlyHeight(Dat.dummy,500,0.)
call UnitRemoveAbility(Dat.dummy,'Amrf')
if Dat.Total == 0 then
call TimerStart(Dat.Time,.03,true,function Data.Loop)
endif
set Dat.Ar[Dat.Total] = Dat
set Dat.Total = Dat.Total + 1
call RemoveLocation(Tloc)
set Tloc = null
set u = null
return Dat
endmethod
static method Loop takes nothing returns nothing
local Data Dat
local integer i = 0
local real x
local real y
local real z
loop
exitwhen i >= Dat.Total
set Dat = Dat.Ar[i]
set Dat.time = Dat.time + .03
if Dat.time < Dat.endtime then
set x = Dat.startX + Dat.speedX * Dat.time
set y = Dat.startY + Dat.speedY * Dat.time
set z = Dat.startZ + Dat.speedZ * Dat.time
call SetUnitX(Dat.dummy,x * Dat.cos)
call SetUnitY(Dat.dummy,y * Dat.sin)
call SetUnitFlyHeight(Dat.dummy,z,0.)
else
set Dat.Total = Dat.Total - 1
set Dat.Ar[i] = Dat.Ar[Dat.Total]
set i = i - 1
call Dat.destroy()
endif
set i = i + 1
endloop
if Dat.Total == 0 then
call PauseTimer(Dat.Time)
endif
endmethod
method onDestroy takes nothing returns nothing
set .caster = null
set .dummy = null
endmethod
endstruct
private function OnCast takes nothing returns boolean
local unit u
local location Tloc
if GetSpellAbilityId()=='A04Q' then
set u = GetTriggerUnit()
set Tloc = GetSpellTargetLoc()
call Data.create(u,Tloc)
call RemoveLocation(Tloc)
set u = null
set Tloc = null
endif
return false
endfunction
private function init takes nothing returns nothing
local trigger Trig = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(Trig,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(Trig,Filter(function OnCast))
set Trig = null
endfunction
endscope
Last edited: