I'm trying to create some sort of a spell that works like the Goblin Landmine.
It's supposed to summon a landmine unit under the feet of the caster. This dummy unit will have a 25sec generic expiration timer but will explode after 24 seconds or whenever any enemy comes in range of it; dealing damage. It will only be able to explode at least 2 seconds after it has been placed.
For some reason the spell is not doing anything. It's not even summoning the bomb unit itself. Is there something I'm doing wrong? I am, after all, able to save the code without errors.
It's supposed to summon a landmine unit under the feet of the caster. This dummy unit will have a 25sec generic expiration timer but will explode after 24 seconds or whenever any enemy comes in range of it; dealing damage. It will only be able to explode at least 2 seconds after it has been placed.
For some reason the spell is not doing anything. It's not even summoning the bomb unit itself. Is there something I'm doing wrong? I am, after all, able to save the code without errors.
JASS:
scope DwarvenLandmine initializer init
globals
private boolexpr Bool
endglobals
private struct Data
unit caster
unit bomb
unit target
real dmg
real delay
real x
real y
group radius
static integer array Ar
static integer Total = 0
static timer Time = CreateTimer()
static method create takes unit u returns Data
local Data Dat = Data.allocate()
local player p = GetOwningPlayer(u)
set Dat.x = GetUnitX(u)
set Dat.y = GetUnitY(u)
set Dat.target = null
set Dat.caster = u
set Dat.delay = 24.
set Dat.dmg = I2R(GetHeroInt(u, true))*2.2
set Dat.bomb = CreateUnit(p, 'n00V', Dat.x, Dat.y, GetUnitFacing(u))
call UnitApplyTimedLife(Dat.bomb, 'BTLF', 25.)
if Dat.Total == 0 then
call TimerStart(Dat.Time,0.1,true,function Data.Loop)
endif
set Dat.Ar[Dat.Total] = Dat
set Dat.Total = Dat.Total + 1
set u = null
return Dat
endmethod
static method Loop takes nothing returns nothing
local Data Dat
local integer i = 0
loop
exitwhen i >= Dat.Total
set Dat = Dat.Ar[i]
set Dat.delay = Dat.delay - 0.1
if Dat.delay < 22. then
call GroupEnumUnitsInRange(Dat.radius, Dat.x, Dat.y, 200., Bool)
endif
if Dat.delay <= 0. or FirstOfGroup(Dat.radius) != null then
call DestroyEffect(AddSpecialEffect("war3mapImported\\Incendiary mortar v2.mdx", Dat.x, Dat.y))
call RemoveUnit(Dat.bomb)
call ShakeCamera(GetOwningPlayer(Dat.caster), 5.00)
loop
set Dat.target = FirstOfGroup(Dat.radius)
exitwhen Dat.target == null
call UnitDamageTargetEx(Dat.caster, Dat.target, Dat.dmg, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_SPELLFIRE, false)
call GroupRemoveUnit(Dat.radius, Dat.target)
endloop
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 .target = null
endmethod
endstruct
private function filt takes nothing returns boolean
local unit f = GetFilterUnit()
local unit u = GetTriggerUnit()
local boolean ok = GetWidgetLife(f) > .305 and IsUnitEnemy(f,GetOwningPlayer(u))
set f = null
set u = null
return ok
endfunction
private function OnCast takes nothing returns boolean
local Data Dat
local unit u
if GetSpellAbilityId() == 'A03M' then ///edit
set u = GetTriggerUnit()
set Dat = Data.create(u)
set u = null
endif
return false
endfunction
private function init takes nothing returns nothing
local trigger trig = CreateTrigger()
local integer index = 0
loop
exitwhen index >= bj_MAX_PLAYER_SLOTS
call TriggerRegisterPlayerUnitEvent(trig,Player(index),EVENT_PLAYER_UNIT_SPELL_EFFECT,BOOLEXPR_TRUE)
set index = index + 1
endloop
call TriggerAddCondition(trig, Condition(function OnCast))
set Bool = Filter(function filt)
set trig = null
endfunction
endscope