ArcEmu: [lua] Lua Scripting - ArcEmu

Jump to content

Toggle shoutbox Lastest Announcements

dfighter  : (07 December 2014 - 12:06 PM) Arcemu is in hibernation mode, please read http://arcemu.org/fo...showtopic=26903
dfighter  : (01 January 2013 - 05:56 PM) Arcemu wishes you all a happy new year!
Hasbro  : (12 September 2012 - 10:01 AM) Please excuse our outage from the web! Our web host had a major malfunction!
dfighter  : (01 September 2012 - 04:05 PM) Since the spam bots just don't want to stop, I've enabled admin verification when registering.
dfighter  : (23 January 2012 - 09:56 PM) Please note that from now on you will need to confirm your email on the wiki in order to edit it!
Hasbro  : (31 December 2011 - 12:50 PM) Happy New Years all!
Navid  : (26 December 2011 - 04:09 AM) Merry Christmas !!!!!! Happy holidays all :)
WAmadeus  : (24 December 2011 - 03:54 PM) Merry Christmas to all!
dfighter  : (24 December 2011 - 11:05 AM) The Arcemu team wishes y'all a Merry Christmukkah!
Hasbro  : (05 October 2011 - 12:53 PM) Looking for web designers for upcoming web related project. If you're interested in designing user interfaces contact me
dfighter  : (02 September 2011 - 03:47 PM) So who here wants vehicles in Arcemu? :P http://arcemu.org/fo...showtopic=25440
Hasbro  : (14 August 2011 - 03:25 PM) Join us on irc, grab an irc client and connect to irc.freenode.net join channel #arcemu /server irc.freenode.net:6667 /join #arcemu
jackpoz  : (03 August 2011 - 05:33 AM) to all Lua Engine (old one) users: please check http://arcemu.org/fo...showtopic=25274
Hasbro  : (20 May 2011 - 05:27 PM) Looking for people experienced with CMake configuration and setup! Contact me asap
Hasbro  : (15 May 2011 - 05:03 PM) ArcEmu is recruiting C++ programmers, contact Hasbro if interested.
paroxysm  : (03 May 2011 - 06:26 PM) Updated luabridge gossip example to describe the whole gossip creation process rather than just how to create menu. Gossip tutorial
paroxysm  : (23 April 2011 - 11:35 AM) Lua writers can refer to the Luabridge Tutorials section in the Wiki to learn how to write gossip code correctly.
Hasbro  : (20 April 2011 - 05:22 PM) Thank you for your continuous contribution of bug reports, we are working on them.
Hasbro  : (17 April 2011 - 03:20 AM) Please consider donating to support our bills. Donations can be sent using PayPal to donations@arcemu.org - Thank you for your support.
paroxysm  : (10 April 2011 - 12:43 AM) Refer to the Luabridge Tutorials section in the Wiki to learn the new syntax of luabridge.
Resize Shouts Area

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[lua] Lua Scripting Big Explain

#1 User is offline   Zuel 

  • Member
  • Pip
  • Group: Members
  • Posts: 91
  • Joined: 11-November 11
  • Gender:Male
  • Server OS:Windows

Posted 08 January 2012 - 07:08 PM

Greetings everyone and welcome to Sjoerd's basic Lua Scripting tutorial for World of Warcraft. With this tutorial I will clearly and step for step learn you about the basics of a boss encounter. Make sure you are reading this tutorial step by step if you are a beginner

Introducion

1. Lua
2. Events
3. Spells
4. Phases
5. Extra additions



LUA

Lua is a great program for much games like World of Warcraft. The main thing to learn Lua is because it's one of the most used languages and one of the easiest to understand in games. With Lua you will get a great rank in developing at servers with a high community.

EVENTS

The Events are the ones who start a script. The most used Events are OnCombat, OnLeaveCombat, OnKilledTarget and OnDeath. I will clearly explain those basic Events to you and how to use them.

2.1. OnCombat
2.2. OnLeaveCombat
2.3. OnKilledTarget
2.4. OnDeath


OnCombat

OnCombat means when the player enters the in-combat range of the boss. When the player enters combat with the boss, then the script basicly starts. Here is an example how an OnCombat phase should look like with no events.

function Boss_OnCombat(pUnit, Event)
end


Let me explain these things to you:

function, the functions tell the script what to do.

Boss, this is the name of my boss, I have called him Boss because there isn't a better name for this tutorial. You can replace this name with your own name, Boss doesn't have anything to deal with what kind of boss it is.

OnCombat, this is the name of the function, at this point, the funcion is the OnCombat Event.

