Lua Scripting Guide

Discussion in 'Programming & Scripting' started by Evil Hero, Mar 23, 2010.

  1. Mock

    Mock Mock the bear (MTB)

    Joined:
    Jul 29, 2008
    Messages:
    619
    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
    @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
     
  2. TGYoshi

    TGYoshi In space

    Joined:
    Aug 20, 2010
    Messages:
    1,107
    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.
     
  3. Mock

    Mock Mock the bear (MTB)

    Joined:
    Jul 29, 2008
    Messages:
    619
    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.
     
  4. Havocbringer

    Havocbringer Well-Known Member

    Joined:
    Apr 28, 2010
    Messages:
    1,687
    Very nice.. thank u very much :p
     
  5. Mock

    Mock Mock the bear (MTB)

    Joined:
    Jul 29, 2008
    Messages:
    619
    nice? this mess?
     
  6. Havocbringer

    Havocbringer Well-Known Member

    Joined:
    Apr 28, 2010
    Messages:
    1,687
    Idk i think it looks pretty good rofl
     
  7. Mock

    Mock Mock the bear (MTB)

    Joined:
    Jul 29, 2008
    Messages:
    619
    This guy have done a great mess with this explanation dude.
    http://www.lua.org/pil/
    Read this.

    I will create a new explanation.
     
  8. TGYoshi

    TGYoshi In space

    Joined:
    Aug 20, 2010
    Messages:
    1,107
    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".
     
  9. GodSebbe

    GodSebbe Banned User, reason: To Sexy

    Joined:
    Apr 16, 2011
    Messages:
    848
    i Loved it! this thread! :) (Good For Beginners) ffs..
     
  10. Sodeko

    Sodeko Member

    Joined:
    Sep 22, 2008
    Messages:
    71
    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.
     
  11. ruubs

    ruubs New Member

    Joined:
    Jan 4, 2011
    Messages:
    8
    Thank u, I was looking for a LUA tutorial. This has been very helpfull!
     
  12. Zatjin

    Zatjin Premium User Premium User

    Joined:
    Sep 18, 2011
    Messages:
    2,199
    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?
     
  13. Transeti

    Transeti Member

    Joined:
    Apr 10, 2011
    Messages:
    91
    ill be on this page for a while, Thank you.
     
  14. Wygle

    Wygle New Member

    Joined:
    Dec 7, 2011
    Messages:
    6
    great tut!
     
  15. KungTao

    KungTao Member

    Joined:
    May 2, 2010
    Messages:
    34
    Very NICE! REP++
     
  16. Reasembled

    Reasembled Turtle of Otland

    Joined:
    Jan 2, 2012
    Messages:
    651
    Repeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed
     
  17. Cyro

    Cyro Well-Known Member

    Joined:
    May 24, 2011
    Messages:
    1,291
    @zatjin It works
     
  18. Dantarrix

    Dantarrix Member

    Joined:
    Aug 27, 2010
    Messages:
    546
    @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 ;)
     
  19. tommish

    tommish New Member

    Joined:
    Jan 23, 2012
    Messages:
    4
    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
     
  20. Elda Swok

    Elda Swok Searching New Project

    Joined:
    Jun 18, 2008
    Messages:
    703
    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.
     

Share This Page