Hi,
This is my first vJass spell and for some reason it won't do as I want it to, in fact, nothing happens at all. It parses, so I guess I must have made some error on my side, but I can't find it atm.
The spell is supposed (at first, for testing) to pick every unit in a 500 aoe, damage every unit in this aoe for 125 damage per level and spawn 1 + drain damage/350 units
The spell itself is based on channel, aoe of 500, point target.
UNIT1-5 are the unit types to be spawned for spell level 1-5.
Most important would be to know what I did wrong, I know that I still have some leaks in there, might have some variables too much, and I'm sure I could do the 5 "if"s somehow better, but getting the spell to work has priority.
This is my first vJass spell and for some reason it won't do as I want it to, in fact, nothing happens at all. It parses, so I guess I must have made some error on my side, but I can't find it atm.
The spell is supposed (at first, for testing) to pick every unit in a 500 aoe, damage every unit in this aoe for 125 damage per level and spawn 1 + drain damage/350 units
The spell itself is based on channel, aoe of 500, point target.
UNIT1-5 are the unit types to be spawned for spell level 1-5.
Most important would be to know what I did wrong, I know that I still have some leaks in there, might have some variables too much, and I'm sure I could do the 5 "if"s somehow better, but getting the spell to work has priority.
JASS:
scope DrainDoerkness initializer init
globals
private constant integer SPELLID=039;A00N039;
private constant integer UNIT1=039;h003039;
private constant integer UNIT2=039;h004039;
private constant integer UNIT3=039;h005039;
private constant integer UNIT4=039;h006039;
private constant integer UNIT5=039;h002039;
private constant attacktype ATKTYPE = ATTACK_TYPE_CHAOS
private constant damagetype DMGTYPE = DAMAGE_TYPE_UNIVERSAL
private constant weapontype WPNTYPE = WEAPON_TYPE_WHOKNOWS
private player TempPlayer
endglobals
private function conditions takes nothing returns boolean
return GetSpellAbilityId() == SPELLID
endfunction
private function unitfilter takes nothing returns boolean
return IsUnitEnemy(GetFilterUnit(), TempPlayer) == true and GetWidgetLife(GetFilterUnit()) > 0.405
endfunction
private function actions takes nothing returns nothing
local location targetloc=GetSpellTargetLoc()
local player p=GetOwningPlayer(GetTriggerUnit())
local group g=CreateGroup()
local unit u
local unit damager=GetTriggerUnit()
local real draincount
local integer lvl=GetUnitAbilityLevel(u, 039;A00N039;)
local integer spawncount
local integer unittospawn
set TempPlayer=p
call GroupEnumUnitsInRangeOfLoc(g, targetloc, 500, Condition(function unitfilter))
loop
set u=FirstOfGroup(g)
exitwhen u==null
call GroupRemoveUnit(g, u)
set draincount=draincount+(125*lvl)
call UnitDamageTarget(damager, u, 125*lvl, true, true, ATKTYPE, DMGTYPE, WPNTYPE)
endloop
set spawncount=1+R2I(draincount)/350
if lvl==1 then
set unittospawn=UNIT1
elseif lvl==2 then
set unittospawn=UNIT2
elseif lvl==3 then
set unittospawn=UNIT3
elseif lvl==4 then
set unittospawn=UNIT4
elseif lvl==5 then
set unittospawn=UNIT5
endif
loop
call CreateUnitAtLoc(p, unittospawn, targetloc, 270)
set spawncount=spawncount-1
exitwhen spawncount <=0.9
endloop
call DestroyGroup(g)
call RemoveLocation(targetloc)
set damager=null
endfunction
//===========================================================================
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function conditions))
call TriggerAddAction(t, function actions)
endfunction
endscope