(pUnit, Event), I haven't put these things seperate because they are a must at every function. pUnit means the NPC, this doesn't mean you have to change pUnit into the name of your NPC, another thing about pUnit is that it doesn't have to be pUnit everytime. You can change pUnit in another name too. The only rule about this is that you can't have two names like pUnit and Unit, remind yourself on that. And Event is the Event, meaning with 'Event is the Event' is because the Event is OnCombat.

end, this means the end of the function. You only have to put one end because it ends on one function, will explain later about this at Phases.

Now we all had these explainations, we are going to make some changes in the OnCombat phase.

With these changes I mean that we are going to let the NPC talk when a player enters in-combat range, watch what I'm going to change.


function Boss_OnCombat(pUnit, Event)
pUnit:SendChatMessage(14, 0, "Welcome to my lair!")
end


This will let the NPC yell "Welcome to my lair!" Let me explain this about how I did this.

pUnit, here is pUnit again, pUnit is always used for things like this, and to cast spells, but I'm coming back on that later.

SendChatMessage, this will let the NPC send a chat message which the players can read

(14, 0, "Welcome to my lair!") I haven't put these things separate because they are all together. The number 14 means that he yells the chat message, the number 0 means that it is universial so that everyone can understand it. The text "Welcome to my lair!" is the text the NPC yells in universial, make sure you are putting it between "".

I'm going to show you some other languages and about in what sort of type he can say it:


How he can say it:

12 - Means that the NPC says something
13 - Means that the NPC whispers something
14 -- Means that the NPC yells something


In what sort of language he can say it:

0 -- Universal, means everyone can understand it
1 -- Orcish
2 -- Darnassian
3 -- Tauron
6 -- Dwarfs
7 -- Common
8 -- Demonic
9 -- Titan
13 -- Gnomish
14 -- Trolls
33 -- Gutterspeak
35 -- Draenei


Ok, this were the basics of an OnCombat Event, lets go to the other Events.

OnLeaveCombat

This is the OnLeaveCombat Event. The OnLeaveCombat Event is when the boss leaves combat with his opponents. You can have text with this too, but there is something else added to it also.

function Boss_OnLeaveCombat(pUnit, Event)
pUnit:SendChatMessage(14, 0, "You are to scared for my powers?!")
[color="red"]pUnit:RemoveEvents()[/color]
end


As you can see it's the same as OnCombat. But now I've added pUnit:RemoveEvents() add it. The reason why I'm doing this is because when you leave combat with him. It will remove all the current events, like casting spells and other things.

Now we are moving on the the next event.


OnKilledTarget

The OnKilledTarget event is not hard at all. You don't need to have pUnit:RemoveEvents() at this event. The reason why? I'll explain, when the boss kills an enemy, the script continues. If you put RemoveEvents() at is, he will start from the beginning. We don't want that ofcourse.

function Boss_OnKilledTarget(pUnit, Event)
end


Ofcourse, you can add more things to it. Like when he kills an enemy, he gets stronger or something. For that, we will use pUnit:CastSpell(). CastSpell() means that he casts a spell in Area of Effect, or on himself. You can look the spell ID's at Wowhead: Dataz! We need more dataz!., or www.thotbot.com. How to get those ID's? I'll explain. I want that my boss gets stronger everytime. I'll try to find the spell "Growth", I'm typing Growth at the search button of wowhead. Going to Uncategorized spells and I click on the spell I wanted. Now I'm at the page: Growth - Spell - World of Warcraft. As you can see the spell ID is on the end. This is how you find spells. Now, back on pUnit:CastSpell(). Now I've got the spellID. I need to copy and paste it into the brackets of CastSpell(), means the (). Lets add the pUnit:CastSpell() now to the event.

function Boss_OnKilledTarget(pUnit, Event)
pUnit:CastSpell(36300)
end


You can have text at it too ofcourse. If he gets stronger everytime, lets think of some text who fits in it.

function Boss_OnKilledTarget(pUnit, Event)
pUnit:SendChatMessage(14, 0, "Your worthless blood feeds me!")
pUnit:CastSpell(36300)
end


So, this was the OnKilledTarget event, not so hard is it?

OnDeath

The OnDeath event is just as easy as the others. You need to have pUnit:RemoveEvents() too and ofcourse, chatmessages are always welcome.

function Boss_OnDeath(pUnit, Event)
pUnit:SendChatMessage(14, 0, "That's impossible! Nooo!")
pUnit:RemoveEvents()
end


I don't have much to explain about only the main thing here, is the put the chatmessage above pUnit:RemoveEvents(). Why? Because otherwise it removes the events before he sends the chat message and it won't say anything then.

Ok! This were the explainations about all the basic Events in a boss encounter. How to put them in a script? I'll show you!


function Boss_OnCombat(pUnit, Event)
pUnit:SendChatMessage(14, 0, "Welcome to my lair!")
end

