Hi everyone, I have recently started to learn JASS by checking the many posts here, reading the tutorials and opening other maps up from this site which use JASS for the custom abilities and whatnot.
I recently made a spell which creates multiple random flame strikes around the caster, and then picks the units within range of the flame strike and deals damage to them, here is the coding for the ability:
I was wondering if this will leak, and if it will be entirely MUI, I think it is except for the part with the damage being dealt since it is in relation to a GroupBJ. I will just mention the ability works exactly how I would like it to, but again I just want some feedback in regards to the code to make it as efficient, leakfree and MUI as possible.
I recently made a spell which creates multiple random flame strikes around the caster, and then picks the units within range of the flame strike and deals damage to them, here is the coding for the ability:
JASS:
scope RandomStrike initializer Init
//===========================================================================
globals
private constant integer ABILITY_ID = 'A001'
private constant string EFFECT = "Abilities\\Spells\\Human\\FlameStrike\\FlameStrike1.mdl"
private constant damagetype D_TYPE = DAMAGE_TYPE_NORMAL
private constant attacktype A_TYPE = ATTACK_TYPE_MAGIC
group rg = CreateGroup()
boolexpr filterExpr
endglobals
private function Damage takes integer level returns real
return level * 15.
endfunction
//===========================================================================
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == ABILITY_ID
endfunction
//===========================================================================
private function pick takes nothing returns nothing
local unit t = GetTriggerUnit()
local integer level = GetUnitAbilityLevel(t, ABILITY_ID)
if ( IsUnitType(GetEnumUnit(), UNIT_TYPE_STRUCTURE) == false ) and ( IsUnitType(GetEnumUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false ) and ( IsUnitAlly(GetEnumUnit(), GetOwningPlayer(t)) == false ) then
call UnitDamageTargetBJ(t, GetEnumUnit(), Damage(level), A_TYPE, D_TYPE)
endif
endfunction
//===========================================================================
private function Actions takes nothing returns nothing
local unit t = GetTriggerUnit()
local integer level = GetUnitAbilityLevel(t,ABILITY_ID)
local integer loopcount
local real xc
local real yc
local real tx
local real ty
local location rl
set loopcount = 2 * level
if loopcount >= 0 then
loop
exitwhen loopcount <= 0
set tx = GetUnitX(t)
set ty = GetUnitY(t)
set xc = GetRandomReal(-350,350)
set yc = GetRandomReal(-350,350)
set rl = Location((tx+xc), (ty+yc))
call AddSpecialEffectLoc(EFFECT, rl)
set loopcount = loopcount - 1
call TriggerSleepAction(0.15)
set rg = GetUnitsInRangeOfLocAll(215, rl)
call ForGroup(rg, function pick)
call TriggerSleepAction(0.02)
endloop
endif
call DestroyGroup(rg)
call RemoveLocation(rl)
set rg = null
set t = null
endfunction
//===========================================================================
private function Init takes nothing returns nothing
local trigger RandomStrike = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(RandomStrike, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(RandomStrike, Condition( function Conditions))
call TriggerAddAction(RandomStrike, function Actions)
endfunction
endscope