[Lua] Beginners Guide menu

User Tag List

Results 1 to 10 of 10
  1. #1
    P1raten's Avatar Banned
    Reputation
    500
    Join Date
    Mar 2008
    Posts
    1,323
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Lua] Beginners Guide

    Introduction
    If you knew any C languages before reading this guide then you'd probably have it easier learning, since Lua is like a simplified C language.

    In this guide you will learn the basics on how to make a boss script, i will follow up with other guides on how to make other things.

    Functions
    Every event in a Lua script is called a function.

    A function looks like the following:

    Code:
    function FUNCTION_NAME(indexes)
        //insert stuff here
    end
    Function obviousley tells the engine that what we are creating now is a function.
    A function can be called anything, but try to make it a good name so that you or other developers can navigate in the script easier.

    Indexes is what is included in the script. In a normal boss fight you just put pUnit and event.

    pUnit = playerUnit = The Boss.

    Event is selfexplainable.

    Unlike the C languages Lua does not use brackets. instead you put 'end' when a function endes.

    Here's a example of a little part of a boss script:

    Code:
    function Boss_Say(pUnit, event)
        pUnit:SendChatMessage(12, 0, "I say something")
    end
    The only thing that you should be unfamiliar with in this function is;

    Code:
    pUnit:SendChatMessage(12, 0, "I say something")
    and i will now explain what this is.

    To make a boss do something you need to add something like the above.

    To tell the engine that you want the boss to do something you write pUnit:SomethingCoolHere.

    As i said before; in this script pUnit = the boss.

    Now, SendChatMessage should be easy to understand.
    We want to send a chat message in the world, to make it even more simple; we want the boss to say something.

    Now in the paranthesis you see the following:

    Code:
    12, 0, "I say something"
    Let's rewrite this so that its easier to understand.

    Code:
    HowToSayIt, WhatLanguage, "What to say"
    There's different flags for HowToSayIt.

    The following can replace 12 in how to say it;

    Code:
    Value :  Description
    
     -1   :  ADDON
      0   :  SAY
      1   :  PARTY
      2   :  RAID
      3   :  GUILD
      4   :  OFFICER
      5   :  YELL
      6   :  WHISPER
      7   :  WHISPER_INFORM
      8   :  EMOTE
      9   :  TEXT_EMOTE
     10   :  SYSTEM
     11   :  MONSTER_SAY
     12   :  MONSTER_YELL
     13   :  MONSTER_WHISPER
     14   :  CHANNEL
     16   :  CHANNEL_JOIN
     17   :  CHANNEL_LEAVE
     18   :  CHANNEL_LIST
     19   :  CHANNEL_NOTICE
     20   :  CHANNEL_NOTICE_USER
     21   :  AFK
     22   :  DND
     23   :  COMBAT_LOG
     24   :  IGNORED
     25   :  SKILL
     32   :  LOOT
     83   :  BATTLEGROUND_EVENT
     87   :  RAIDLEADER
     88   :  RAIDWARNING
    In WhatLanguage we have used the Universal type, which means that every creature and player can understand it.
    Now here's what we can replace WhatLanguage with:

    Code:
    Value :   Description
    
      0   :   UNIVERSAL
      1   :   ORCISH
      2   :   DARNASSIAN
      3   :   TAURAHE
      6   :   DWARVISH
      7   :   COMMON
      8   :   DEMONIC
      9   :   TITAN
     10   :   THELASSIAN
     11   :   DRACONIC
     12   :   KALIMAG
     13   :   GNOMISH
     14   :   TROLL
     33   :   GUTTERSPEAK
     35   :   DRAENEI
    "I say something" should be fell explainable; you input in quotes what you want the creature(in this case our boss) to say.

    You're almost done with your first function.

    For the function to work we also need to add this:

    Code:
    RegisterUnitEvent(BOSSID, 1, "Boss_Say")
    This should be very selfexplainable. If it isnt to you; then dont worry, ill walk you through it.

    RegisterUnitEvent means that were registering a event containing a Unit. A unit is the same thing as a creature.

    BOSSID is replaced with the Bosses ID, which can be found in your database in the creatures table under the entryid column.

    1 is a flag, which says that the Boss should say this when he enters combat.

    Flags:
    Code:
        CREATURE_EVENT_ON_ENTER_COMBAT        = 1,
        CREATURE_EVENT_ON_LEAVE_COMBAT        = 2,
        CREATURE_EVENT_ON_TARGET_DIED        = 3,
        CREATURE_EVENT_ON_DIED        = 4,
        CREATURE_EVENT_ON_TARGET_PARRIED        = 5,
        CREATURE_EVENT_ON_TARGET_DODGED        = 6,
        CREATURE_EVENT_ON_TARGET_BLOCKED        = 7,
        CREATURE_EVENT_ON_TARGET_CRIT_HIT        = 8,
        CREATURE_EVENT_ON_PARRY        = 9,
        CREATURE_EVENT_ON_DODGED        = 10,
        CREATURE_EVENT_ON_BLOCKED        = 11,
        CREATURE_EVENT_ON_CRIT_HIT        = 12,
        CREATURE_EVENT_ON_HIT        = 13,
        CREATURE_EVENT_ON_ASSIST_TARGET_DIED        = 14,
        CREATURE_EVENT_ON_FEAR        = 15,
        CREATURE_EVENT_ON_FLEE        = 16,
        CREATURE_EVENT_ON_CALL_FOR_HELP        = 17,
        CREATURE_EVENT_ON_LOAD        = 18,
        CREATURE_EVENT_ON_REACH_WP        = 19,
        CREATURE_EVENT_ON_LOOT_TAKEN        = 20,
        CREATURE_EVENT_ON_AIUPDATE        = 21,
        CREATURE_EVENT_ON_EMOTE        = 22,
    "Boss_Say" must be the same as the function name or the function wont register. Which means that the function will never exist.

    So, your script should now look something like this:

    Code:
    function Boss_Say(pUnit, event)
        pUnit:SendChatMessage(12, 0, "I say something")
    end
    
    RegisterUnitEvent(1337, 1, "Boss_Say")
    If you'd put this in a file and save it as script.lua then it would work perfectly.
    Although once again; you need to have a creature with the entry id of 1337 in this case.

    More on functions

    In this part i will teach you how to register a new function within another function, this is most commonly used in what's called phase fights.

    It's basically a boss fight that just registers functions after functions and when the boss is below X HP then it registers another function. Even though i hate these boss fights i am stilll going to learn you how to make one.

    Here's a example of a typical phase fight:

    Code:
    local tank = pUnit:GetMainTank() --Here we define that "tank" is the same as pUnit:GetMainTank()
    local plr = pUnit:GetRandomPlayer(0) --Here we define that "plr" is the same as pUnit:GetRandomPlayer(0)
    
    function BossOnCombat(pUnit, Event)
        pUnit:Root() --Roots the Boss so that he cant move while hes speaking.
        pUnit:SetCombatCapable(1) --Makes the Boss unable to fight since i dont want him to fight the players while hes speaking.
        pUnit:SendChatMessage(14, 0, "There's no point in trying to defeat me!") --The Boss yells
        pUnit:RegisterEvent("BossLieksToSpeak", 2000, 0) --Register a new event
    end
    
    function BossLieksToSpeak(pUnit, Event)
        pUnit:SendChatMessage(14, 0, "You wont get through here.")
        pUnit:RegisterEvent("PrepareToFight", 2000, 0)
        pUnit:RegisterEvent("LetsFite", 2100, 0)
    end
    
    function PrepareToFight(pUnit, Event)
        pUnit:UnRoot() --Unroots the boss.
        pUnit:SetCombatCapable(0) --Makes the boss able to fight again.
    end
    
    function LetsFite(pUnit, Event)
        local choice = math.random(1, 3) --Chooses a random number between 1 and 3.
        if choice == 1 then --If the random number is 1
            pUnit:FullCastSpellOnTarget(40932, tank)
        end
        if choice == 2 then --If the random number is 2
            pUnit:FullCastSpell(60019)
        end
        if choice == 3 then --If the random number is 3
            pUnit:FullCastSpellOnTarget(69528, plr)
        end
        if pUnit:GetHealthPct() <= 50 then --If the boss' health is below 50% then register a new phase.
            pUnit:RegisterEvent("NewPhase", 2000, 0)
        end
    end
    
    function NewPhase(pUnit, Event)
        pUnit:Kill() --The Boss Kills itself.
    end
    ------------------------------

    Variations

    There are different ways to make your Boss fights more variated.

    For example:

    Code:
    if pUnit:GetHealthPct() == math.random(40,60)
    The options are only limited to your imagination.

    If you think that your script file is too big then you can seperate it into 2 files.

    By simply adding:

    Code:
    include( 'scriptnumbertwo.lua' )
    in script file number 1.

    A smart thing to do is to vary your if's.

    Like so:

    Code:
    if pUnit:GetHealthPct() == math.random(40,60) || pUnit:GetHealthPcty() == math.random(20, 39) then
    This if variation is kinda pointless, but its just a demonstration
    Last edited by Ground Zero; 04-13-2010 at 07:46 AM.

    [Lua] Beginners Guide
  2. #2
    stoneharry's Avatar Moderator Harry

    Authenticator enabled
    Reputation
    1613
    Join Date
    Sep 2007
    Posts
    4,554
    Thanks G/R
    151/146
    Trade Feedback
    0 (0%)
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Noooo! No more 'beginner' guides! We got enough of them! Write something for the intermediate or more advanced user...

  3. #3
    Dombo's Avatar Banned
    Reputation
    622
    Join Date
    Nov 2008
    Posts
    1,421
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice read, I'm a beginner at LUA and have found it very comprehensible. Although I have to agree with stoneharry, we need more guides for intermediates.

    Perhaps you can add some more difficult tutorials to your thread?

  4. #4
    P1raten's Avatar Banned
    Reputation
    500
    Join Date
    Mar 2008
    Posts
    1,323
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by stoneharry View Post
    Noooo! No more 'beginner' guides! We got enough of them! Write something for the intermediate or more advanced user...
    As you wish, ill add it to my thread later.

  5. #5
    Ground Zero's Avatar ★ Elder ★
    Reputation
    1132
    Join Date
    Aug 2008
    Posts
    3,504
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are loads of guides like this and most much more detailed, such as http://www.mmowned.com/forums/emulat...-tutorial.html

  6. #6
    P1raten's Avatar Banned
    Reputation
    500
    Join Date
    Mar 2008
    Posts
    1,323
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Ground Zero View Post
    There are loads of guides like this and most much more detailed, such as http://www.mmowned.com/forums/emulat...-tutorial.html
    Agreeable. hsnap:

  7. #7
    alj03's Avatar Contributor
    Reputation
    91
    Join Date
    Feb 2008
    Posts
    1,103
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But but... Jebus wrote it so it counts doesn't it?

    I think it's set out nicely and easy to understand.
    Death to all but Metal.

  8. #8
    ~OddBall~'s Avatar Contributor
    Reputation
    207
    Join Date
    Jan 2008
    Posts
    1,156
    Thanks G/R
    4/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But it's still a good guide xD
    https://www.mmowned.com/forums/world-of-warcraft/guides/278302-selecting-bot-you.html - SELECTING THE BOT FOR YOU

    PHWOOOOAAAAAR - Parog was here. <3 <----Wtf's a Parog?

  9. #9
    Dynashock's Avatar Contributor

    Reputation
    176
    Join Date
    Nov 2007
    Posts
    203
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since when is || part of the Lua syntax? I think you mixed the languages up there. Its equivalent in Lua is 'or'.

    I have a hard time seeing the point of this guide as I've seen too many which explain the very same subject but do it, in my opinion, better. Besides, there are too many faulty assumptions made in this thread.

    Functions cannot hold ANY name, Lua preserves certain characters for its own engine. Furthermore, they're not called indeces, but parameters. Thirdly, you don't have to call it pUnit or event. I could just as well call it 'fgt' and call methods with fgtoIt();. (Oh yes, I know I did a semi-colon there. Lua allows for semi-colons just as C++ and C# do.)

    Can we please get anything new to read?
    Ignorance is bliss.

  10. #10
    Xel's Avatar ★ Elder ★
    Authenticator enabled
    Reputation
    1179
    Join Date
    Jul 2008
    Posts
    2,906
    Thanks G/R
    94/51
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Noooo! No more 'beginner' guides! We got enough of them! Write something for the intermediate or more advanced user...
    Indeed but it's still well written and helpful +Rep

Similar Threads

  1. [Guide]Lua [Beginner]
    By ZestyJ in forum WoW EMU Guides & Tutorials
    Replies: 4
    Last Post: 04-23-2009, 11:40 PM
  2. Beginners Guide (Dun Morgoth)
    By Amedis in forum World of Warcraft Guides
    Replies: 0
    Last Post: 06-19-2006, 04:27 PM
  3. Beginners Guide (Teldrassil)
    By Amedis in forum World of Warcraft Guides
    Replies: 0
    Last Post: 06-19-2006, 04:26 PM
  4. Beginners Guide (Durotar)
    By Amedis in forum World of Warcraft Guides
    Replies: 0
    Last Post: 06-19-2006, 04:25 PM
  5. Beginners Guide (Tirisfal Glades)
    By Amedis in forum World of Warcraft Guides
    Replies: 0
    Last Post: 06-19-2006, 04:24 PM
All times are GMT -5. The time now is 04:38 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search