• 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 Scripting Guide

Well many mistakes people make with these types of tutorials is they don't start from the ground up, with every ounce of detail and feature. My suggestions, before getting into the Open Tibia side of the scripting, first include the syntax, the keywords, what they do, etc.
 
Well many mistakes people make with these types of tutorials is they don't start from the ground up, with every ounce of detail and feature. My suggestions, before getting into the Open Tibia side of the scripting, first include the syntax, the keywords, what they do, etc.

I've once written such a tutorial but mostly the feedback was like "I wanna learn scripting for my servers, then starting at zero point and learn everything."

I'm not gonna disagree on your point, it's for sure better if you start with lua itself, then just jump into scripting for servers already but somehow it seems that people wont do it like that :p

If you like to contribute such a tutorial, I would gladly add it, that's out of question but I'm going to stick for the server scripting for now, since the guide isn't finished at all just now ^_^
 
i almost didn't know Anything about scripting, so i am so bookmarking this, also i am looking for the rest :)
 
Hello Evil Hero.
I've tested your lever function, and it doesn't work properly. The first part works. I get the "It Works!'Message and the item ID chages to 1946, butwhen I pull it back, I don't get a message nor any mana.
 
Hello Evil Hero.
I've tested your lever function, and it doesn't work properly. The first part works. I get the "It Works!'Message and the item ID chages to 1946, butwhen I pull it back, I don't get a message nor any mana.

I've had a slightly error in it, check it now again.
 
I've had a slightly error in it, check it now again.

Still aint working, but maybe my fault. This is the code I've put in my XML file:
<action itemid="1945" event="script" value="tools/addmana.lua"/>

(addmana is the name of the file).
 
Still aint working, but maybe my fault. This is the code I've put in my XML file:
<action itemid="1945" event="script" value="tools/addmana.lua"/>

(addmana is the name of the file).
well you have to add the 1946 aswell ofc :p

And this is ofc just for testing, I don't reccomend to add that on a serious server but for now, do it this way.

Code:
<action itemid="1945-1946" event="script" value="tools/addmana.lua"/>

Because if you add it that way, every lever with that itemid will do that script.
 
well you have to add the 1946 aswell ofc :p

And this is ofc just for testing, I don't reccomend to add that on a serious server but for now, do it this way.

Code:
<action itemid="1945-1946" event="script" value="tools/addmana.lua"/>

Because if you add it that way, every lever with that itemid will do that script.

Hehe, it's working. Thanks! I aint gonna use it for my server, of course not:p I'm just trying to learn the basics of lua and this is a fine way to learn it imo :)
 
Thanks, thanks thanks and thanks! :D

I will for sure follow this tutorial until its end ;)


and btw, make a tutorial for "time" - (os
 
Looking forward for the upcoming parts. :D
 
Thank you very much for your tutorials. I'm looking forward for there to be more. I'm new at scripting & this helps me understand ALOT.
 
i need a function like i can only use the item 1 time or anything
 
Last edited:
Whenever I try setItemExtraAttack() or setItemAttack(), the server tells me that he could not find this global.

I use TFS 0.3.6 and I even have this functions in doc.
 
...each for loop has to have it's own
Let's go for another example to see how it works in a server based script.

Let's say we want to add the player a backpack and that backpack contains 3 times the same item.
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local backpack = doPlayerAddItem(cid, 1988, 1)
	for a = 1,3 do
		doAddContainerItem(backpack, 2160, 100)
	end
	return true
end

There's not really much more to say about the for loops.
We'll get back to them later on.
This repeat doAddContainerItem(backpack, 2160, 100) 3 times?
 
Back
Top