• 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

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
 
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.
 
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.
 
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".
 
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.
 
Thank u, I was looking for a LUA tutorial. This has been very helpfull!
 
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?
 
@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 ;)
 
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
 
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.
 
Back
Top