Lua Scripting Guide menu

User Tag List

Results 1 to 7 of 7
  1. #1
    [Shon3m]'s Avatar Banned
    Reputation
    128
    Join Date
    Apr 2007
    Posts
    669
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lua Scripting Guide

    LUA SCRIPTING GUIDE


    What you need:


    =======================
    1. Notepad
    2. Lua Enabled on your server
    =======================



    Alirte. I will give you a basic example of an Lua code and explain it to you.



    function Captain_Dementox_Enrage(pUnit, event)
    if pUnit:GetHealthPct() < 40 then
    pUnit:RemoveEvents()
    pUnit:PlaySoundToSet(11273)
    pUnit:CastSpell(33653)
    pUnit:CastSpell(36900)
    pUnit:SendChatMessage(11,0,"I have not come this far to be stopped! The future I have planned will not be jepordized! Now you will taste true power!")

    end

    function Captain_Dementox_onCombat (pUnit, Event)
    pUnit:PlaySoundToSet(11263)
    pUnit:SendChatMessage(11, 0, "Alas, sometimes one must take matters into one's own hands.")
    pUnit:RegisterEvent("Captain_Dementox_Enrage",1000,0)
    end

    function Captain_Dementox_onLeaveCombat(pUnit, Event)
    pUnit:RemoveAura(33653)
    pUnit:RemoveAura(36900)
    pUnit:RemoveEvents()
    end

    function Captain_Dementox_onDeath(pUnit, Event)
    pUnit:PlaySoundToSet(11204)
    pUnit:SendChatMessage(11,0,"Forgive me my prince....I have..failed...")
    pUnit:RemoveAura(33653)
    pUnit:RemoveAura(36900)
    pUnit:RemoveEvents()
    end

    RegisterUnitEvent (26, 1, "Captain_Dementox_onCombat")
    RegisterUnitEvent (26, 2, "Captain_Dementox_onLeaveCombat")
    RegisterUnitEvent (26, 4, "Captain_Dementox_onDeath")



    1. Alrite the word function is always needed. What it does is basically tell the script what you are GOING to do. The names can be whatever you want.

    2. The parenthesis (pUnit, Event) declares what you ARE doing.
    pUnit means npc/player, event means what it is. They are not so important. You just have to know they have to be there.

    3. Now I will list the basic commands in this code:

    1. pUnit:PlaySoundToSet(####) <--Plays a sound to the surrounding area

    2.pUnit:SendChatMessage(11,0,"Forgive me my prince....I have..failed...") <---Makes the NPC say what is in quotes

    3. pUnit:RemoveAura(####) <---Removes the spell ID that is on the unit

    4. punit:CastSpell(####) <---Casts the spell ID number on itself NOT on a player

    5. pUnit:GetHealthPct() <--- This allows the script to get the current percentage of the mob's health at the time it is executed.





    REGISTERING YOUR EVENTS


    Okay that is is a breakdown of the code. However in order to run these functions you need to tell the script when to run them and how to run them. This goes at the end of your code. In this example:


    RegisterUnitEvent (26, 1, "Captain_Dementox_onCombat")
    RegisterUnitEvent (26, 2, "Captain_Dementox_onLeaveCombat")
    RegisterUnitEvent (26, 4, "Captain_Dementox_onDeath")

    What we are telling the script to do is:

    1. run the event Captain_Dementox_onComat
    2. run the event Captain_Dementox_onLeaveCombat
    3. run the event Captain_Dementox_onDeath



    Now how does the script know when these events occur? Well that is what the little numbers are:


    [qoute]
    RegisterUnitEvent (26, 1, "Captain_Dementox_onCombat")
    RegisterUnitEvent (26, 2, "Captain_Dementox_onLeaveCombat")
    RegisterUnitEvent (26, 4, "Captain_Dementox_onDeath")
    [/qoute]

    The number 1 signifies that this will run once the mob enters combat
    The number 2 signifies that this will run when you run from a mob
    4. signifies that this will run when the mob is killed.

    These numbers are hard coded into your Lua engine. You can't just go making numbers up as the engine will not recognize what you are doing.

    That about does it for the explanation. I have requested for an Lua section to be created on the site so that all of you may post your scripts or ask for help on them. We will see if it is done. For now I will do the best I can to help you out from here. Lua is not very easy to explain. The best way to learn is by trial and error. I will post some smaller scripts as well that you can look at.

    Once you create a code in notepad you must save it as a .lua file. and then put it into the scripts folder in your ascent directory NOT the scripts_bin folder.

    By default Lua is disabled in ascent, you must enable it if you compile your own version. So you will find out if your server has it when you put scripts into the script folder of ascent and see if it loads up. Many repacks do have it enabled however.

    ________________________________________________________________________________
    __________________

    First we will find the mob we want to use for our script. Lets take the Kobold Vermin. Its creature ID in thottbot is 6. So lets say we want to Kobold to say "You can kiss my ass." when you aggro it. So here we go. Let start off with opening notepad. Here is the script:

    We want to first make the event or function so lets give it a simple name like "Kobold Aggro" so here is how we will write the event:



    function koboldAggro(pUnit, event)This is the name of the function. All your events/functions will have the word function before it. The (pUnit,event) is the type of function it is. This is going to be the majority of all your scripts. When more advaced stuff comes later on these will change.


    Okay now for the next part. We want to make the Kobold yell out his line rite? So here is how we do this:


    pUnit:SendChatMessage(12, 0, "You can kiss my ass.")Now for the breakdown.

    pUnit: is used becasue that is what you called it at the top in the (pUnit,event). This will be your most common pUnit

    Now the SendChatMessage(12, 0, "You can kiss my ass.") is broken down as follows.

    SendChatMessage -- this is the command we want to use to make the mob speak.
    12 -- means yell. So it will appear in yell
    0 -- means Universal language. Basically everyone can understand it
    "You can kiss my ass" -- what the mob will say.



    Now for the last part of the code.




    endThis is simply as it seems. This ends the function. Make sure your ends are placed properly or your script won't work. Generally speaking you only need 1 end at the end of your function. When you get into if statements and nested statements you will need more.


    So lets look at the script as a whole.

    function koboldAggro(pUnit, event)
    pUnit:SendChatMessage(12, 0, "You can kiss my ass.")
    end



    Spacing is very particular in Lua so is captials so make sure you don't make any mistakes with this. Plus everyone likes a neat code it makes things easier to read. Well we are almost done. So now we need to call this function rite? So here is how we do this.

    We make a special function. I made up a name for these type of functions. I call them Primary Functions. (I don't know if that is what they are really called. ) But I call these primary functions becasue you need them to intiate your script. So lets take a look at one primary function rite now.

    We call this one EnterCombat. Basically what it does is when you aggro a mob it will run the appropriate script so here is how we write this function.


    CODE
    CODE
    RegisterUnitEvent (6, 1, "koboldAggro")Now what is this? Alrite well this as you can see doesnt have the word function written before it. That is becasue it is a special function that is loaded when the server starts. There are only 10 of these that can be used. Check the Commands sticky for examples.


    Now the numbers in the code are these. the 6 is the entry ID of Kobold Vermin. The 1 means OnAggro or EnterCombat and the "koboldAggro" is the name of the function we made up top. So now ALL Kobold Vermins will do this function when you aggro them. Well I hope you understood this and it helped you out a bit. If you have more questions feel free to make a thread.

    Here is your end product:

    CODE
    CODE
    function koboldAggro(pUnit, event)
    pUnit:SendChatMessage(12, 0, "You can kiss my ass.")
    end


    RegisterUnitEvent (6, 1, "koboldAggro")
    Now save your script as Kobold.LUA and stick it in the scripts folder of your ascent server and restart your server. It is important that you save it as an lua or LUA file or it won't work.



    Good Luck
    Happy Scripting!

    Here are things to remember about Lua:

    It is EXTREMLY case sensative.
    It is Precise
    And you must be neat.


    All Made By Halestorm And if someone else from wow-v kills me bc of its there work then blame hale

    Lua Scripting Guide
  2. #2
    Power of Illuminati's Avatar Contributor
    Reputation
    179
    Join Date
    May 2008
    Posts
    1,410
    Thanks G/R
    6/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wrong section. Move it!

  3. #3
    TheSpidey's Avatar Elite User
    Reputation
    365
    Join Date
    Jan 2008
    Posts
    2,200
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You didn't even bother adding proper code boxes eh?

  4. #4
    LordDarkling's Avatar Active Member
    Reputation
    28
    Join Date
    Jul 2007
    Posts
    126
    Thanks G/R
    0/0
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ... umm why do people keep making LUA guides? there are so many, such as mine, gastric's and SEVERAL others... also wrong section
    Certs: CCNA, CCNA Sec, Security+, A+, Network+
    Willing to help with networking problems, just send me a PM.

    Professional software developer/machine learning engineer, please PM me if you have any questions about either of the two.

  5. #5
    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)
    Wrong section - repost - and no code boxes - bad color i give this thread a 1/10 jsut for trying. I have made a lua guide but it has not been active for while i guess i will update soon and bump it...

  6. #6
    [Shon3m]'s Avatar Banned
    Reputation
    128
    Join Date
    Apr 2007
    Posts
    669
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by runiker View Post
    Wrong section - repost - and no code boxes - bad color i give this thread a 1/10 jsut for trying. I have made a lua guide but it has not been active for while i guess i will update soon and bump it...


    because people need help some people r noobs 2 privte servers
    thats why...

  7. #7
    kajdzas's Avatar Corporal
    Reputation
    2
    Join Date
    Mar 2008
    Posts
    29
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Soularis, can you teach me "spell lua scripts"??? (if i aggro mob (kobold) he will cast some spell every 5 sec) pls send me guide to a MMOwned mail, THX!

Similar Threads

  1. [LUA Scripting] Guide 2.0
    By Blackheat in forum WoW EMU Guides & Tutorials
    Replies: 0
    Last Post: 03-23-2009, 05:35 PM
  2. [Wanted] Lua Scripting Guide
    By Kirsebaer in forum WoW EMU Questions & Requests
    Replies: 3
    Last Post: 12-13-2008, 09:25 PM
  3. [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
  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 09:09 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