- Reaction score
- 91
I also noticed this in my last script:
Will look over the mistakes you pointed and going to edit if there are still some problems...
EDIT: Now the damage is instant - the snippet doesn't wait for the missile at all. I also noticed that the timer isn't paused in the end.
EDIT2: And only the first assigned instance of the struct causes damage (I mean the first unit that casts the spell will deal damage, other MDs after it do nothing). Shouldn't it be better if I used dynamic timers?
Will look over the mistakes you pointed and going to edit if there are still some problems...
EDIT: Now the damage is instant - the snippet doesn't wait for the missile at all. I also noticed that the timer isn't paused in the end.
EDIT2: And only the first assigned instance of the struct causes damage (I mean the first unit that casts the spell will deal damage, other MDs after it do nothing). Shouldn't it be better if I used dynamic timers?
JASS:
library MD
//===========================================================================
// CONFIGURE IF NECESSARY
//===========================================================================
globals
// Period of the timer.
private constant real PERIOD = 0.03125
// Minimum damage required for the unit to be damaged.
// If it's less than 100 then the unit will be hurt,
// else the damaging will be delayed until the condition is met.
private constant real LEAST_RANGE = 100.
endglobals
//===========================================================================
private keyword Data
globals
private Data array D
private integer I = 0
private timer t = CreateTimer()
endglobals
private struct Data
unit cast
unit targ
real dmg
real x
real y
real s
attacktype at
damagetype dt
static method create takes unit cast, unit targ, real dmg, real speed, attacktype at, damagetype dt returns Data
local Data d = Data.allocate()
set d.cast = cast
set d.targ = targ
set d.dmg = dmg
set d.s = speed
set d.at = at
set d.dt = dt
return d
endmethod
endstruct
private function Callback takes nothing returns nothing
local Data d
local integer i = 0
local real x1
local real y1
local real x2
local real y2
local real xx
local real yy
local real r
local real tr
loop
exitwhen i > I
set d = D<i>
set x1 = d.x
set y1 = d.y
set x2 = GetUnitX(d.targ)
set y2 = GetUnitY(d.targ)
set xx = x1 - x2
set yy = y1 - y2
set r = SquareRoot(xx * xx + yy * yy)
//set tr = r / d.s
call BJDebugMsg("calculated range, ifs")
if r < LEAST_RANGE then
if IsUnitVisible(d.targ, GetOwningPlayer(d.cast)) then
if not IsUnitInvisible(d.targ, GetOwningPlayer(d.cast)) then
if GetWidgetLife(d.targ) > 0.405 then
call UnitDamageTarget(d.cast, d.targ, d.dmg, true, true, d.at, d.dt, WEAPON_TYPE_WHOKNOWS)
endif
endif
endif
call BJDebugMsg("d.destroy()")
call d.destroy()
set D<i> = D[ I ]
set I = I - 1
else
call BJDebugMsg("d.x = x2; d.y = y2")
set d.x = x2
set d.y = y2
endif
if I == 0 then
call BJDebugMsg("Paused timer")
call PauseTimer(t)
endif
call BJDebugMsg("i = i + 1")
set i = i + 1
endloop
endfunction
public function Start takes unit cast, unit targ, real dmg, real speed, attacktype at, damagetype dt returns nothing
local Data d = Data.create(cast, targ, dmg, speed, at, dt)
local real x1 = GetUnitX(d.cast)
local real y1 = GetUnitY(d.cast)
local real x2 = GetUnitX(d.targ)
local real y2 = GetUnitY(d.targ)
local real xx = x1 - x2
local real yy = y1 - y2
local real r = SquareRoot(xx * xx + yy * yy)
local real tr = r / d.s
set d.x = x2
set d.y = y2
set D[ I ] = d
set I = I + 1
if I == 1 then
call BJDebugMsg("Timer started")
call TimerStart(t, PERIOD, false, function Callback)
endif
endfunction
endlibrary
</i></i>