• 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!

Tutorial:Multiple effects, and understanding of lua scripts

Dixter

Amateur Web Developer
Joined
Mar 31, 2009
Messages
660
Reaction score
11
Ok this is my first tutorial so don't post bad comments, I'm not the best scripter in the world but I know a lot of people look for this and I happen to understand it so here it goes ;p.

Here is a my script,i edited so people wouldn't use the same effects ;p, and I will explain everything in it

Code:
local combat1 = createCombatObject()
setCombatParam(combat1, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
setCombatParam(combat1, COMBAT_PARAM_EFFECT, [B]1[/B])
setCombatParam(combat1, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SUDDENDEATH)
setCombatFormula(combat1, COMBAT_FORMULA_LEVELMAGIC, -0.6, 0, -1.1, 0)

local combat2 = createCombatObject()
setCombatParam(combat2, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat2, COMBAT_PARAM_EFFECT, [B]2[/B])

setCombatFormula(combat2, COMBAT_FORMULA_LEVELMAGIC, -0.6, 0, -1.1, 0)

local combat3 = createCombatObject()
setCombatParam(combat3, COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
setCombatParam(combat3, COMBAT_PARAM_EFFECT, [B]3[/B])
setCombatFormula(combat3, COMBAT_FORMULA_LEVELMAGIC, -0.6, 0, -1.1, 0)

local combat4 = createCombatObject()
setCombatParam(combat4, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat4, COMBAT_PARAM_EFFECT, [B]4[/B])

setCombatFormula(combat4, COMBAT_FORMULA_LEVELMAGIC, -0.6, 0, -1.1, 0)

local combat5 = createCombatObject()
setCombatParam(combat5, COMBAT_PARAM_TYPE, COMBAT_EARTHDAMAGE)
setCombatParam(combat5, COMBAT_PARAM_EFFECT, [B]5[/B])

setCombatFormula(combat5, COMBAT_FORMULA_LE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0, 0, 0, 0},
{0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0},
{0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0},
{0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0},
{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
}


arr4 = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0},
{0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 3, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0},
{0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}


arr5 = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 3, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}


local area1 = createCombatArea(arr1)
local area2 = createCombatArea(arr2)
local area3 = createCombatArea(arr3)
local area4 = createCombatArea(arr4)
local area5 = createCombatArea(arr5)

setCombatArea(combat1, area1)
setCombatArea(combat2, area2)
setCombatArea(combat3, area3)
setCombatArea(combat4, area4)
setCombatArea(combat5, area5)



local function onCastSpell1(parameters)
doCombat(parameters.cid, combat1, parameters.var)
end

local function onCastSpell2(parameters)
doCombat(parameters.cid, combat2, parameters.var)
end

local function onCastSpell3(parameters)
doCombat(parameters.cid, combat3, parameters.var)
end

local function onCastSpell4(parameters)
doCombat(parameters.cid, combat4, parameters.var)
end

local function onCastSpell5(parameters)
doCombat(parameters.cid, combat5, parameters.var)
end






function onCastSpell(cid, var)
local parameters = { cid = cid, var = var}
addEvent(onCastSpell1, 0, parameters)
addEvent(onCastSpell2, 150, parameters)
addEvent(onCastSpell3, 300, parameters)
addEvent(onCastSpell4, 450, parameters)
addEvent(onCastSpell5, 600, parameters)
return TRUE
end

Ok first of all "local combat1" means that every time you write combat1 somewhere it will read it as "createCombatObject" and same goes for anything else that has "local" so like "local min = 10000000" would mean that you could just write "min" in your script instead of writing 10000000 every time.
-----------------------------------------------------------------

setCombatParam(combat1, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)


This is the kind of DAMAGE the enemy will take, see that "combat1" in there, if we didnt make "local combat1" we would have to write createCombatObject every time. createCombatObject is pretty much self explanatory, it creates the "combat" which is the damage type, effect type, and damage amount all put together.
-----------------------------------------------------------------

setCombatParam(combat1, COMBAT_PARAM_EFFECT, 1)

This is what kind of EFFECT the attack will have, for example an energy effect or fire effect, this has nothing to do with the kind of damage the enemy takes.
Now you may be wondering "what kind of effect is 1"

Here's a link for a spell effect chart that will tell you what each effect number will look like in game.

Spell effect chart - OpenTibia Fans
-----------------------------------------------------------------

setCombatParam(combat1, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SUDDENDEATH)

This is only for the rune, if this was a spell we wouldnt need this because you would say the spell and the effects would happen. I only added one because I only want one shot for all 5 effects. When you use this rune on somebody it will shoot like a sudden death rune(the black thing flies across the screen). you can also erase "CONST_ANI_SUDDENDEATH" and put an effect number, to find out what the effects looks like refer to that link I gave you ;p.
----------------------------------------------------------------

setCombatFormula(combat1, COMBAT_FORMULA_LEVELMAGIC, -0.6, 0, -1.1, 0)