function Boss_OnLeaveCombat(pUnit, Event)
pUnit:SendChatMessage(14, 0, "You are to scared for my powers?!")
pUnit:RemoveEvents()
end

function Boss_OnKilledTarget(pUnit, Event)
pUnit:SendChatMessage(14, 0, "Your worthless blood feeds me!")
pUnit:CastSpell(36300)
end

function Boss_OnDeath(pUnit, Event)
pUnit:SendChatMessage(14, 0, "That's impossible! Nooo!")
pUnit:RemoveEvents()
end


It looks nice now, but how are these events activated? Well, really simple, you need to register these events with:

RegisterUnitEvent(EntryID, 1, "Boss_OnCombat")
RegisterUnitEvent(EntryID, 2, "Boss_OnLeaveCombat")
RegisterUnitEvent(EntryID, 3, "Boss_OnKilledTarget")
RegisterUnitEvent(EntryID, 4, "Boss_OnDeath")


This is the registering part of the events, I'm going to explain you step by step how it works.

RegisterUnitEvent, means that it registers the kind of event.

EntryID, here you need to put the EntryID of your NPC.

1, this shows what type of event it is. 1 means that it's the OnCombat event. 2 means OnLeaveCombat, 3, means OnKilledTarget and 4 means OnDeath. Those are basics, do not mess with these numbers, just put them at the right place.

"Boss_OnCombat", this is the name of the event, if you got another name on the OnCombat event, you need to change to name of it in the registering part too.

How do I put the registering part in the script? Simple, I'll show you!


function Boss_OnCombat(pUnit, Event)
pUnit:SendChatMessage(14, 0, "Welcome to my lair!")
end

function Boss_OnLeaveCombat(pUnit, Event)
pUnit:SendChatMessage(14, 0, "You are to scared for my powers?!")
pUnit:RemoveEvents()
end

function Boss_OnKilledTarget(pUnit, Event)
pUnit:SendChatMessage(14, 0, "Your worthless blood feeds me!")
pUnit:CastSpell(36300)
end

function Boss_OnDeath(pUnit, Event)
pUnit:SendChatMessage(14, 0, "That's impossible! Nooo!")
pUnit:RemoveEvents()
end

RegisterUnitEvent(EntryID, 1, "Boss_OnCombat")
RegisterUnitEvent(EntryID, 2, "Boss_OnLeaveCombat")
RegisterUnitEvent(EntryID, 3, "Boss_OnKilledTarget")
RegisterUnitEvent(EntryID, 4, "Boss_OnDeath")


Just down the whole script, you don't need to have function, end or whatever to it. This is the whole Registering part of the events.

Now, you should know how the events are working. Lets move to the next part


SPELLS

