Code: Select all
projectiles = {}
function addProjectileEffect(projectile,effectName,speed,onHitEffectName)
local timer = spawn('timer',projectile.level,projectile.x,projectile.y,projectile.facing)
local effect = spawn('fx',projectile.level,projectile.x,projectile.y,projectile.facing)
projectiles[timer.id] = {}
projectiles[timer.id].projectile_id = projectile.id
projectiles[timer.id].effect_id = effect.id
projectiles[timer.id].level = projectile.level
projectiles[timer.id].x = 0
projectiles[timer.id].y = 0
projectiles[timer.id].facing = projectile.facing
projectiles[timer.id].onHitEffect= onHitEffectName
local dx,dy = getForward(projectile.facing)
dy = -1 * dy
projectiles[timer.id].x = dx * 0.5
projectiles[timer.id].y = dy * 0.5
timer:addConnector('activate','fxScripts','move_effect')
timer:setTimerInterval(0.5/speed)
local light = getLightPreset(effectName)
if light then
effect:setLight(unpack(light))
end
effect:translate(0.5*dx,1,0.5*dy)
effect:setParticleSystem(effectName)
timer:activate()
return effect
end
function addProjectileManualHit(caster, projectile, damageAmount, damageType, radius)
for key,value in pairs(projectiles) do
if value.projectile_id == projectile.id then
if caster then
projectiles[key].caster = caster:getOrdinal()
end
projectiles[key].damage = damageAmount
projectiles[key].damageType = damageType
projectiles[key].radius = radius
end
end
end
function getLightPreset(preset)
--FX:setLight(red, green, blue, brightness, range, time, castShadow)
local s = {}
s['fireball'] = {1, 0.5, 0.25,15,7,200,true}
s['fireball_hit'] = {1, 0.5, 0.25,40,7,1,true}
s['magic_missile'] = {1, 1, 1,15,7,200,true}
s['poison_bolt'] = {0.25, 0.6, 0.2,4,4,200,true}
s['lightning_bolt'] = {0.25, 0.5, 1,30,5,1,true}
s['lightning_bolt_hit'] = {0.25, 0.5, 1,100,5,0.5,true}
s['magic_missile_hit'] = {1, 1, 1,40,10,1,true}
s['wizards_fire'] = {1, 0.9, 0.5,40,10,1,true}
s['wizards_life_fire'] = {1, 1, 1,120,10,1,true}
s['wizards_fire_hit'] = {1, 1, 0.95, 150,10,0.6,true}
local l = s[preset]
if not l then
l = {0, 0, 0, 0, 0, 0, false}
end
return l
end
function move_effect(timer)
local e = projectiles[timer.id]
local p = findEntity(e.projectile_id)
local fx = findEntity(e.effect_id)
if not p then
if e.onHitEffect then
local ohfx = spawn('fx',e.level,e.px,e.py,e.facing)
ohfx:setParticleSystem(e.onHitEffect)
ohfx:translate(0, 1, 0)
local light = getLightPreset(e.onHitEffect)
if light then
ohfx:setLight(unpack(light))
end
end
projectiles[timer.id] = nil
timer:deactivate()
timer:destroy()
fx:destroy()
return
end
e.px = p.x
e.py = p.y
fx:translate(e.x,0,e.y)
end