- Joined
- Sep 25, 2005
- Messages
- 71
Alright, with the exception of a few bugs (in particular, multiple instances firing simultaneously rarely create a dummy unit that sticks around and doesn't even up moving,) I've hammered out most of this spell I've been working on.
The idea is to create a fireball which travels in a line. The trick and the part I'm having issues implementing is, well, actually doing something with the fireball. Ideally, the fireball travels, and if a unit comes within range, it deals damage to that unit, kills the fireball/smoke trail.
What functions should I be looking at to find whether there's a single unit nearby/what kind of system for managing this should I use, and what kind of function am I using for actually dealing the damage? Should I have an "if" clause to make sure the execution loop stops when this situation happens?
Anyways, thanks in advance, sorry about the jumble of questions above.
The idea is to create a fireball which travels in a line. The trick and the part I'm having issues implementing is, well, actually doing something with the fireball. Ideally, the fireball travels, and if a unit comes within range, it deals damage to that unit, kills the fireball/smoke trail.
What functions should I be looking at to find whether there's a single unit nearby/what kind of system for managing this should I use, and what kind of function am I using for actually dealing the damage? Should I have an "if" clause to make sure the execution loop stops when this situation happens?
Anyways, thanks in advance, sorry about the jumble of questions above.
JASS:
globals
timer fireballTimer = CreateTimer()
real fireballInterval = .015
integer activeFireballs = 0
fireballData array fireballArray
endglobals
struct fireballData
unit caster
unit dummy
real angle
real x
real y
real speed
real maxDist
real distance
endstruct
function fireballExecution takes nothing returns nothing
local integer i = 0
local real x = 0.
local real y = 0.
local effect smoke
local fireballData localFireball = fireballData.create()
loop
exitwhen i >= activeFireballs
set localFireball = fireballArray[i]
set x = GetUnitX(localFireball.dummy) + localFireball.speed * Cos(localFireball.angle * bj_DEGTORAD)
set y = GetUnitY(localFireball.dummy) + localFireball.speed * Sin(localFireball.angle * bj_DEGTORAD)
call SetUnitBoundedX(localFireball.dummy, x)
call SetUnitBoundedY(localFireball.dummy, y)
set localFireball.distance = localFireball.distance + localFireball.speed
set smoke = AddSpecialEffect("Abilities\\Spells\\Human\\FlakCannons\\FlakTarget.mdl", x, y)
if localFireball.distance >= localFireball.maxDist then
call KillUnit(localFireball.dummy)
set activeFireballs = activeFireballs - 1
set fireballArray[i] = fireballArray[activeFireballs]
call localFireball.destroy()
endif
call DestroyEffect(smoke)
set smoke = null
set i = i + 1
endloop
if activeFireballs == 0 then
call PauseTimer(fireballTimer)
endif
endfunction
function activatedFireball takes nothing returns nothing
local unit caster = GetTriggerUnit()
local unit fireball
local player casterOwner = GetOwningPlayer(GetTriggerUnit())
local fireballData localFireball = fireballData.create()
set fireball = CreateUnit(casterOwner, 'o003', GetUnitX(caster), GetUnitY(caster), GetUnitFacing(caster))
call UnitApplyTimedLife(fireball, 'B001', .21)
call SetUnitPathing(fireball, false)
set localFireball.caster = caster
set localFireball.dummy = fireball
set localFireball.angle = GetUnitFacing(caster)
set localFireball.x = GetUnitX(caster)
set localFireball.y = GetUnitY(caster)
set localFireball.speed = 33.
set localFireball.maxDist = 700.
set localFireball.distance = 0.
set fireballArray[activeFireballs] = localFireball
if activeFireballs <= 0 then
call TimerStart(fireballTimer, fireballInterval, true, function fireballExecution)
endif
set activeFireballs = activeFireballs + 1
set caster = null
set fireball = null
set casterOwner = null
call localFireball.destroy()
endfunction
function checkFireball takes nothing returns boolean
if GetSpellAbilityId() == 'A005' then
call activatedFireball()
endif
return false
endfunction
function InitTrig_Fireball takes nothing returns nothing
local trigger localTrigVar = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( localTrigVar, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( localTrigVar, Condition( function checkFireball ) )
set localTrigVar = null
endfunction