• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Spells

Zoriath

New Member
Joined
Mar 26, 2008
Messages
1,496
Reaction score
4
NOTE: I made this tutorial a long time ago, I don't know if it's correct or anything, just posting it:thumbup:.

This are the basics of what the code in the spells means.

[For this tutorial you must have decent LUA knowledge, else it would be very hard to understand.]

To start off, go to:
Code:
data/spells/scripts
Open up a script. In this case I'll do beserk.lua (exori). You'll see a script like this:

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -0.6, -30, -1.2, 0)

local arr = {
{1, 1, 1},
{1, 2, 1},
{1, 1, 1}
}

local area = createCombatArea(arr)
setCombatArea(combat, area)

function onCastSpell(cid, var)
	return doCombat(cid, combat, var)
end

Well. To make your very own basic custom spell, you'll need all of these functions. So I'll explain them to you.
Code:
local combat = createCombatObject()
It's the beginning of all spells. EVERY spell will have this in it (that is actually not 100% true). If you are a beginner, the best is to put this always in the first line of the spell.
After that you'll see this:
Code:
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
This is a 'combat parameter'. You'll see the parentheses '(' and ')'. Between this are the parameters. After the first parenthese '(' you'll see the word combat. That word refers to the first line of the spell. If a word comes after 'local' it'll be a word that you'll need later on, in parameters.
Then, after that you'll see 'COMBAT_PARAM_TYPE'. This means the spell will create a parameter type.
Ok, now you'll see: 'COMBAT_PHYSICALDAMAGE'. This is a parameter for the kind of damage. 'PHYSICALDAMAGE' Is for spells like exori and like Sudden Death. But you can also have things like 'FIREDAMAGE' or 'ENERGYDAMAGE'. These are for spells like Fire Wave (exevo flam hur) and Energy Beam (exevo vis lux).

Well, this is a bit difficult to memorise, so go to the map 'data'. In data you'll see a file called global.lua. Open it up. You'll see a very long code. For this part of my tutorial, we only need a small piece of it. That piece will look something like this:

Code:
COMBAT_NONE = 0
COMBAT_PHYSICALDAMAGE = 1
COMBAT_ENERGYDAMAGE = 2
COMBAT_POISONDAMAGE = 4 
COMBAT_FIREDAMAGE = 8
COMBAT_UNDEFINEDDAMAGE = 16
COMBAT_LIFEDRAIN = 32
COMBAT_MANADRAIN = 64
COMBAT_HEALING = 128
COMBAT_DROWNDAMAGE = 256

Well this are all the damages (and healing) that you can use in the parameter of 'COMBAT_PHYSICALDAMAGE'. I'll just give some examples of what they are.

NONE just does nothing
PHYSICALDAMAGE is for Sudden Death
ENERGYDAMAGE is for Energy Wave (exevo mort hur)
POISONDAMAGE is for Poison Storm (exevo gran mas pox)
FIREDAMAGE is for Fire Wave (exevo flam hur)
UNDEFINEDDAMAGE is just damage, not used in any spell
LIFEDRAIN drains your life (duh?)
MANADRAIN drains your mana
HEALING heals (yourself or another)
DROWNDAMAGE go to this thread for more info on 'DROWNDAMAGE', I don't know anything about it (never looked at it;)).

Then you'll see this line:
Code:
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
Well, as you see it is another parameter. Again it refers to 'local combat'. The only difference is that this is the effect of the spell. You can change that effect at 'HITAREA'. You may think: "But how would I know when it is a effect?" Well, thats pretty easy. After 'COMBAT_PARAM' (between the parentheses), and after that you'll see the word 'EFFECT'. Now this means, that it'll set a effect parameter for the next piece of text after the comma (,), which refers to the parameter of 'COMBAT_PARAM_EFFECT'. A 'effect' is in this case how the spell looks like. For example the flames of a Ultimate Explosion (exevo gran mas vis). Just the same as the previous time, go to global.lua. Search till you find some lines that look like this:

Code:
CONST_ME_DRAWBLOOD = 0
CONST_ME_LOSEENERGY = 1
CONST_ME_POFF = 2
CONST_ME_BLOCKHIT = 3
CONST_ME_EXPLOSIONAREA = 4
CONST_ME_EXPLOSIONHIT = 5
CONST_ME_FIREAREA = 6
CONST_ME_YELLOW_RINGS = 7
CONST_ME_GREEN_RINGS = 8
CONST_ME_HITAREA = 9
CONST_ME_ENERGYAREA = 10
CONST_ME_ENERGYHIT = 11
CONST_ME_MAGIC_BLUE = 12
CONST_ME_MAGIC_RED = 13
CONST_ME_MAGIC_GREEN = 14
CONST_ME_HITBYFIRE = 15
CONST_ME_HITBYPOISON = 16
CONST_ME_MORTAREA = 17
CONST_ME_SOUND_BLUE = 18
CONST_ME_SOUND_RED = 19
CONST_ME_POISONAREA = 20
CONST_ME_SOUND_YELLOW = 21
CONST_ME_SOUND_PURPLE = 22
CONST_ME_SOUND_BLUE = 23
CONST_ME_SOUND_WHITE = 24
CONST_ME_BUBBLES = 25
CONST_ME_CRAPS = 26
CONST_ME_NONE = 255

Ok, I'll just pick some out, so that you can see what it does.

HITAREA is for Beserk (exori, we've already seen that)
EXPLOSIONAREA is for Ultimate Explosion (exevo gran mas vis)
MORTAREA is for Sudden Death
ENERGYAREA is for Energy Wave (exevo mort hur)

You can just expiriment with them, then you'll find out how they look like.

Okay, then we'll see this line:
Code:
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -0.6, -30, -1.2, 0)
(You may notice that in some spells there is a line between this line and the previous one, I'll get back on that later on.)
This is the 'Hit Formula'. It calculates the hit with the magic level that you have. Again, it refers to 'local combat', that is very important. Then you'll see 'COMBAT_FORMULA_LEVELMAGIC', this means that it'll calculate the next parameters (thats how many the spell hits) togheter with the magic level. Now you'll need to know what the numbers after it mean. These are the numbers that the calculator changes into hits. -0.6 And -30 are the minimum that the spell can hit. -1.2 and 0 are the maximum. Just experiment with it.

Then we have this box thing:

Code:
local arr = {
{1, 1, 1},
{1, 2, 1},
{1, 1, 1}
}

This sais where there is going to hit. Each digit is one sqm. On a point where 0 stands, there is nothing hitted, on a point where 1 stands it'll hit with the parameters provided before. On a point where 2 stands it wont hit, and from there will the spell be casted. You can say that number 2 is you. Number 3 means actually the same, but nothing will go into that sqm. You can edit this by just putting extra lines in it, like I did here:

Code:
local arr = {
{1, 1, 0, 1, 1},
{1, 1, 1, 1, 1},
{0, 1, 2, 1, 0},
{1, 1, 1, 1, 1},
{1, 1, 0, 1, 1}
}

Now it'll hit that area where 1 stands.

The next line reads:
Code:
local area = createCombatArea(arr)
'createCombatArea(arr)' refers to 'local arr' because between the parentheses it sais arr. 'createCombatArea' Means that it'll create that area what we've just edited(with the 1's and 0's).

Next:
Code:
setCombatArea(combat, area)
This is just a standard thing in spells, if they have a area like this one. It refers to combat and to area. Very important to have this in your spell (nearly everything is important actually).

Now you'll see a function:
Code:
function onCastSpell(cid, var)

This means that it'll cast the spell, if you don't have this in your spell, you aren't able to cast the spell.

And the last two lines:
Code:
	return doCombat(cid, combat, var)
end

This just has to be in the function. Don't know really why, but I think because you won't be able to do it again.

Ok, it sometimes appears that between the 'setCombatParam' line and the 'setCombatFormula' line is another line. Most of the times that is with runes. In the Sudden Death rune it's this one:
Code:
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SUDDENDEATH)

That piece of code is a 'Distance Effect'. It amounts a sprite to the spell while it's flying. In the case of Sudden Death it is a black circle. Again: Go to global.lua and look for something like this:

Code:
CONST_ANI_SPEAR = 0
CONST_ANI_BOLT = 1
CONST_ANI_ARROW = 2
CONST_ANI_FIRE = 3
CONST_ANI_ENERGY = 4
CONST_ANI_POISONARROW = 5
CONST_ANI_BURSTARROW = 6
CONST_ANI_THROWINGSTAR = 7
CONST_ANI_THROWINGKNIFE = 8
CONST_ANI_SMALLSTONE = 9
CONST_ANI_SUDDENDEATH = 10
CONST_ANI_LARGEROCK = 11
CONST_ANI_SNOWBALL = 12
CONST_ANI_POWERBOLT = 13
CONST_ANI_POISON = 14
CONST_ANI_INFERNALBOLT = 15
CONST_ANI_NONE = 255

Again, I will explain some:

SUDDENDEATH is for Sudden Death (Duh..)
FIRE is for Great Fire Ball
ENERGY is for Energy Field

etc.

Well, this was my tutorial with the basics of spells. Hope it helped you ;)

