Beginners LUA Guide From Nub to Expert [updating] menu

User Tag List

Results 1 to 1 of 1
  1. #1
    mager1794's Avatar Member
    Reputation
    356
    Join Date
    Feb 2008
    Posts
    703
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Beginners LUA Guide From Nub to Expert [updating]

    Mager1794's LUA Script Tutorial

    Chapter 1 Beging LUA
    Intro
    Supplies
    What is LUA
    What is it for

    Chapter 2 A First Look at LUA Script
    My First Script
    Described
    It Wont Work

    Chapter 3 Peeking at the Registers
    What it does
    How to do it
    Explained alot!

    Chapter 4 Script an AI
    Whats an AI
    Making the script(in detail)





    Chapter 1

    Intro

    Hi There im Mager1794 you might now me from assisting you in Emulator discusion or one
    of my past guides. Well here i am making another guide to help you master LUA as fast
    as possible follow this guide and you'll be good enough to call yourself a dev in no time
    maybe you will be contributing to MMowned who knows now lets begin

    Supplies

    All you trully need is a World of warcraft server with LUA enabled and a notepad
    you could also use a one of the few LUA compilers but it wont matter anyway just
    make sure you save as name.LUA files

    What is LUA

    LUA is a extremely basic programming language that is created through C++ the functions
    in LUA will react with the C++ to create the script that you are writing its
    pretty much an easy version of C++

    What is it for

    LUA can be used for many different things for one say you have an addon?? that is made
    with LUA and some XML i believe also a great thing about LUA is scripting bosses quest
    event and more the powers of lua are limitless if your DLL file is made for it : )


    Chapter 2

    My First Script

    lets begin writing our very first script now with most programming languages they always do
    the little hello world thing and i dont like to be the one to break traditions so..

    lets begin

    [please type this rather than copy& paste from personal expieriance i feel it helps the
    language sink in a little better]

    Code:
    function firstscript_OnCombat(pUnit, Event)
    pUnit:SendChatMessage(14, 0, "Hello World")
     end
    end
    Described

    now lets break it down a bit

    function
    firstscript_OnEnterCombat(pUnit, Event)
    pUnit:SendChatMessage(14, 0, "Hello World")
    end
    end

    excellent now its broken down... wait thats no help

    here we go

    function - its the starting command for mostly every script you will ever write with out you
    just have a notpad with a weird file extension

    firstscript_OnEnterCombat(pUnit, Event) - its the name of the your function
    (except the pUnit, Event part) the OnEnterCombat and Event work together to create the
    function to happen on a certain event in this case it is on entering combat

    pUnit:SendChatMessage(14. 0, "Hello World") - its your command in this function cause it to
    speak the 14 is how it will be said(yell, whisper, broadcast etc) the 0 is the language
    which will be your common langauge to use cause all races can understand it and the "Hello World"
    is the message to be stated

    end
    end - there just ending the function kinda obvious

    It Wont Work

    Well if you already know a little about LUA then you should know why its not working
    the function isn't registered yet all you have is a function no mob set for it or nothing
    so we have to register it im not gonna go into it cuase that is gonna be the next chapter
    but
    Code:
    RegisterUnitEvent(123456,1,"firstscript_OnEnterCombat:)
    Chapter 3 : Peeking at the Registers

    What it does

    The Registers of course keep track of all the money we get from people at our
    convienient store... wait...this is LUA right ooops

    The Registers are what enable us to have the functions declared onto
    mobs and NPC etc for now im just going to show RegisterUnitEvent but later
    in the guide there will be more so be ready

    How to do it

    its really simple type this with me

    "R" "e" "g" "i" "s" "t" "e" "r"

    then erase and type

    RegisterUnitEvent(

    thats the basic function for the registering a unit
    but for it to work you need (npc spawn ID,EventNumber,"Name_Event")

    let me help you figure this stuff out

    Explained Alot

    EVENTNUMBER!!! *GASP*
    ZOMG!! WHATS THAT
    well its the number for the event
    here is what i know (theres probably more)

    1 - EnterCombat = It Sets the function off when it enter combat
    2 - LeaveCombat = Its Set off the function when it leave combat
    3 - KillTarget = Sets the function off whne it kill the target
    4 - Died = Sets the function off when it dies
    5 - AItick = Sets off the function when its AI (pretty much any spell used) ticks
    6 - Spawn = Sets off the function on spawn
    7 - Gossip = Sets the function off on gossip which is when you speak to it
    8 - Waypoint = Sets off when a waypoint is reached
    9 - leavelimbo = I believe its on the targets revival
    10 - playerenter= When the player enters the targets area

    now just insert the NPC Spawn ID and the event name and wha lah you got a
    function and its registered

    Chapter 4 Scripting an AI

    What is AI?

    AI stand for Artificial Intelligence now im not saying that i teach you this and you can
    go program a robot with it or something becuase well we all know that only SectorSevens
    that awesome lol. But you can program your bosses/mobs etc. with it whats the fun of a
    fight if all they do is attack wheres the excitement ill tell you where on my server
    with fully scripted instances its unfair for you so heres your shot to have you instances
    script

    Making the script(in detail)

    Lets begin with a normal function

    Code:
    function mob_spell(unit)
    notice how i used non of the identifiers from the previous chapter why is that..
    its because this a pretty much a phase and i wont register it with RegisterUnitEvent
    it will be done with RegisterEvent (we'll get there dont worry)

    now after we do that lets make him speak with it so add

    Code:
    function mob_spell(unit)
    Unit:SendChatMessage(12,0,"Eat the Fire")
    ok so now we have him talking a fire so we dont want him to do frost or shadow or something
    so always watch for that now lets make him cast the spell

    Code:
    function mob_spell(unit)
    Unit:SendChatMessage(12,0,"Eat the Fire")
    Unit:CastSpell(40255)
    great that is done lets just add the end

    Code:
    function mob_spell(unit)
    Unit:SendChatMessage(12,0,"Eat the Fire")
    Unit:CastSpell(40255)
    end
    great were finished now were just making a mob script here so im having only one spell
    but you can put as many as you wish (practice as much as you want)

    ok so we have that now lets just make a simple OnCombatScript

    Code:
    function mob_OnEnterCombat(unit, event)
    ok so we have that set up now here is where we shall register the spell

    Code:
    function mob_OnEnterCombat(unit, event)
    Unit:RegisterEvent("function name",how often it will be done, 0)
    ok so we have that now change the function name to
    mob_spell
    and the how often we want to be 7 seconds and since its in miliseconds just add 3 0's to
    the end of it

    and there ya have it its registered
    now just add a SendChatMessage if you want and your done

    Heres a Full Script (of that mob) Example

    Code:
    function mob_spell(unit)
    Unit:SendChatMessage(12,0,"Eat the Fire")
    Unit:CastSpell(40255)
    end
    
    function mob_OnEnterCombat(unit, event)
    Unit:RegisterEvent("mob_spell",7000, 0)
    end
    thats all i have for now i will update this guide even more til im finally finished
    leave you thoughts plz its 3 am so im goin to bed ill get some more in tommorow
    Lunar Gaming - Reaching For The Stars

    Beginners LUA Guide From Nub to Expert [updating]
  2. Thanks 1boywonder1 (1 members gave Thanks to mager1794 for this useful post)

Similar Threads

  1. Beginner's Guide to Lua Gossip
    By Dr. Livingstone in forum WoW EMU Guides & Tutorials
    Replies: 13
    Last Post: 10-22-2008, 05:33 PM
  2. Updated Mega Lua guide {all known commands}
    By runiker in forum WoW EMU Guides & Tutorials
    Replies: 28
    Last Post: 07-30-2008, 10:10 PM
  3. Any1 have the guide from www.ultimatewowguide.com
    By oooscorpion in forum World of Warcraft General
    Replies: 0
    Last Post: 03-24-2007, 03:37 PM
  4. Beginners MC Guide
    By Amedis in forum World of Warcraft Guides
    Replies: 7
    Last Post: 01-05-2007, 11:44 PM
  5. WOW GUide FROM RED GUIDES.. ( WOW UNDERGROUND)
    By Elites360 in forum World of Warcraft Guides
    Replies: 12
    Last Post: 11-01-2006, 05:05 PM
All times are GMT -5. The time now is 09:22 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