Lua Scripting Guide

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Best answers
0
Reaction score
101
Location
Brazil
Better tou change the thread name, you are teaching how to create scripts in O.T.S not a real scripting guide.
@function
You wrote a wrong syntax, the correct syntax is:
Code:
function aa(param1,param2,...)
   --content
end
--or
local function aa(param1,param2,...)
   --content
end
@If...Else...Elseif...Return...End
okay i think in a big part you said correct. but in return you did a great mess -.-
Return is used to return (ohrly?) a value from a function, that you not explained correctly
Code:
function plus(v1,v2)
     return v1+v2
end
print(plus(10,20))
-->> print 30
Ok, where is
>= <= not and or
@Local and Global Statements
WHAT A BIG MESS! you are trying explai what is global and local without explain what is a variable?
@For loops
the first time i see some one explain for as first ;o but ok.
@While Loops
Code:
--By Evil Hero
function onUse(cid, item, fromPosition, itemEx, toPosition)
	while getPlayerLevel(cid) < 50 do
		doPlayerSendTextMessage(cid,22,"You are under level 50!")
	end
	return true
end
Are you sure? Your idea is to freeze your server?
So you will explay why to use 'break' in the loop?
@Repeat Loops
ok, where is the break?


If you really want learn LUA correctly just take a look in these links:

Lua 5.1 Reference Manual - contents
Programming in Lua : contents <-- this is better
and look to download it: luaforwindows - Installation of Lua for the Windows operating systems including many lua libraries. - Google Project Hosting
 

TGYoshi

In space
Joined
Aug 20, 2010
Messages
1,107
Best answers
0
Reaction score
116
Location
In space
Agree at up.
Who the hell starts explaining 'functions' by the way?

Start by giving people some basic onUse code without containings.
Then explain them what to add in between.
 

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Best answers
0
Reaction score
101
Location
Brazil
Agree at up.
Who the hell starts explaining 'functions' by the way?

Start by giving people some basic onUse code without containings.
Then explain them what to add in between.
if the thread says "scripting guide" the owner have to explain how to use the lua not how to use in otserv. Bt if the thread name was "Open tibia scripting" its okay BUT the owner have done a big mess with the explanation.
 

TGYoshi

In space
Joined
Aug 20, 2010
Messages
1,107
Best answers
0
Reaction score
116
Location
In space
if the thread says "scripting guide" the owner have to explain how to use the lua not how to use in otserv. Bt if the thread name was "Open tibia scripting" its okay BUT the owner have done a big mess with the explanation.
It doesn't really matter if it's OT scripting on 'normal' scripting, nobody it really able to learn from it fully from this. Actually, I would quit immediately because we start with something weird instead of stuff we understand.
What's the point of this topic? I'm unable to learn from it if I had to do so. It's all like "what the heck are you talking about" instead of "hey let's try something like this".
 

GodSebbe

Banned User, reason: To Sexy
Joined
Apr 16, 2011
Messages
847
Best answers
0
Reaction score
118
Location
Sweden
i Loved it! this thread! :) (Good For Beginners) ffs..
 

Sodeko

New Member
Joined
Sep 22, 2008
Messages
71
Best answers
0
Reaction score
3
Wow a lot of no-it-alls lol... I am a beginer. I know the basics. For me, this tutorial actually explained a whole lot. It gave me the breakdown of the code in layman's terms... and it helped me understand better what the functions and the other stuff does. I have looked at scripts that come with a distro, able to decipher bits and pieces but this actually helped me understand and be able to read and write my own code. Try to keep in mind, YOU may know how to script with your eyes closed, but most of us don't really know that much. This tutorial is great for us beginers. Maybe it sucks for you experts but its great for us.

Here is my recommendation... Instead of being dicks to people and talking shit about how they did something, why don't you do it better? why don't you create a tutorial about the same thing that is "better" than this if you think this sux so much.

Ty :) Rep ++ for this thread.
 

ruubs

New Member
Joined
Jan 4, 2011
Messages
8
Best answers
0
Reaction score
0
Thank u, I was looking for a LUA tutorial. This has been very helpfull!
 

Zatjin

Advanced OT User
Joined
Sep 18, 2011
Messages
2,220
Best answers
0
Reaction score
191
Location
Norway
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1945 and getPlayerLevel(cid) >= 50 then
		doPlayerSendTextMessage(cid,21,"It works !")
		doTransformItem(item.uid, item.itemid + 1)
		doCreatureAddMana(cid,500)
		doCreatureAddHealth(cid,500)
	elseif item.itemid == 1946 and getPlayerLevel(cid) >= 50 then
		doPlayerSendTextMessage(cid,21,"You pulled it back!")
		doTransformItem(item.uid, item.itemid - 1)
		doCreatureAddMana(cid,500)
		doCreatureAddHealth(cid,500)
	else
		doPlayerSendCancel(cid,"You don't have the required level to use this.")
	end
	return TRUE
end
This line:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
Wouldn't it be better to use it this way?:
Code:
function onUse(cid, item, fromPos, itemEx, toPos)
Or isn't that possible?
 

Reasembled

Turtle of Otland
Joined
Jan 2, 2012
Messages
651
Best answers
0
Reaction score
38
Location
Computer...Forever
Repeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed
 

Dantarrix

Member
Joined
Aug 27, 2010
Messages
546
Best answers
0
Reaction score
18
Location
Stgo, Chile
@Zatjin: you can do it whatever you like, only you need to keep it on mind...

function onUse(player, item1, position1, item2, position2)

if item1.itemid
if isPlayer(player)

you can see that i used the same that i replaced on function ;)
 

tommish

New Member
Joined
Jan 23, 2012
Messages
4
Best answers
0
Reaction score
0
Location
Stocktown
Good tutorial.
Too bad about the forum-troll-horde slendering about minor syntax errors and whining about you leaving out tons of information which only would had made newbies run in terror.
Think you should definitely complete this tutorial, or let someone else do it.

It's obviously of great help to new-comers like moi =)
+r
 

Elda Swok

Searching New Project
Joined
Jun 18, 2008
Messages
703
Best answers
0
Reaction score
9
Location
Pittsburgh, Pa.
I'm a bit confused, can someone explain what all of the () means? Like

function onUse(cid <!-- I know this is for player. -->, item, fromPosition, itemEx, toPosition)

What do the others mean, and I could be wrong on cid. not 100% sure, I'd love to learn scripting but it's hard when you don't know the basic concept of the source.
 
Top