AscentWorld
Would you like to react to this message? Create an account in a few clicks or log in to continue.



 
HomeHome  PortalPortal  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

 

 {GUIDE} Lua Scripting

Go down 
5 posters
AuthorMessage
HalestormXV
Sentinos
Sentinos
HalestormXV


Posts : 43
Join date : 2008-03-21

{GUIDE} Lua Scripting Empty
PostSubject: {GUIDE} Lua Scripting   {GUIDE} Lua Scripting EmptySat 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_onDeath


Now 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
Back to top Go down
Fusion
CN Gangster
CN Gangster
Fusion


Posts : 123
Join date : 2008-03-21
Location : Some ware deep in your hard drive

{GUIDE} Lua Scripting Empty
PostSubject: Re: {GUIDE} Lua Scripting   {GUIDE} Lua Scripting EmptySat Mar 22, 2008 1:30 pm

thank you. ain't read it yet but i will when ive cooked food
Back to top Go down
http://www.fusionprogramming.co.uk
Hexagram†
Sentinos
Sentinos
Hexagram†


Posts : 50
Join date : 2008-03-21
Location : C:/Windows/System32/drivers

{GUIDE} Lua Scripting Empty
PostSubject: Re: {GUIDE} Lua Scripting   {GUIDE} Lua Scripting EmptySat Mar 22, 2008 3:20 pm

Thanks alot for taking the time to post this Hale, this will help me alot sunny
Back to top Go down
Fusion
CN Gangster
CN Gangster
Fusion


Posts : 123
Join date : 2008-03-21
Location : Some ware deep in your hard drive

{GUIDE} Lua Scripting Empty
PostSubject: Re: {GUIDE} Lua Scripting   {GUIDE} Lua Scripting EmptySat 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 Razz
Back to top Go down
http://www.fusionprogramming.co.uk
HalestormXV
Sentinos
Sentinos
HalestormXV


Posts : 43
Join date : 2008-03-21

{GUIDE} Lua Scripting Empty
PostSubject: Re: {GUIDE} Lua Scripting   {GUIDE} Lua Scripting EmptySat 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.
Back to top Go down
Fusion
CN Gangster
CN Gangster
Fusion


Posts : 123
Join date : 2008-03-21
Location : Some ware deep in your hard drive

{GUIDE} Lua Scripting Empty
PostSubject: Re: {GUIDE} Lua Scripting   {GUIDE} Lua Scripting EmptySun 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?
Back to top Go down
http://www.fusionprogramming.co.uk
HalestormXV
Sentinos
Sentinos
HalestormXV


Posts : 43
Join date : 2008-03-21

{GUIDE} Lua Scripting Empty
PostSubject: Re: {GUIDE} Lua Scripting   {GUIDE} Lua Scripting EmptySun 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
Back to top Go down
Hexagram†
Sentinos
Sentinos
Hexagram†


Posts : 50
Join date : 2008-03-21
Location : C:/Windows/System32/drivers

{GUIDE} Lua Scripting Empty
PostSubject: Re: {GUIDE} Lua Scripting   {GUIDE} Lua Scripting EmptySun 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 =[
Back to top Go down
MRHide
Member
Member
MRHide


Posts : 22
Join date : 2008-03-21

{GUIDE} Lua Scripting Empty
PostSubject: Re: {GUIDE} Lua Scripting   {GUIDE} Lua Scripting EmptyMon 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 =[
Back to top Go down
Pyromagnetic
CN Elite
CN Elite
Pyromagnetic


Posts : 37
Join date : 2008-03-21

{GUIDE} Lua Scripting Empty
PostSubject: Re: {GUIDE} Lua Scripting   {GUIDE} Lua Scripting EmptyMon Mar 24, 2008 9:48 am

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 =[

lol away i do it is very quick and creative Smile

open your scripts folder and find any LUA file of your choice.

Copy it. and copy paste it on your desktop.

Rename the file on your desktop to w.e , edit it with notepad. delete everyting in it. and copy paste the code ppl posted in it. Smile save file and put it in your scripts folder.
Back to top Go down
HalestormXV
Sentinos
Sentinos
HalestormXV


Posts : 43
Join date : 2008-03-21

{GUIDE} Lua Scripting Empty
PostSubject: Re: {GUIDE} Lua Scripting   {GUIDE} Lua Scripting EmptyMon Mar 24, 2008 12:41 pm

Well when you want to save the Lua file you make in notepad you can just do

File
Save As
<name of file>.lua queen

Lol it is alot easier then all these creative ways I am reading.
Back to top Go down
Sponsored content





{GUIDE} Lua Scripting Empty
PostSubject: Re: {GUIDE} Lua Scripting   {GUIDE} Lua Scripting Empty

Back to top Go down
 
{GUIDE} Lua Scripting
Back to top 
Page 1 of 1
 Similar topics
-
» Can We Get a Guide?
» [GUIDE] ASCENT - GM COMMANDS
» [GUIDE] TOWARDS EARLIER REVISIONS
» [GUIDE] Compiling your OWN Core
» [REQUEST] Textureing/Skinning Guide

Permissions in this forum:You cannot reply to topics in this forum
AscentWorld :: Ascent Development :: Guides-
Jump to: