Lua Scripting Guide

Syntax

Developer
Joined
Oct 10, 2007
Messages
2,840
Best answers
0
Reaction score
201
Location
Texas
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.
 
OP
Evil Hero

Evil Hero

Legacy Member
TFS Developer
Joined
Dec 12, 2007
Messages
1,179
Best answers
15
Reaction score
553
Location
Germany
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 ^_^
 

slayzer

Klaffen
Joined
Dec 28, 2008
Messages
260
Best answers
0
Reaction score
11
i almost didn't know Anything about scripting, so i am so bookmarking this, also i am looking for the rest :)
 

memofighter

New Member
Joined
Mar 11, 2010
Messages
10
Best answers
0
Reaction score
0
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.
 
OP
Evil Hero

Evil Hero

Legacy Member
TFS Developer
Joined
Dec 12, 2007
Messages
1,179
Best answers
15
Reaction score
553
Location
Germany
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.
 

memofighter

New Member
Joined
Mar 11, 2010
Messages
10
Best answers
0
Reaction score
0
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).
 
OP
Evil Hero

Evil Hero

Legacy Member
TFS Developer
Joined
Dec 12, 2007
Messages
1,179
Best answers
15
Reaction score
553
Location
Germany
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.
 

memofighter

New Member
Joined
Mar 11, 2010
Messages
10
Best answers
0
Reaction score
0
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 :)
 
Joined
Jun 19, 2009
Messages
1,852
Best answers
0
Reaction score
5
Thanks, thanks thanks and thanks! :D

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


and btw, make a tutorial for "time" - (os
 

Znote

<?php echo $title; ?>
Staff member
Global Moderator
Premium User
Joined
Feb 14, 2008
Messages
6,668
Best answers
202
Reaction score
1,375
Location
Norway, Oslo
Looking forward for the upcoming parts. :D
 

Evil Mark

Active Member
Joined
Nov 23, 2008
Messages
1,681
Best answers
0
Reaction score
28
I made my first script thanks to this thread ^_^
 

Kaydee

New Member
Joined
Jul 3, 2010
Messages
3
Best answers
0
Reaction score
0
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.
 

JoSePh15_

Well-Known Member
Joined
Jan 28, 2010
Messages
1,768
Best answers
0
Reaction score
56
Very Helpfull and you have got my reputation! Give it back :D
 

moha99

Newbie Scripter :)
Joined
Jul 13, 2010
Messages
4
Best answers
0
Reaction score
0
i need a function like i can only use the item 1 time or anything
 
Last edited:

zippoxer

New Member
Joined
Mar 18, 2008
Messages
90
Best answers
0
Reaction score
4
Location
Israel
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.
 

JuanC

New Member
Joined
Sep 24, 2009
Messages
220
Best answers
0
Reaction score
2
...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?
 
Top