[GUIDE] Lua - Begginers -> Advanced menu

User Tag List

Results 1 to 11 of 11
  1. #1
    Dr. Livingstone's Avatar Member
    Reputation
    113
    Join Date
    Mar 2008
    Posts
    290
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [GUIDE] Lua - Begginers -> Advanced

    There are a LOT of lua guides out there right now, but I’ve tried to create a guide that would let you start as a beginner, and by the end you would have some skills in lua and be able to continue to figure more things out for yourself. First we are starting with boss scripts, after boss scripts comes gossip, and after gossip comes item/gobject gossip. Then after that I will give some nifty tips and some more advanced ideas. .

    Boss Scripts
    1. Creating Your First Script!
    1.1 Making your NPC talk
    1.2 Making your NPC cast spells
    1.3 Making your NPC spawn other NPCs

    2. Creating Phases
    2.1 Using pUnit:RegisterEvent to create phases
    2.2 Using ‘if’ statements to your advantage
    2.3 Removing events with pUnit:RemoveEvent()

    3. Variables <3 You
    3.1 Local =

    3.2 Using variables to change things up
    3.3 Variables and math.random


    NPC Gossip Scripts
    1. Creating A Basic Gossip Menu
    [
    1.1 Making Your NPC broadcast a message
    1.2 Making your NPC teleport a player
    1.3 Making your NPC morph a player
    1.4 Making your NPC buff a player


    2. Making Gossip Scripts Fit With Boss Scripts
    2.1 Gossip NPC spawning other NPC’s
    2.2 Gossip NPC starting an event


    Item Gossip Scripts
    1. Setting Up An Item Gossip Script
    1.1 Creating a warp stone
    1.2 Creating an information stone
    1.3 Creating a wishing stone


    ----------------------------------------------------------------------------------------------------------------------------------------------------
    1. Creating Your First Script!
    1.1 Making your NPC talk.
    I personally think that making an NPC talk is the easiest thing to
    script, and it gives us the ability to provide a good starting point when it comes to creating events and that sort of thing. So right here I will introduce you to the structure of every lua script. Some things may be different depending on the script, but generally this is how they will all start.
    Code:
     function BossName_OnCombat(pUnit, event)
    Now this is telling you what the boss will do when he enters combat. So let’s state what we want the boss to do when he enters combat. We will make him say, “My first lua boss script.” So we need to add this to our script.
    Code:
     pUnit:SendChatMessage(14, 0, “My first lua boss script.”)
    Let me explain. This is saying the NPC is going to send a chat message in ‘Monster Yell’ (That’s what the 14 is saying), and he is saying “My first lua boss script.” It is really that simple. Now there are a lot of things that can be used instead of 14. I normally use one of the following:
    Code:
    12 – Monster Say
    13 – Monster Whisper
    14 – Monster Yell
    42 – Announce (Similar to a raid announcement)
    The 0 in the script tells us what language the monster should speak in. Here is a list of possible languages.
    Code:
    0 – Universal
    1 – Orcish
    2 - Darnassian
     3 - Tauren
    6 – Dwarven
    7 – Common
    8 – Demonic
    9 – Titan Language
    13 – Gnomish
    14 – Troll
    33 – Gutterspeak
    35 – Draenie language
    Now all you need to do is to end your script. This is always done with an ‘end’ in lua. So just throw an end at the end of the script and you are almost done. Your script should look something like this:
    Code:
    function BossName_OnCombat(pUnit, event)
    pUnit:SendChatMessage(14, 0, “My first lua boss script!”)
    end
    Now we need to register the event. Registering an event in lua looks like this:
    Code:
    RegisterUnitEvent(NPCID, When To Register It, “function name”)
    So your registration should look like this:
    Code:
    RegisterUnitEvent(YOUR NPC ID, 1, “BossName_OnCombat”)
    I’m going to go over what that ‘1’ means in the RegisterUnitEvent. The 1 is saying that you should register the event when the NPC enters combat. Here are the options that you can put there:
    Code:
    1 – Enter Combat
    2 – Leave Combat
    3 – Killed Target
    4 – When NPC dies
    6 – When NPC spawns
    7 – Gossip Talk
    8 – Reach Waypoint
    10 – When player enters range
    So now your final script should look like this:
    Code:
    Function BossName_OnCombat(pUnit, event)
    pUnit:SendChatMessage(14, 0, “My first lua boss script.”)
    end
    
    RegisterUnitEvent(YOURNPCID, 1, “BossName_OnCombat”)
    Congratulations! You have completed your first boss script!

    1.2 Making Your NPC Cast Spells
    Making your NPC cast spells is really what makes your boss script into an actual fight that players want to enjoy. WoWhead is your #1 source for finding spells/spell id’s, so use it whenever you need. So now that you have the basic structure for a script down we can begin making the boss cast spells. This can be done in many ways, I advise using FullCastSpellOnTarget. I will talk about the other ways at the end of the guide. So let’s get started. We will start with the same setup as before.
    Code:
    Function BossName_OnCombat(pUnit, event)
    Now this is where things are changed up. We are now going to use this:
    Code:
    pUnit:FullCastSpellOnTarget(SPELLID, TARGET)
    Now for the spell ID look at WoWhead, but for the target you can use this list:
    Code:
    pUnit:GetRandomPlayer(0) – Will make your NPC target a completely random player
    pUnit:GetRandomPlayer(1) – Will make your NPC target a random player in short range
    pUnit:GetRandomPlayer(2) – Will make your NPC target a random player in medium range
    pUnit:GetRandomPlayer(3) – Will make your NPC target a random player in long range
    pUnit:GetRandomPlayer(4) – Will make your NPC target a random player with mana
    pUnit:GetRandomPlayer(5) – Will make your NPC target a random player with rage
    pUnit:GetRandomPlayer(6) – Will make your NPC target a random player with energy
    pUnit:GetRandomPlayer(7) – Will make your NPC target a random player outside of the main tank
    pUnit:GetMainTank() – Makes your NPC target the main tank
    pUnit:GetClosestPlayer() – Makes your NPC target the closest player
    So you can replace TARGET with any of those above. In this guide we are going to have your NPC cast Fireball (Spellid 42833) on the main tank. So it should look like this
    Code:
    pUnit:FullCastSpellOnTarget(42833, pUnit:GetMainTank())
    Now for putting it all together and registering the event.
    Code:
    		function BossName_OnCombat(pUnit, event)
    		pUnit:FullCastSpellOnTarget(42833, pUnit:GetMainTank())
    		end
    		
    		RegisterUnitEvent(YOURNPCID, 1, “BossName_OnCombat”)
    You have successfully made your boss cast a spell!
    1.3 Making your NPC spawn other NPC’s
    Making your NPC spawn other NPC’s is really just as simple as everything else we have done. Spawning NPC’s is really a fun way to make a boss fight more interesting. So let’s get started. First we need to start by looking at what we will use to spawn NPCs. For this guide we will use this:
    Code:
    pUnit:SpawnCreature(NPCID, X, Y, Z)
    Simple enough right? Spawns an NPC with the id you listed at the x, y, and z coordinates you specified. Now you will have to get your own coordinates in-game as I won’t provide you with any for the guide. The easiest way to do that is to use the .gps command in-game and copy down the x, y, and z coords. Just like with all our other scripts this will be inside the BossName_OnCombat and will be registered just like the others. So throw in your coordinates and bam. Your script should look something like this:
    Code:
    function BossName_OnCombat(pUnit, event)
    pUnit:SpawnCreature(NPCID, X, Y, Z)
    end
    
    RegisterUnitEvent(YOURBOSSNPCID, 1, “BossName_OnCombat”)
    There you have it. Your boss will now spawn an NPC at those coordinates when you attack him!

    2. Creating Phases
    2.1 pUnit:RegisterEvent()
    PUnit:RegisterEvent() is a very important tool in a good lua scripters arsenal.
    Registering events this way makes it so that you can make the boss do far more than you could if you just used ‘RegisterUnitEvent’. Using ‘pUnit:RegisterEvent()’ provides us with a quick and easy way to do fun stuff. So here we go. Registering events always looks like this:
    Code:
    pUnit:RegisterEvent(“EventName”, Interval of Time, # of times you want the event to occur in the specified time)
    So just like before we will add that to our OnCombat function. Just remember that all time in lua is in milliseconds. 1000 is actually 1 second. Just a reminder for all of you. . So this is an idea of what your script could look like:
    Code:
    function BossName_OnCombat(pUnit, event)
    pUnit:RegisterEvent(“FirstRegisteredEvent”, 10000, 1)
     end
    Now when registering events like this you don’t have to register it again with the ‘RegisterUnitEvent’, but you do need to register the original event, which in this case is the ‘BossName_OnCombat’, but before we do that we should say what our ‘FirstRegisteredEvent’ is going to do. I’m going to make mine say something interesting.
    Code:
    function FirstRegisteredEvent(pUnit, event)
    pUnit:SendChatMessage(14, 0, “Something interesting!”)
    end
    Now we can add this to our original script, and then use ‘RegisterUnitEvent’ for our original OnCombat function. Once you have done that your script is finished, and you have successfully created a new event.

    Hope you enjoy what I have so far! The rest is coming shortly! Just need to figure out how to word it properly If you have any advice please tell me so I can add it to the guide.
    Last edited by Dr. Livingstone; 04-28-2009 at 09:18 PM.

    [GUIDE] Lua - Begginers -&gt; Advanced
  2. #2
    Linkn's Avatar Contributor
    Reputation
    90
    Join Date
    Mar 2009
    Posts
    296
    Thanks G/R
    0/0
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice guide so far, as for boss functions. I like to combine talking into a sort of mini cinematic with oncombat. Example:

    Code:
    function Mage_OnCombat(Unit, Event)
    Unit:SendChatMessage(14, 0, "What do you want!?")
    Unit:SetCombatCapable(1)
    Unit:SetFaction(35)
    Unit:RegisterEvent("Mage_TalkStart1", 1000, 0)
    end
    Unit:SetCombatCapable(1) No longer able to attack and
    Unit:SetFaction(35) friendly.

    Can also be combined with
    Unit:Root()
    Unit:Unroot()

    Code:
    function Mage_TalkStart1(Unit,Event)
    Unit:RemoveEvents()
    Unit:SetCombatCapable(1)
    x=Unit:GetX()
    y=Unit:GetY()
    z=Unit:GetZ()
    o=Unit:GetO()
    Unit:MoveTo(x, y+5, z, o)
    Unit:SendChatMessage(12, 0, "Wait..What!? How!? How are you here... I knew  I should of delt with you myself!")
    Unit:RegisterEvent("Mage_TalkStart2", 7000, 0)
    end
    You could go on with the cinematic as long as you want then register phase 1 or allow the mob to fight again with

    Code:
    Unit:SetCombatCapable(0)
    Unit:SetFaction(14)
    Also!
    Code:
    Unit:RegisterEvent("Mage_TalkStart2", 7000, 0)
    That number is how long the mob waits on the current message before moving to the next message or phase.

    Hopefully you get my point I'm trying to make +Rep for your guide though.
    Last edited by Linkn; 04-28-2009 at 09:34 PM.

  3. #3
    Dr. Livingstone's Avatar Member
    Reputation
    113
    Join Date
    Mar 2008
    Posts
    290
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. Maybe I'll add a section on cinematics when I get through this stuff. Good ideas too

  4. #4
    Kaiza's Avatar Member
    Reputation
    9
    Join Date
    Sep 2008
    Posts
    89
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice guide helped me alot,cuz i am new in scripting..... +rep ofc

  5. #5
    jrnkosik's Avatar Member
    Reputation
    1
    Join Date
    Apr 2009
    Posts
    16
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nice guide for noobs, i will use this fo sho. +rep

  6. #6
    runiker's Avatar Contributor
    Reputation
    105
    Join Date
    Nov 2007
    Posts
    501
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice guide as somebody who does lua on a day to day thing take it as a compliment.

  7. #7
    Fuynuns93's Avatar Active Member
    Reputation
    25
    Join Date
    Sep 2007
    Posts
    182
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great Guide! Easy to understand. +Repx2 :wave:

  8. #8
    Dr. Livingstone's Avatar Member
    Reputation
    113
    Join Date
    Mar 2008
    Posts
    290
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you everyone. I've been really busy and haven't been able to update this with the rest of what I wanted. I'm hoping to get back to this shortly.

  9. #9
    sapristi's Avatar Member
    Reputation
    1
    Join Date
    May 2009
    Posts
    1
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great guide for a lua beginner like me. Looking forward to the bit about teleporting as its something my kids really want.

  10. #10
    Death_Master's Avatar Member
    Reputation
    4
    Join Date
    Mar 2009
    Posts
    27
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nice guide

  11. #11
    samppaa's Avatar Member
    Reputation
    1
    Join Date
    Aug 2007
    Posts
    36
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very nice thanks! And would you add how to play sound when npc attacks like bosses usually talk ?
    Last edited by samppaa; 05-24-2009 at 07:40 AM.

Similar Threads

  1. [Guide] Lua Scripting Guide is here [Updating]
    By Illidan1 in forum WoW EMU Guides & Tutorials
    Replies: 93
    Last Post: 11-04-2008, 06:56 PM
  2. [Guide] LUA Portals
    By Gastricpenguin in forum WoW EMU Guides & Tutorials
    Replies: 83
    Last Post: 08-27-2008, 11:17 PM
  3. [Guide] LUA 2.
    By EmuX in forum WoW EMU Guides & Tutorials
    Replies: 3
    Last Post: 03-09-2008, 08:32 PM
  4. [Guide] LUA.
    By EmuX in forum WoW EMU Guides & Tutorials
    Replies: 4
    Last Post: 03-05-2008, 10:08 PM
  5. [Guide][LUA] Make a mob speak/use spell on a %!
    By Meltoor in forum WoW EMU Guides & Tutorials
    Replies: 14
    Last Post: 02-29-2008, 10:41 PM
All times are GMT -5. The time now is 10:04 AM. 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