Gaming Community
Forum
 
Go Back   D3scene > Hot Games > WoW forum > WoW Private Server Info & Help
Register Blogs Live view Downloads Marketplace FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

[SHARE] (Not my work): Lua script basic tut

This is a discussion on [SHARE] (Not my work): Lua script basic tut within the WoW Private Server Info & Help forum part of the WoW forum category; OK as the title say this is not my work. Credit goes to ac-web. I just thought I'd share it ...


Welcome on D3scene.com! Make sure to register - it's free and very quick! You have to register before you can post and participate in our discussions with 70000 other registered members. Downloads, user profiles and some forums can only be seen by registered members. After you create your free account you will be able to customize many options, you will have the full access to new hacks, latest cheats and last but not least will see no advertisements at all. We would love to see you around in our community!
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 04-09-2008, 12:17 PM
skhouri10's Avatar
So.... Whats up???

 
Join Date: Nov 2007
Location: Silvermoon in Sunfury Spire
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
Reputation: 149
Rep Power: 2
skhouri10 will become famous soon enoughskhouri10 will become famous soon enough
Send a message via MSN to skhouri10
[SHARE] (Not my work): Lua script basic tut

OK as the title say this is not my work. Credit goes to ac-web. I just thought I'd share it with you :grin:.

The Build of a LUA script:

Lua is a nice scripting method that allows you to scripts npc's.
You can let them cast spells and let them say things, so this is great if you want to script
an instance or a event boss/mob.

I will teach you the basics of LUA today, and we will start with the base of a script.
Everything that a npc needs to do starts with; FUNCTION and ends with END
so we get this:

Code:
 function functionname(pUnit or Unit, Event)
end
So if we fill it in we get this:

[code]function Example_OnCombat(Unit, Event)
end[\CODE]
This is how the beginning of a LUA script looks like.


Tutorial 1: The SendChatMessage Part
Ok, Now its time to let the npc say something.
We can do that by adding this:

Code:
 Unit:SendChatMessage(type, language, "Some text here")
To the Example_OnCombat
function and if we do that it looks like:

[code] function Example_OnCombat(Unit, Event)
Unit:SendChatMessage(type, language, "Some text here")
end[\CODE]
The Most used for type = 11 or 12
11= monster say
12= monster yell

And the most used for Language = 0
0 = universal, so every race can understand it.

Lets fill it in:

Code:
 function Example_OnCombat(Unit, Event)
Unit:SendChatMessage(12, 0, "My Tutorial is ownage")
end
Now we need to register the OnCombat function and we can do that if we add a: to the bottem of the script

Code:
RegisterUnitEvent(entryidofthenpc, event, "functionname")
If we do that our script will look like:

Code:
 function Example_OnCombat(Unit, Event)
Unit:SendChatMessage(12, 0, "My Tutorial is ownage")
end
RegisterUnitEvent(entryidofthenpc, 1, "Example_OnCombat")
This means if you enter his range and he starts to attack, he will yell: My tutorial is ownage.

Lets move on to the next part.



Tutorial 2: Adding More Functions


A LUA script can have more functions. The four basic functions are:
- OnCombat: Already added in the script
- OnDied
- OnKilledTarget
- OnLeaveCombat

If we add those functions to our script our script will look like:

Code:
 function Example_OnCombat(Unit, Event)
Unit:SendChatMessage(12, 0, "My Tutorial is ownage")
end

function Example_OnDied(Unit, Event)
Unit:RemoveEvents()
end

function Example_OnKilledTarget(Unit, Event)
end

function Example_OnLeaveCombat(Unit, Event)
Unit:RemoveEvents()
end

RegisterUnitEvent(entryidofthenpc, 1, "Example_OnCombat")
RegisterUnitEvent(entryidofthenpc, 2, "Example_OnLeaveCombat")
RegisterUnitEvent(entryidofthenpc, 3, "Example_OnKilledTarget")
RegisterUnitEvent(entryidofthenpc, 4, "Example_OnDied")
This will allow the mob to do things when he:
- Starts to fight
- Dies
- Killed someone
- Leave combat



Tutorial 3: Adding spells to the NPC

Non Area on Effect Spell;On Targets.
A scripted npc is kinda boring without spells, so lets add them!
We can do that by adding another function to the script:

Code:
 function Example_Spellname(pUnit, Event)
end
And if you have made the function, you need to add a:

Code:
 pUnit:CastSpellOnTarget(spellid, pUnit:Getwho?)         = Without casting time

or

Code:
 pUnit:FullCastSpellOnTarget(spellid, pUnit:Getwho?)  = With casting time
So if we do that we get this:

f
Code:
unction Example_Spellname(pUnit, Event)
pUnit:CastSpellOnTarget(spellid, pUnit:Getwho?)
end
Code:
 *Getwho can be:
- GetRandomPlayer(0) = Random Player
- GetRandomPlayer(1) = Random in Short-Range
- GetRandomPlayer(2) = Random in Mid-Range
- GetRandomPlayer(3) = Random in Long-Range
- GetRandomPlayer(4) = Random with Mana
- GetRandomPlayer(5) = Random with Rage
- GetRandomPlayer(6) = Random With Energy
- GetRandomPlayer(7) = Random NOT Main-Tank
- GetMainTank()
- GetClosestPlayer()
*
Ok, now I want to add it to my script, and we can do that by adding a:

