I am learning JASS and I've made a basic fireball spell. The fireball moves fine but I can't make it deal damage yet. I struggle with the GroupEnumUnitsInRange() function. How to make it work? Here's my code:
Is there any convenient way to pass variables between functions besides hashtables? Would structs be helpful here? (if yes, how would it look like?) Could you show how to make this trigger better?
p.s. Do I need to constantly clear groups to avoid leaks or even turn off the periodic trigger when idle?
JASS:
globals
group FGroup = CreateGroup()
location array Point
unit array temp
endglobals
function Trigger_SpellFireball_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local location point1 = GetUnitLoc(u)
local location point2 = GetSpellTargetLoc()
local unit fireball = CreateUnitAtLoc(GetTriggerPlayer(), 'h021', point1, 0)
local integer cv = GetUnitUserData(fireball) // I use Unit Indexer system
call SetUnitAnimationByIndex(u, 3)
set Point[cv] = point2
set temp[cv] = fireball
call GroupAddUnit(FGroup, fireball)
set u = null
set point1 = null
set point2 = null
set fireball = null
endfunction
function Trigger_SpellFireball_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A02P'
endfunction
//===========================================================================
function InitTrig_SpellFireball takes nothing returns nothing
set gg_trg_SpellFireball = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_SpellFireball, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_SpellFireball , Condition(function Trigger_SpellFireball_Conditions))
call TriggerAddAction( gg_trg_SpellFireball, function Trigger_SpellFireball_Actions )
endfunction
JASS:
function F_damager takes nothing returns nothing
//call UnitDamageTarget(??, GetFilterUnit(), 50, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
// how do I pass the caster in here? how not to damage myself and my allies?
endfunction
function F_Callback takes nothing returns nothing
local integer cv = GetUnitUserData(GetEnumUnit())
local group damagegroup = CreateGroup()
local location point1 = GetUnitLoc(GetEnumUnit())
local location point2 = Point[cv]
local real facing = AngleBetweenPoints(point1, point2)
local real x = GetLocationX(point1) + 20 * Cos(facing * bj_DEGTORAD)
local real y = GetLocationY(point1) + 20 * Sin(facing * bj_DEGTORAD)
if DistanceBetweenPoints(point1, point2) > 20 then
call SetUnitPosition(GetEnumUnit(), x, y)
call DestroyEffect(AddSpecialEffectLoc("Abilities\\Spells\\Other\\Doom\\DoomDeath.mdl",point1))
call GroupEnumUnitsInRange(damagegroup, x,y, 250, Filter(function F_damager))
call GroupClear(damagegroup)
else
call KillUnit(GetEnumUnit())
call GroupRemoveUnit(FGroup, GetEnumUnit())
call GroupClear(damagegroup)
endif
endfunction
function Trig_SpellFireballMover_Actions takes nothing returns nothing
call ForGroup(FGroup, function F_Callback)
endfunction
//===========================================================================
function InitTrig_SpellFireballMover takes nothing returns nothing
set gg_trg_SpellFireballMover = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic( gg_trg_SpellFireballMover, 0.03 )
call TriggerAddAction( gg_trg_SpellFireballMover, function Trig_SpellFireballMover_Actions )
endfunction
Is there any convenient way to pass variables between functions besides hashtables? Would structs be helpful here? (if yes, how would it look like?) Could you show how to make this trigger better?
p.s. Do I need to constantly clear groups to avoid leaks or even turn off the periodic trigger when idle?
Last edited: