| {GUIDE} Lua Scripting | |
|
|
Author | Message |
---|
HalestormXV Sentinos
Posts : 43 Join date : 2008-03-21
| Subject: {GUIDE} Lua Scripting Sat Mar 22, 2008 9:46 am | |
| 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. - 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") 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: - 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_onDeathNow how does the script know when these events occur? Well that is what the little numbers are: - Quote :
- RegisterUnitEvent (26, 1, "Captain_Dementox_onCombat")
RegisterUnitEvent (26, 2, "Captain_Dementox_onLeaveCombat") RegisterUnitEvent (26, 4, "Captain_Dementox_onDeath") 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.
~Halestorm | |
|
| |
Fusion CN Gangster
Posts : 123 Join date : 2008-03-21 Location : Some ware deep in your hard drive
| Subject: Re: {GUIDE} Lua Scripting Sat Mar 22, 2008 1:30 pm | |
| thank you. ain't read it yet but i will when ive cooked food | |
|
| |
Hexagram† Sentinos
Posts : 50 Join date : 2008-03-21 Location : C:/Windows/System32/drivers
| |
| |
Fusion CN Gangster
Posts : 123 Join date : 2008-03-21 Location : Some ware deep in your hard drive
| Subject: Re: {GUIDE} Lua Scripting Sat Mar 22, 2008 3:28 pm | |
| i just read it could you please explain a few things pUnit:SendChatMessage( 11, 0,"Forgive me my prince....I have..failed...") what do those numbers mean also RegisterUnitEvent ( 26, 1, "Captain_Dementox_onCombat") that number there | |
|
| |
HalestormXV Sentinos
Posts : 43 Join date : 2008-03-21
| Subject: Re: {GUIDE} Lua Scripting Sat Mar 22, 2008 5:47 pm | |
| No problem. The 11 is the type of text such as say or yell, and the 0 is the type of language which is universal so everyone can see it.
The 26 is the entry ID number of the mob using this script. | |
|
| |
Fusion CN Gangster
Posts : 123 Join date : 2008-03-21 Location : Some ware deep in your hard drive
| Subject: Re: {GUIDE} Lua Scripting Sun Mar 23, 2008 5:22 am | |
| - HalestormXV wrote:
- No problem. The 11 is the type of text such as say or yell, and the 0 is the type of language which is universal so everyone can see it.
The 26 is the entry ID number of the mob using this script. thanxx what is the number for yell? | |
|
| |
HalestormXV Sentinos
Posts : 43 Join date : 2008-03-21
| Subject: Re: {GUIDE} Lua Scripting Sun Mar 23, 2008 9:34 am | |
| - Fusion wrote:
- HalestormXV wrote:
- No problem. The 11 is the type of text such as say or yell, and the 0 is the type of language which is universal so everyone can see it.
The 26 is the entry ID number of the mob using this script. thanxx what is the number for yell? 12 | |
|
| |
Hexagram† Sentinos
Posts : 50 Join date : 2008-03-21 Location : C:/Windows/System32/drivers
| Subject: Re: {GUIDE} Lua Scripting Sun Mar 23, 2008 11:06 pm | |
| BTW quick question how exactly would I save one of these as an LUA? Would I just open notepad and write this in it and save? Because it's not giving me the option to save as an LUA, only txt =[ | |
|
| |
MRHide Member
Posts : 22 Join date : 2008-03-21
| Subject: Re: {GUIDE} Lua Scripting Mon Mar 24, 2008 4:19 am | |
| yeah..but the second options you have under there "FILEFORMAT" you wright the name change the second options under to all files..and now you can typ filename.lua - Hexagram† wrote:
- BTW quick question how exactly would I save one of these as an LUA? Would I just open notepad and write this in it and save? Because it's not giving me the option to save as an LUA, only txt =[
| |
|
| |
Pyromagnetic CN Elite
Posts : 37 Join date : 2008-03-21
| |
| |
HalestormXV Sentinos
Posts : 43 Join date : 2008-03-21
| |
| |
Sponsored content
| Subject: Re: {GUIDE} Lua Scripting | |
| |
|
| |
| {GUIDE} Lua Scripting | |
|