Code:
 Unit:RegisterEvent("nameofthefunction", timeinmiliseconds, howmuchtimes)
to the prefered function, in this case to the OnCombat function:

Code:
 function Example_OnCombat(Unit, Event)
Unit:SendChatMessage(12, 0, "My Tutorial is ownage")
Unit:RegisterEvent("Example_Spellname", 10000, 0)
end

function Example_Spellname(pUnit, Event)
pUnit:CastSpellOnTarget(spellid, pUnit:GetRandomPlayer(0))
end

function Example_OnDied(Unit, Event)
Unit:RemoveEvents()
end

function Example_OnKilledTarget(Unit, Event)
end

function Example_OnLeaveCombat(Unit, Event)
Unit:RemoveEvents()
end

RegisterUnitEvent(entryidofthenpc, 1, "Example_OnCombat")
RegisterUnitEvent(entryidofthenpc, 2, "Example_OnLeaveCombat")
RegisterUnitEvent(entryidofthenpc, 3, "Example_OnKilledTarget")
RegisterUnitEvent(entryidofthenpc, 4, "Example_OnDied")
If you got some problems with the targeting system, like that the NPC cast it on itself.
Then try this code:

Code:
 function Name_Event(pUnit, Event)
local plr = pUnit:GetRandomPlayer(0) <-- Or something else
if (plr ~= nil) then
pUnit:FullCastSpellOnTarget(SpellID, plr)
end
end
Area on Effect Spell:
Its also nice to let the npc cast an AoE spell like Blizzard.
We can do that by adding this function to the script:

Code:
 function Example_Blizzard(Unit, Event)
Unit:CastSpell(Spellid)
end
And we also need to register our function with the:

Code:
 Unit:RegisterEvent("nameofthefunction", timeinmilisec, howmuchtimes)
to the OnCombat Function:

Our script will look like this if we do that:

Code:
 function Example_OnCombat(Unit, Event)
Unit:SendChatMessage(12, 0, "My Tutorial is ownage")
Unit:RegisterEvent("Example_Spellname", 10000, 0)
Unit:RegisterEvent("Example_Blizzard", 20000, 5)
end

function Example_Spellname(pUnit, Event)
pUnit:CastSpellOnTarget(spellid, pUnit:GetRandomPlayer(0))
end

function Example_Blizzard(Unit, Event)
Unit:CastSpell(Spellid)
end

function Example_OnDied(Unit, Event)
Unit:RemoveEvents()
end

function Example_OnKilledTarget(Unit, Event)
end

function Example_OnLeaveCombat(Unit, Event)
Unit:RemoveEvents()
end

RegisterUnitEvent(entryidofthenpc, 1, "Example_OnCombat")
RegisterUnitEvent(entryidofthenpc, 2, "Example_OnDied")
RegisterUnitEvent(entryidofthenpc, 3, "Example_OnKilledTarget")
RegisterUnitEvent(entryidofthenpc, 4, "Example_OnLeaveCombat")
Other events:

Code:
SendChatMessage Events:
type:
11 – npc say   = Nice for little gossips 
12 – npc yell  = Cool for boss fights
13 – npc whisper

Language:
0 = UNIVERSAL <= I use this the most
1 = ORCISH
2 = DARNASSIAN
3 = TAUREN
6 = DWARVISH
7 = COMMON
8 = DEMONIC
9 = TITAN
10 = THELASSIAN
11 = DRAGONIC
12 = KALIMAG
13 = GNOMISH
14 = TROLL
33 = GUTTERSPEAK
35 = DRAENEI

RegisterUnitEvents events:
eventtype:
1 = Enter Combat  <= Important
2 = Leave Combat  <= Important
3 = Killed Target <= Important
4 = Died          <= Important
5 = AI Tick
6 = Spawn         <= Also a nice one
7 = Gossip Talk
8 = Reach Waypoint
9 = On Leave Limbo
10 = Player Enters RangeHope u like and once again this is not my work

Last edited by skhouri10; 04-09-2008 at 12:25 PM.
Reply With Quote
D3scene
Welcome to D3scene - probably the best location for all Gamers.

To participate in our friendly environment you have to register. After completing registration you will have full access to all threads and features. We care about members and try to make your stay as pleasant as possible. We are unique with the following feature for members - you will not see a single Advertisement!


The best: registration is completely free. It will not cost you a single penny or harm you in any way. You will lose nothing except 1 minute of your time. So why not register? We would be happy to see you around!
  #2  
Old 04-10-2008, 06:02 PM
Hacker

 
Join Date: Jan 2008
Posts: 214
Thanks: 0
Thanked 0 Times in 0 Posts
Reputation: 85
Rep Power: 2
Marshal will become famous soon enough
Good copy : ) rep+
Reply With Quote
D3scene
Welcome to D3scene - probably the best location for all Gamers.

To participate in our friendly environment you have to register. After completing registration you will have full access to all threads and features. We care about members and try to make your stay as pleasant as possible. We are unique with the following feature for members - you will not see a single Advertisement!


The best: registration is completely free. It will not cost you a single penny or harm you in any way. You will lose nothing except 1 minute of your time. So why not register? We would be happy to see you around!
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Antfamous Gauntlet Bot v1.8 for mmBot tschoerk Diablo 2 Hacks 9 04-29-2009 03:33 PM


All times are GMT +1. The time now is 02:32 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.0 ©2009, Crawlability, Inc.
vBulletin style developed by Transverse Styles