Regards,
Zoriath
 
Some more distance effects ...


SPEAR = 0
BOLT = 1
ARROW = 2
FIRE = 3
ENERGY = 4
POISONARROW = 5
BURSTARROW = 6
THROWINGSTAR = 7
THROWINGKNIFE = 8
SMALLSTONE = 9
DEATH = 10
LARGEROCK = 11
SNOWBALL = 12
POWERBOLT = 13
POISON = 14
INFERNALBOLT = 15
CONST_ANI_HUNTINGSPEAR = 16
ENCHANTEDSPEAR = 17
REDSTAR = 18
GREENSTAR = 19
ROYALSPEAR = 20
SNIPERARROW = 21
ONYXARROW = 22
PIERCINGBOLT = 23
WHIRLWINDSWORD = 24
WHIRLWINDAXE = 25
WHIRLWINDCLUB = 26
ETHEREALSPEAR = 27
ICE = 28
EARTH = 29
HOLY = 30
SUDDENDEATH = 31
FLASHARROW = 32
FLAMMINGARROW = 33
SHIVERARROW = 34
ENERGYBALL = 35
SMALLICE = 36
SMALLHOLY = 37
SMALLEARTH = 38
EARTHARROW = 39
EXPLOSION = 40
CAKE = 41
 
Back
Top