Tutorials:Basic Lua Scripting - Spell Scripts
- Last edited 10 years ago by Vlash Nytefall
Tutorials:Basic Lua Scripting - Spell Scripts
Return to: Main Page | Tutorials | Portal | Forum | Project Manager | Bug Tracker
Spell scripts are what make spells work, if you want to have a spell do anything beyond the animation you will need to make a spell script. This tutorial will cover making a simple spell, it will not cover lua basics, for that see Foof's Scripting Fundamentals, it will also not cover inserting data into the database.
Functions
This is what the server will call and what makes every thing work. The first and second parameters will be provided by the server, the first is the caster of the spell, the second is the target of the spell. There are three major functions for spells, cast, tick, and remove.
Cast
The cast function is called when a spell finishes casting and is ready to apply its effects, this must be included in all spell scripts
function cast(Caster, Target) end
Tick
The tick function is called when a spell needs to apply multiple effects, like damage over time spells
function tick(Caster, Target) end
Remove
The remove function is called when the spell is canceled or removed from the target, this is where you would remove any stat bonuses from buffs
function remove(Caster, Target) end
Data
Any data added to a spell is passed to the functions as additional parameters take data for solar flare for an example
There are 3 values (3, 14, 27) so all the above functions will be given 3 extra parameters. These extra parameters can be named what ever you want but it is best to name them for what they do, in this case the first value is damage type, the second is the minimum damage the spell will do and the third is the max damage the spell will do so the functions would now look something like this
function cast(Caster, Target, DmgType, MinDmg, MaxDmg) end function tick(Caster, Target, DmgType, MinDmg, MaxDmg) end function remove(Caster, Target, DmgType, MinDmg, MaxDmg) end
Direct Damage Spell
Lets continue with solar flare example, it is a simple direct damage spell with nothing special. As there is no tick and nothing to remove those functions do not need to be included so all this script will have is a cast function, assuming the data shown above you would start off with this
function cast(Caster, Target, DmgType, MinDmg, MaxDmg) end
Now lets make the spell damage the target, looking at all the LUA functions we will find SpellDamage(), looking at the details on that page we will see that this function requires 4 parameters and has 2 optional parameters, we do not need the extra parameters so they will be left of we will just use the 4 required parameters. According to that page the first parameter is the spawn who will take damage, so the spells target given by the second parameter in the cast function. The second parameter is the damage type we will do, third is the minimum damage to do, and the forth is the maximum damage to do. So using the parameters given in the cast function it would look like this
SpellDamage(Target, DmgType, MinDmg, MaxDmg)
So the final spell script would be
function cast(Caster, Target, DmgType, MinDmg, MaxDmg)
SpellDamage(Target, DmgType, MinDmg, MaxDmg)
end
And that is it, you now have a functional direct damage spell.
Damage Over Time Spell
TODO
Buff spell
TODO