[color="[color="royalblue"]Alright! The part who shows what sort of boss it is, the part who shows how hard the boss is, the part shows how great the boss is!

Spells have everything to do with what type of boss it is and how hard it is. Without spells, the boss is nothing, but you know. Let me show you some ways how to have spells.[/color]

CastSpell()
FullCastSpell()
CastSpellOnTarget()
FullCastSpellOnTarget()


[color="royalblue"]I have showed you in the first part how to find an ID of a spell. So, I don't need to explain that anymore. And you know how CastSpell() works so I'm going to skip that too.[/color]

[color="red"]FullCastSpell(),[/color] [color="royalblue"]this means that he casts an Area of Efect spell with casttime or a spell on himself.
Example:[/color]

function Boss_Spell(pUnit, Event)
pUnit:FullCastSpell(SpellID)
end


[color="red"]CastSpellOnTarget(),[/color] [color="royalblue"]this is that he casts a spell on a target. You need to have the ID in the brackets ofcourse. But there is another thing you need to have on it, I'll red it up what I'm changing.[/color]

function Boss_Spell(pUnit, Event)
pUnit:CastSpellOnTarget(SpellID[color="red"], pUnit:GetMainTank()[/color])
end


[color="royalblue"]As you can see there is something new added. "pUnit:GetMainTank()". This means that he will target the main tank (the one with the highest treath). There are more targets he can target. I will show you which you can target more and how to use them.[/color]

pUnit:GetMainTank() -- He will target a player with the highest treath
pUnit:GetRandomPlayer(0) -- He will target a random player
pUnit:GetRandomPlayer(1) -- He will target a player in short range
pUnit:GetRandomPlayer(2) -- He will target a player in mid range
pUnit:GetRandomPlayer(3) -- He will target a player in longe range
pUnit:GetRandomPlayer(4) -- He will target a player with mana
pUnit:GetRandomPlayer(5) -- He will target a player with rage
pUnit:GetRandomPlayer(6) -- He will target a player with energy
pUnit:GetRandomPlayer(7) -- He will target a player who is not the main tank


[color="royalblue"]If you want to let him target someone else, just remove "pUnit:GetMainTank()" and put another target in it, by example someone in short range: "pUnit:GetRandomPlayer(1)".[/color]

[color="red"]FullCastSpellOnTarget(),[/color] [color="royalblue"]this is the same as CastSpellOnTarget() but this is now with casttime, looks like the same as CastSpell() and FullCastSpell(). You just need to use the same format as you did with CastSpellOnTarget().

Alright, now you know how to set the spells in an event, I'm going to show now how to register them.

Registering the spells has much to do with timing. I can't explain it really good in words now, so let me show an example. I will be using the OnCombat phase.[/color]

function Boss_OnCombat(pUnit, Event)
pUnit:SendChatMessage(14, 0, "Welcome to my lair!")
[color="red"]pUnit:RegisterEvent("Boss_Spell", 5000, 0)[/color]
end

[color="red"]function Boss_Spell(pUnit, Event)
pUnit:FullCastSpellOnTarget(SpellID, pUnit:GetMainTank())
end[/color]


[color="royalblue"]I will be explaining this step by step:[/color]

[color="red"]pUnit:RegisterEvent,[/color] [color="royalblue"]this will register the event "Boss_Spell". Without registering it, then it will not work.[/color]

[color="red"]("Boss_Spell",[/color] [color="royalblue"]this is the name of the event what the boss registers.[/color]

[color="red"], 5000, 0),[/color] [color="royalblue"]Now, the boss will register the function every 5000 miliseconds so, every 5 seconds. 1000 miliseconds = 1 second. The 0 means how many time it registers. The 0 here means that it registers every 5 seconds forever. You can replace the 0 by another number, by example 2. Then it will register only 2 times so he casts the spell 2 times and not forever.[/color]

[color="red"]function Boss_Spell(pUnit, Event)
pUnit:FullCastSpellOnTarget(SpellID, pUnit:GetMainTank())
end,[/color] [color="royalblue"]this is the event of a spell. As you can see, it contains 3 simple lines. The function, the spell and the end. This event looks very much on the oncombat phase. Most events do look like eachother. But it is just about what they are for. I named my function "Boss_Spell" because it's simple to understand in this tutorial. If you are making your own scripts, I recommend to not use Boss_Spell1 or something. Because when you are making more scripts, there could be a script interferne. This means that it will use the script of another script and your script for the boss in one. Use the name of your NPC and the name of your spell, like "KelThuzad_FrostBolt" but this could be simple way "Kel_FrostBolt" as long as you have the same name as the name in the registering part.

Now you should know:

How to make an event with a spell
How to register the event
How to lookup the spell
How to make it target someone else

Lets move on the to next part of our journey to Lua knowledge![/color]
0

#2 User is offline   Rigamaru 

  • Member
  • Pip
  • Group: Members
  • Posts: 18
  • Joined: 02-August 11
  • IRC:Rigamaru
  • Gender:Male
  • Location:USA
  • Server OS:Windows

Posted 08 January 2012 - 11:05 PM

This looks like sjoerdman tutorial... From AC-Web
0

#3 User is offline   dfighter 

  • Titles are overrated
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Administrator
  • Posts: 5,189
  • Joined: 14-June 08
  • IRC:dfighter
  • Gender:Male
  • Server OS:Linux

Posted 09 January 2012 - 12:53 PM

http://arcemu.org/wiki/Lua ??????
"The demand for free goods is infinite."
0

#4 User is offline   Zuel 

  • Member
  • Pip
  • Group: Members
  • Posts: 91
  • Joined: 11-November 11
  • Gender:Male
  • Server OS:Windows

Posted 21 April 2012 - 09:44 PM

View PostRigamaru, on 08 January 2012 - 11:05 PM, said:

This looks like sjoerdman tutorial... From AC-Web


Yea, i thought about sharing it here.
0

#5 User is offline   YuckFou 

  • Member
  • Pip
  • Group: Members
  • Posts: 13
  • Joined: 01-October 12
  • Gender:Male
  • Location:The Netherlands.
  • Server OS:Windows

Posted 05 October 2012 - 01:38 PM

Your text colouring got messed up at the end.
0

#6 User is offline   Zuel 

  • Member
  • Pip
  • Group: Members
  • Posts: 91
  • Joined: 11-November 11
  • Gender:Male
  • Server OS:Windows

Posted 21 October 2012 - 09:02 PM

View PostYuckFou, on 05 October 2012 - 01:38 PM, said:

Your text colouring got messed up at the end.


Yes, too lazy to edit it. xD
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users