Couple things; you do not have to calculate available power, because I believe the World does that before you can even cast the spell - then it takes away power expended. If there is a specific need to subtract even more power, then yes do it in the LUA. Otherwise you shouldn't have to.
All "parameters" are sent from the `spell_data` table. So if you have 3 params in your LUA that you plan to use, set up 3 parameters in spell_data (index_field 0, 1 and 2) with the proper data types you plan to use in the script. In these examples below, you will see 3 - 6 params used. If you need clarification on what the spell_data looks like, just ask.
Here are a couple Heal related scripts I have been using - both seem to work rather well.
Direct Heal:
Code: Select all
--[[
Script Name : Heal (Spell Type)
Script Purpose : Generic script for healing spells
Script Author : John Adams
Script Date : 2008.12.03
Script Note :
--]]
function cast(Caster, Target, HealType, HealMinVal, HealMaxVal)
-- Heal Component
if HealMinVal < HealMaxVal then
ModifyHP(Caster, math.random(HealMinVal, HealMaxVal))
else
ModifyHP(Caster, HealMinVal)
end
end
A HoT spell:
Code: Select all
--[[
Script Name : HoT (Spell Type)
Script Purpose : Generic script for heal-over-time spells
Script Author : John Adams
Script Date : 2008.12.04
Script Notes : JA: Need to determine if HoT's land instantly with the initial heal, or wait til tick()
--]]
function cast(Caster, Target, HealType, HealMinVal, HealMaxVal, HOTType, HOTMinVal, HOTMaxVal)
-- Heal component
if HealMinVal < HealMaxVal then
ModifyHP(Caster, math.random(HealMinVal, HealMaxVal))
else
ModifyHP(Caster, HealMinVal)
end
-- HoT component
if HOTType ~= nil then
-- Determine if there is a range to HoT values
if HOTMaxVal ~= nil and HOTMinVal < HOTMaxVal then
ModifyHP(Caster, math.random(HOTMinVal, HOTMaxVal))
else
ModifyHP(Caster, HOTMinVal)
end
end
end
function tick(Caster, Target, HealType, HealMinVal, HealMaxVal, HOTType, HOTMinVal, HOTMaxVal)
if HOTMaxVal ~= nil and HOTMinVal < HOTMaxVal then
ModifyHP(Caster, math.random(HOTMinVal, HOTMaxVal))
else
ModifyHP(Caster, HOTMinVal)
end
end
function remove(Caster, Target)
-- code to remove the spell
end
And a complete heal (beta heal for testers):
Code: Select all
--[[
Script Name : betaheal.lua
Script Purpose : Fast / High healing for Beta testers
Script Author : John Adams
Script Date : 2008.12.03
Script Note : This heal has an instand heal + HoT
--]]
function cast(Caster, Target, HealType, HealMinVal, HealMaxVal, EffectType, EffectMinVal, EffectMaxVal)
if HealType == "complete" then
ModifyHP(Caster, GetMaxHP(Target))
else
if HealMaxVal ~= nil and HealMinVal < HealMaxVal then
ModifyHP(Caster, math.random(HealMinVal, HealMaxVal))
else
ModifyHP(Caster, HealMinVal)
end
end
if EffectType ~= nil then
if EffectType == "hot" then
if EffectMaxVal ~= nil and EffectMinVal < EffectMaxVal then
ModifyHP(Caster, math.random(EffectMinVal, EffectMaxVal))
else
ModifyHP(Caster, EffectMinVal)
end
end
end
end
function tick(Caster, Target, HealType, HealMinVal, HealMaxVal, EffectType, EffectMinVal, EffectMaxVal)
if EffectType ~= nil then
if EffectType == "hot" then
if EffectMaxVal ~= nil and EffectMinVal < EffectMaxVal then
ModifyHP(Caster, math.random(EffectMinVal, EffectMaxVal))
else
ModifyHP(Caster, EffectMinVal)
end
end
end
end
You can see how flexible the system is. Scatman was kind enough to add functionality for the "sac"-type heals too, that cause the caster to lose HP to give to another... just set the param for `hp_req` in spell_tiers to achieve that effect.