Now this is a little more complicated ;p. This is how much the rune will actually HIT(damage amount). LEVELMAGIC in this case is the main skill for the rune. "-0.6, 0, -1.1, 0)" The first number is your multiplier of your MAIN skill(the one you set in the script) which in this case is magic level. The second number is the minimum damage be(be sure to put a "-" sign or else you will heal the enemy) dealt by the rune for THAT effect.
The third number is the multiplier of your character level. The fourth number is the maximum damage done by THAT effect(also be sure to put a "-" sign). you can leave the max damage blank, and the minimum, as long as u have at least one multiplier it will still make damage, if u just want the effect to hit 50-100 leave the multiplies 0 and make the second and fourth numbers 50 and 100.
-----------------------------------------------------------------

Make as many of those as you want for as many effects as you want. But remember you have to change the combat"number" for each one, like "combat1","combat2","combat3" and so on.
-----------------------------------------------------------------

arr1 = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 3, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}

This is simply how the effect will look in game. the 1's are where it hits, and the 0's are where it doesn't. the "3" is the center. For example if you make an cross 5 sqms up and 5 sqms down, than that is how THAT effect will look like in game.

Make one of these for each combat you made. Also change the numbers, EXAMPLE: arr1, arr2, arr3, and so on.
-----------------------------------------------------------------

This is where it all starts coming together.

local area1 = createCombatArea(arr1)

This actually CREATES "arr1". Treat the server as if its a small child, you have to tell it to do EVERYTHING. There's that "local" again, so now every time we write area1 the server will read it as "createCombatArea(arr1)"

Now you have to make one of these for each effect and "arr" you made. also be sure to change the numbers. EXAMPLE: local area1, local area2, local area3 and so on.
-----------------------------------------------------------------

setCombatArea(combat1, area1)

This is what actually SETS the "combat1"(this is what we made in the beginning) as A combat. This is damage amount, damage type, effect type etc...
It also SETS area1 as the area it will use in game (remember the "cross")

Remember to make one for each of your combats and areas(number of combats and areas should be the same).
-----------------------------------------------------------------

local function onCastSpell1(parameters)
doCombat(parameters.cid, combat1, parameters.var)
end

This makes the "function" shorter. and the function will make the whole script HAPPEN. There's that "local" again it means every time we write onCastSpell1 the server will read it as the "parameters" you set in the combat. The doCombat part means that the server will "DO" the combat and parameters that you made.

Make one for each of your combats. and remember to change the numbers. EXAMPLE: onCastSpell1, onCastSpell2, onCastSpell3 and so on.

function onCastSpell(cid, var)
local parameters = { cid = cid, var = var} this is what sets the "onCastSpell" parameters before we write "onCastSpell"1,2,3 etc.." below.
-----------------------------------------------------------------

addEvent(onCastSpell1, 0, parameters)

This actually makes the whole script above an event(something that happens) "onCastSpell1" after addevent means the area and combat1 will happen when you cast a spell, or in this case use the rune. The "0" how long after you cast the spell does all of this actually happen(its used in milliseconds). in this case its at the same time. its "0" milliseconds after you cast the spell or use the rune.

and addevent2 it says "150" that means it will happen 150 milliseconds after you cast the spell or use the rune.

parameters simply means that all the numbers etc.. "parameters" that you set will happen.

you HAVE to add the event or else none of this will happen, and you will get an error when you try to load it.
------------------------------------------------------------

I know its not a REALLY good tutorial but I hope it helped a little bit in your understanding of scripts. Be sure to give me REPUTATION if this helped you. Make a post and tell me what you think too :p Peace out :D
 
Last edited:
this is support, i thought it was a good section ;p where should i put it?
 
thank you :), I don't know how to transfer it but i want to keep one copy here xD cuz a lot of people go to support, tutorials is all the way at the bottom of the page and i just realised that xD. I didn't even know we had a tutorials section ;p
 
I have a question for the formula, the first number multiplies by the skill.. ok lets say I set that to 3.5, and my ml is 20 (20 * 3.5 = 70)... What happens with the 70, where is it included into? Same with the level multiplier?
 
Last edited:
I have a question for the formula, the first number multiplies by the skill.. ok lets say I set that to 3.5, and my ml is 20 (20 * 3.5 = 70)... What happens with the 70, where is it included into? Same with the level multiplier?

where do you see "(20 * 3.5 = 70)" that type of thing. say its LEVELMAGIC and you put -1.6 for the first number. your mlvl is 20. its 1.6x your mlvl, the "-" means it deals damage and doesnt heal. can you be more specific i dont understand you really. sorry but i couldnt reply earlier my computer is broken.
 
Cool lua XD keep it up




Vala Jaal Foreverrr!

Dude im starting not to get lag but at some point i get a Enormous lag Usually when i Pk.






"Vala Jaal"FOREVER"!!!!!!!:peace:
 
Last edited by a moderator:
sgamez1, r u talking about my ot? I'm getting a net upgrade tomorrow, itll be way faster, i would have gotten the complete upgrade, but its not available atm. By the time a lot more people play, ill have it fully upgraded to 764 kbs upload speed, its 150 atm. itll upgrade to like 300 tmrw.
 
Back
Top