[LUA Scripting] Guide 2.0 menu

User Tag List

Results 1 to 1 of 1
  1. #1
    Blackheat's Avatar Member
    Reputation
    81
    Join Date
    Apr 2007
    Posts
    67
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [LUA Scripting] Guide 2.0

    ------|Forewords|------

    Welcome to the second guide that I release.
    If you feel that you understand the content in my first guide
    http://www.mmowned.com/forums/emulator-server-guides/220201-lua-scripting-beginners-1-0-a.html

    Then this is the place for you!
    In the last guide we learned how to script the bascics.
    In this guide on the otherhand it will get a little bit more advanced.
    We're going to script a NPC so that he will perform certain actions at a certain percentage!

    Let's start!

    As in any script we're going to start with the "function" line.

    Code:
    function NPC_Function/Phase(Unit, Event)
    Then we're adding some action!
    Let's suppose we want the boss to cast a spell and yell at 95%

    Code:
    function NPC_Function/Phase(Unit, Event)
    if Unit:GetHealthPct() < 95 then
    Unit:SendChatMessage(14, 0, "Message")
    Unit:FullCastSpellOnTarget(43488, Unit:GetRandomPlayer(0))
    end
    end
    Alright lets review.

    if Unit:GetHealthPct() < 95 then
    This signals the NPC to do a certail action at the certail percentage.

    Unit:FullCastSpellOnTarget(43488, Unit:GetRandomPlayer(0))
    FullCastSpellOnTarget - Cast's a (often) Offensive spell with casting time.
    43488 - This is the spell ID I chose, this is the spell "Wrath of the Lich King"
    It one shots a player.
    Unit:GetRandomPlayer(0) - Makes the NPC target a random player and cast the spell.

    Let's review the script as far as we are now.
    Note: Look out for the new stuff now that you've never seen. And I added a yell when the NPC enters combat.

    Code:
     
    function Arthas_OnCombat(Unit, Event)
    Unit:SendChatMessage(14, 0, "Fools, all of you!")
    Unit:RegisterEvent("Arthas_PhaseOne", 1000, 0)
    end
     
    function Arthas_PhaseOne(Unit, Event)
    if Unit:GetHealthPct() < 95 then
    Unit:RemoveEvents()
    Unit:SendChatMessage(14, 0, "Now you die!")
    Unit:FullCastSpellOnTarget(43488, Unit:GetRandomPlayer(0))
    end
    end
    "Unit:RegisterEvent("Arthas_PhaseOne", 1000, 0)"
    Okay, so what the heck is this?
    This is a command similiar to the "RegisterUnitEvent" But this is often used to register spells and/or events that occurs in the middle of a fight.
    1000 - This is how many seconds after 95% The script will activate. (1000 = 1 sec etc etc)
    0 - This signals how many times it should occur.

    That's pretty much it, you'll soon get a hang of it.
    More guides coming up :-)

    Next guide will contain a druid world boss!
    Don't miss that one!

    *Prowls into the shadows*
    Thank you for this time, I hope you learned anything from this guide.
    Farewell!


    Code:
    function Arthas_OnCombat(Unit, Event)
    Unit:SendChatMessage(14, 0, "Fools, all of you!")
    Unit:RegisterEvent("Arthas_PhaseOne", 1000, 0)
    end
     
    function Arthas_PhaseOne(Unit, Event)
    if Unit:GetHealthPct() < 95 then
    Unit:RemoveEvents()
    Unit:SendChatMessage(14, 0, "Now you die!")
    Unit:FullCastSpellOnTarget(43488, Unit:GetRandomPlayer(0))
    end
    end
     
    RegisterUnitEvent(NPCID, 1, "Arthas_OnCombat")
    
    Thanks to
    knaur - For teaching me so much!
    NE Team - For additional help.
    Last edited by Blackheat; 03-23-2009 at 05:41 PM.

    [LUA Scripting] Guide 2.0

Similar Threads

  1. [Wanted] Lua Scripting Guide
    By Kirsebaer in forum WoW EMU Questions & Requests
    Replies: 3
    Last Post: 12-13-2008, 09:25 PM
  2. [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
  3. Lua Scripting Guide
    By [Shon3m] in forum WoW EMU Guides & Tutorials
    Replies: 6
    Last Post: 06-16-2008, 02:03 PM
  4. [Guide] Another LUA Scripting Guide
    By Bapes in forum WoW EMU Guides & Tutorials
    Replies: 13
    Last Post: 05-08-2008, 05:01 PM
  5. LuA SCRIPTING (guide)
    By Dee2001 in forum WoW EMU Guides & Tutorials
    Replies: 5
    Last Post: 03-05-2008, 11:43 AM
All times are GMT -5. The time now is 05:13 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