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
    Likes Received:
    91
    Best Answers:
    0
    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 (Text):
    1.  
    2. function aa(param1,param2,...)
    3.    --content
    4. end
    5. --or
    6. local function aa(param1,param2,...)
    7.    --content
    8. end
    9.  
    @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 (Text):
    1.  
    2. function plus(v1,v2)
    3.      return v1+v2
    4. end
    5. print(plus(10,20))
    6. -->> print 30
    7.  
    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 (Text):
    1.  
    2. --By Evil Hero
    3. function onUse(cid, item, fromPosition, itemEx, toPosition)
    4.     while getPlayerLevel(cid) < 50 do
    5.         doPlayerSendTextMessage(cid,22,"You are under level 50!")
    6.     end
    7.     return true
    8. end
    9.  
    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
    Likes Received:
    110
    Best Answers:
    0
    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
    Likes Received:
    91
    Best Answers:
    0
    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
    Likes Received:
    102
    Best Answers:
    0
    Very nice.. thank u very much :p
     
  5. Mock

    Mock Mock the bear (MTB)

    Joined:
    Jul 29, 2008
    Messages:
    619
    Likes Received:
    91
    Best Answers:
    0
    nice? this mess?
     
  6. Havocbringer

    Havocbringer Well-Known Member

    Joined:
    Apr 28, 2010
    Messages:
    1,687
    Likes Received:
    102
    Best Answers:
    0
    Idk i think it looks pretty good rofl
     
  7. Mock

    Mock Mock the bear (MTB)

    Joined:
    Jul 29, 2008
    Messages:
    619
    Likes Received:
    91
    Best Answers:
    0
    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
    Likes Received:
    110
    Best Answers:
    0
    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
    Likes Received:
    119
    Best Answers:
    0
    i Loved it! this thread! :) (Good For Beginners) ffs..
     
  10. Sodeko

    Sodeko Member

    Joined:
    Sep 22, 2008
    Messages:
    71
    Likes Received:
    3
    Best Answers:
    0
    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
    Likes Received:
    0
    Best Answers:
    0
    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,203
    Likes Received:
    213
    Best Answers:
    0
    Code (Text):
    1.  
    2. function onUse(cid, item, fromPosition, itemEx, toPosition)
    3.     if item.itemid == 1945 and getPlayerLevel(cid) >= 50 then
    4.         doPlayerSendTextMessage(cid,21,"It works !")
    5.         doTransformItem(item.uid, item.itemid + 1)
    6.         doCreatureAddMana(cid,500)
    7.         doCreatureAddHealth(cid,500)
    8.     elseif item.itemid == 1946 and getPlayerLevel(cid) >= 50 then
    9.         doPlayerSendTextMessage(cid,21,"You pulled it back!")
    10.         doTransformItem(item.uid, item.itemid - 1)
    11.         doCreatureAddMana(cid,500)
    12.         doCreatureAddHealth(cid,500)
    13.     else
    14.         doPlayerSendCancel(cid,"You don't have the required level to use this.")
    15.     end
    16.     return TRUE
    17. end
    This line:
    Code (Text):
    1.  
    2. function onUse(cid, item, fromPosition, itemEx, toPosition)
    3.  
    Wouldn't it be better to use it this way?:
    Code (Text):
    1.  
    2. function onUse(cid, item, fromPos, itemEx, toPos)
    3.  
    Or isn't that possible?
     
  13. Transeti

    Transeti Member

    Joined:
    Apr 10, 2011
    Messages:
    91
    Likes Received:
    1
    Best Answers:
    0
    ill be on this page for a while, Thank you.
     
  14. Wygle

    Wygle New Member

    Joined:
    Dec 7, 2011
    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    great tut!
     
  15. KungTao

    KungTao Member

    Joined:
    May 2, 2010
    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Very NICE! REP++
     
  16. Reasembled

    Reasembled Turtle of Otland

    Joined:
    Jan 2, 2012
    Messages:
    651
    Likes Received:
    38
    Best Answers:
    0
    Repeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed
     
  17. Cyro

    Cyro Well-Known Member

    Joined:
    May 24, 2011
    Messages:
    1,291
    Likes Received:
    116
    Best Answers:
    0
    @zatjin It works
     
  18. Dantarrix

    Dantarrix Member

    Joined:
    Aug 27, 2010
    Messages:
    546
    Likes Received:
    19
    Best Answers:
    0
    @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
    Likes Received:
    0
    Best Answers:
    0
    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
    Likes Received:
    11
    Best Answers:
    0
    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

Loading...