Likes: 0
Results 1 to 4 of 4
Thread: LUA Scripting Guide
-
25-07-08, 01:36 PM #1
LUA Scripting Guide
Register to remove this adLUA SCRIPTING GUIDE
What you need:
=====================a==
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.
Code: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 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")
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:
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.
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:
Code: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
[code]
RegisterUnitEvent (26, 1, "Captain_Dementox_onCombat")
RegisterUnitEvent (26, 2, "Captain_Dementox_onLeaveCombat")
RegisterUnitEvent (26, 4, "Captain_Dementox_onDeath")
[code]
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:
Code: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.
Code: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.
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.
Code:function koboldAggro(pUnit, event) pUnit:SendChatMessage(12, 0, "You can kiss my ass.") end
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: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.
Here is your end product:
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.
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
› See More: LUA Scripting Guide
-
03-08-08, 08:17 AM #2
- Rep Power
- 17
- Reputation
- 11
Good Guide +1Rep
-
06-09-08, 03:22 AM #3
Got a possible guide on NPC teleporters? I'm trying to add in new locations to a teleporter but when trying it, the server eathier crashes OR it doesnt work.
-
06-09-08, 12:58 PM #4
Register to remove this adActually no sorry...if u ask one of the LUA experts...i'm pretty sure they can make you one or make a guide for one...
Related Threads - Scroll Down after related threads if you are only interested to view replies for above post/thread
Visitors found this page by searching for:
Nobody landed on this page from a search engine, yet!
SEO Blog