Network: WoW Gold | WoW Accounts | MPS Games | FPSowned
MMOwned - World of Warcraft Exploits, Hacks, Bots and Guides
Homepage »      Register »      Hall of Fame »      Ranks And Awards »      Advertise »      Marketplace »
 
Sign up



Do you like this excellent information? Then Donate HERE to remove ads and support the MMOwned community.


Go Back   MMOwned - World of Warcraft Exploits, Hacks, Bots and Guides > WoW Emulator Server > Emulator Server Guides

Emulator Server Guides Guides for working with World of Warcraft Emulator servers. Learn how to create a WoW Server here.
[NO QUESTIONS HERE]

Reply
 
LinkBack Thread Tools
  #1  
Old 04-28-2009
Dr. Livingstone's Avatar
Dr. Livingstone is offline.
Knight-Lieutenant
  
 
Join Date: Mar 2008
Posts: 250
Reputation: 71
Points: 1,052, Level: 2
Points: 1,052, Level: 2 Points: 1,052, Level: 2 Points: 1,052, Level: 2
Level up: 31%, 348 Points needed
Level up: 31% Level up: 31% Level up: 31%
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
[GUIDE] Lua - Begginers -> Advanced

There are a LOT of lua guides out there right now, but I’ve tried to create a guide that would let you start as a beginner, and by the end you would have some skills in lua and be able to continue to figure more things out for yourself. First we are starting with boss scripts, after boss scripts comes gossip, and after gossip comes item/gobject gossip. Then after that I will give some nifty tips and some more advanced ideas. .

Boss Scripts
1. Creating Your First Script!
1.1 Making your NPC talk
1.2 Making your NPC cast spells
1.3 Making your NPC spawn other NPCs

2. Creating Phases
2.1 Using pUnit:RegisterEvent to create phases
2.2 Using ‘if’ statements to your advantage
2.3 Removing events with pUnit:RemoveEvent()

3. Variables <3 You
3.1 Local =

3.2 Using variables to change things up
3.3 Variables and math.random


NPC Gossip Scripts
1. Creating A Basic Gossip Menu
[
1.1 Making Your NPC broadcast a message
1.2 Making your NPC teleport a player
1.3 Making your NPC morph a player
1.4 Making your NPC buff a player


2. Making Gossip Scripts Fit With Boss Scripts
2.1 Gossip NPC spawning other NPC’s
2.2 Gossip NPC starting an event


Item Gossip Scripts
1. Setting Up An Item Gossip Script
1.1 Creating a warp stone
1.2 Creating an information stone
1.3 Creating a wishing stone


----------------------------------------------------------------------------------------------------------------------------------------------------
1. Creating Your First Script!
1.1 Making your NPC talk.
I personally think that making an NPC talk is the easiest thing to
script, and it gives us the ability to provide a good starting point when it comes to creating events and that sort of thing. So right here I will introduce you to the structure of every lua script. Some things may be different depending on the script, but generally this is how they will all start.
Code:
 function BossName_OnCombat(pUnit, event)
Now this is telling you what the boss will do when he enters combat. So let’s state what we want the boss to do when he enters combat. We will make him say, “My first lua boss script.” So we need to add this to our script.
Code:
 pUnit:SendChatMessage(14, 0, “My first lua boss script.”)
Let me explain. This is saying the NPC is going to send a chat message in ‘Monster Yell’ (That’s what the 14 is saying), and he is saying “My first lua boss script.” It is really that simple. Now there are a lot of things that can be used instead of 14. I normally use one of the following:
Code:
12 – Monster Say
13 – Monster Whisper
14 – Monster Yell
42 – Announce (Similar to a raid announcement)
The 0 in the script tells us what language the monster should speak in. Here is a list of possible languages.
Code:
0 – Universal
1 – Orcish
2 - Darnassian
 3 - Tauren
6 – Dwarven
7 – Common
8 – Demonic
9 – Titan Language
13 – Gnomish
14 – Troll
33 – Gutterspeak
35 – Draenie language
Now all you need to do is to end your script. This is always done with an ‘end’ in lua. So just throw an end at the end of the script and you are almost done. Your script should look something like this:
Code:
function BossName_OnCombat(pUnit, event)
pUnit:SendChatMessage(14, 0, “My first lua boss script!”)
end
Now we need to register the event. Registering an event in lua looks like this:
Code:
RegisterUnitEvent(NPCID, When To Register It, “function name”)
So your registration should look like this:
Code:
RegisterUnitEvent(YOUR NPC ID, 1, “BossName_OnCombat”)
I’m going to go over what that ‘1’ means in the RegisterUnitEvent. The 1 is saying that you should register the event when the NPC enters combat. Here are the options that you can put there:
Code:
1 – Enter Combat
2 – Leave Combat
3 – Killed Target
4 – When NPC dies
6 – When NPC spawns
7 – Gossip Talk
8 – Reach Waypoint
10 – When player enters range
So now your final script should look like this:
Code:
Function BossName_OnCombat(pUnit, event)
pUnit:SendChatMessage(14, 0, “My first lua boss script.”)
end

RegisterUnitEvent(YOURNPCID, 1, “BossName_OnCombat”)
Congratulations! You have completed your first boss script!

1.2 Making Your NPC Cast Spells
Making your NPC cast spells is really what makes your boss script into an actual fight that players want to enjoy. WoWhead is your #1 source for finding spells/spell id’s, so use it whenever you need. So now that you have the basic structure for a script down we can begin making the boss cast spells. This can be done in many ways, I advise using FullCastSpellOnTarget. I will talk about the other ways at the end of the guide. So let’s get started. We will start with the same setup as before.
Code:
Function BossName_OnCombat(pUnit, event)
Now this is where things are changed up. We are now going to use this:
Code:
pUnit:FullCastSpellOnTarget(SPELLID, TARGET)
Now for the spell ID look at WoWhead, but for the target you can use this list:
Code:
pUnit:GetRandomPlayer(0) – Will make your NPC target a completely random player
pUnit:GetRandomPlayer(1) – Will make your NPC target a random player in short range
pUnit:GetRandomPlayer(2) – Will make your NPC target a random player in medium range
pUnit:GetRandomPlayer(3) – Will make your NPC target a random player in long range
pUnit:GetRandomPlayer(4) – Will make your NPC target a random player with mana
pUnit:GetRandomPlayer(5) – Will make your NPC target a random player with rage
pUnit:GetRandomPlayer(6) – Will make your NPC target a random player with energy
pUnit:GetRandomPlayer(7) – Will make your NPC target a random player outside of the main tank
pUnit:GetMainTank() – Makes your NPC target the main tank
pUnit:GetClosestPlayer() – Makes your NPC target the closest player
So you can replace TARGET with any of those above. In this guide we are going to have your NPC cast Fireball (Spellid 42833) on the main tank. So it should look like this
Code:
pUnit:FullCastSpellOnTarget(42833, pUnit:GetMainTank())
Now for putting it all together and registering the event.
Code:
		function BossName_OnCombat(pUnit, event)
		pUnit:FullCastSpellOnTarget(42833, pUnit:GetMainTank())
		end
		
		RegisterUnitEvent(YOURNPCID, 1, “BossName_OnCombat”)
You have successfully made your boss cast a spell!
1.3 Making your NPC spawn other NPC’s
Making your NPC spawn other NPC’s is really just as simple as everything else we have done. Spawning NPC’s is really a fun way to make a boss fight more interesting. So let’s get started. First we need to start by looking at what we will use to spawn NPCs. For this guide we will use this:
Code:
pUnit:SpawnCreature(NPCID, X, Y, Z)
Simple enough right? Spawns an NPC with the id you listed at the x, y, and z coordinates you specified. Now you will have to get your own coordinates in-game as I won’t provide you with any for the guide. The easiest way to do that is to use the .gps command in-game and copy down the x, y, and z coords. Just like with all our other scripts this will be inside the BossName_OnCombat and will be registered just like the others. So throw in your coordinates and bam. Your script should look something like this:
Code:
function BossName_OnCombat(pUnit, event)
pUnit:SpawnCreature(NPCID, X, Y, Z)
end

RegisterUnitEvent(YOURBOSSNPCID, 1, “BossName_OnCombat”)
There you have it. Your boss will now spawn an NPC at those coordinates when you attack him!

2. Creating Phases
2.1 pUnit:RegisterEvent()
PUnit:RegisterEvent() is a very important tool in a good lua scripters arsenal.
Registering events this way makes it so that you can make the boss do far more than you could if you just used ‘RegisterUnitEvent’. Using ‘pUnit:RegisterEvent()’ provides us with a quick and easy way to do fun stuff. So here we go. Registering events always looks like this:
Code:
pUnit:RegisterEvent(“EventName”, Interval of Time, # of times you want the event to occur in the specified time)
So just like before we will add that to our OnCombat function. Just remember that all time in lua is in milliseconds. 1000 is actually 1 second. Just a reminder for all of you. . So this is an idea of what your script could look like:
Code:
function BossName_OnCombat(pUnit, event)
pUnit:RegisterEvent(“FirstRegisteredEvent”, 10000, 1)
 end
Now when registering events like this you don’t have to register it again with the ‘RegisterUnitEvent’, but you do need to register the original event, which in this case is the ‘BossName_OnCombat’, but before we do that we should say what our ‘FirstRegisteredEvent’ is going to do. I’m going to make mine say something interesting.
Code:
function FirstRegisteredEvent(pUnit, event)
pUnit:SendChatMessage(14, 0, “Something interesting!”)
end
Now we can add this to our original script, and then use ‘RegisterUnitEvent’ for our original OnCombat function. Once you have done that your script is finished, and you have successfully created a new event.

Hope you enjoy what I have so far! The rest is coming shortly! Just need to figure out how to word it properly If you have any advice please tell me so I can add it to the guide.
__________________

NXDHosting.com - For All Your Hosting Needs!

Last edited by Dr. Livingstone; 04-28-2009 at 11:18 PM.
Reply With Quote


Donate to remove ads, get your "DONATOR title, and get access to the MMOwned community's elite Shoutbawx.

  #2  
Old 04-28-2009
Linkn's Avatar
Linkn is offline.
Knight-Lieutenant
  
 
Join Date: Mar 2009
Location: Middle Earth
Posts: 227
Reputation: 71
Points: 1,346, Level: 2
Points: 1,346, Level: 2 Points: 1,346, Level: 2 Points: 1,346, Level: 2
Level up: 90%, 54 Points needed
Level up: 90% Level up: 90% Level up: 90%
Activity: 1.9%
Activity: 1.9% Activity: 1.9% Activity: 1.9%

Nice guide so far, as for boss functions. I like to combine talking into a sort of mini cinematic with oncombat. Example:

Code:
function Mage_OnCombat(Unit, Event)
Unit:SendChatMessage(14, 0, "What do you want!?")
Unit:SetCombatCapable(1)
Unit:SetFaction(35)
Unit:RegisterEvent("Mage_TalkStart1", 1000, 0)
end
Unit:SetCombatCapable(1) No longer able to attack and
Unit:SetFaction(35) friendly.

Can also be combined with
Unit:Root()
Unit:Unroot()

Code:
function Mage_TalkStart1(Unit,Event)
Unit:RemoveEvents()
Unit:SetCombatCapable(1)
x=Unit:GetX()
y=Unit:GetY()
z=Unit:GetZ()
o=Unit:GetO()
Unit:MoveTo(x, y+5, z, o)
Unit:SendChatMessage(12, 0, "Wait..What!? How!? How are you here... I knew  I should of delt with you myself!")
Unit:RegisterEvent("Mage_TalkStart2", 7000, 0)
end
You could go on with the cinematic as long as you want then register phase 1 or allow the mob to fight again with

Code:
Unit:SetCombatCapable(0)
Unit:SetFaction(14)
Also!
Code:
Unit:RegisterEvent("Mage_TalkStart2", 7000, 0)
That number is how long the mob waits on the current message before moving to the next message or phase.

Hopefully you get my point I'm trying to make for your guide though.

Last edited by Linkn; 04-28-2009 at 11:34 PM.
Reply With Quote
  #3  
Old 04-29-2009
Dr. Livingstone's Avatar
Dr. Livingstone is offline.
Knight-Lieutenant
  
 
Join Date: Mar 2008
Posts: 250
Reputation: 71
Points: 1,052, Level: 2
Points: 1,052, Level: 2 Points: 1,052, Level: 2 Points: 1,052, Level: 2
Level up: 31%, 348 Points needed
Level up: 31% Level up: 31% Level up: 31%
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Thanks. Maybe I'll add a section on cinematics when I get through this stuff. Good ideas too
__________________

NXDHosting.com - For All Your Hosting Needs!
Reply With Quote
  #4  
Old 04-29-2009
Kaiza's Avatar
Kaiza is offline.
Master Sergeant
  
 
Join Date: Sep 2008
Location: In your mind
Posts: 90
Reputation: 9
Points: 872, Level: 1
Points: 872, Level: 1 Points: 872, Level: 1 Points: 872, Level: 1
Level up: 95%, 28 Points needed
Level up: 95% Level up: 95% Level up: 95%
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%

Nice guide helped me alot,cuz i am new in scripting..... +rep ofc
Reply With Quote
  #5  
Old 04-30-2009
jrnkosik is offline.
Site n00b.. (A leecher if I've been here for more than a month and can't earn 5 rep)
  
 
Join Date: Apr 2009
Posts: 16
Reputation: 1
nice guide for noobs, i will use this fo sho. +rep
Reply With Quote
  #6  
Old 05-12-2009
runiker's Avatar
runiker is offline.
Contributor
  
 
Join Date: Nov 2007
Posts: 500
Reputation: 98
Points: 3,919, Level: 6
Points: 3,919, Level: 6 Points: 3,919, Level: 6 Points: 3,919, Level: 6
Level up: 36%, 581 Points needed
Level up: 36% Level up: 36% Level up: 36%
Activity: 2.6%
Activity: 2.6% Activity: 2.6% Activity: 2.6%

Nice guide as somebody who does lua on a day to day thing take it as a compliment.
__________________
Reply With Quote
  #7  
Old 05-13-2009
Fuynuns93's Avatar
Fuynuns93 is offline.
Sergeant Major
  
 
Join Date: Sep 2007
Posts: 172
Reputation: 25
Points: 1,323, Level: 2
Points: 1,323, Level: 2 Points: 1,323, Level: 2 Points: 1,323, Level: 2
Level up: 85%, 77 Points needed
Level up: 85% Level up: 85% Level up: 85%
Activity: 0.7%
Activity: 0.7% Activity: 0.7% Activity: 0.7%

Great Guide! Easy to understand. x2
__________________

Reply With Quote
  #8  
Old 05-13-2009
Dr. Livingstone's Avatar
Dr. Livingstone is offline.
Knight-Lieutenant
  
 
Join Date: Mar 2008
Posts: 250
Reputation: 71
Points: 1,052, Level: 2
Points: 1,052, Level: 2 Points: 1,052, Level: 2 Points: 1,052, Level: 2
Level up: 31%, 348 Points needed
Level up: 31% Level up: 31% Level up: 31%
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Thank you everyone. I've been really busy and haven't been able to update this with the rest of what I wanted. I'm hoping to get back to this shortly.
__________________

NXDHosting.com - For All Your Hosting Needs!
Reply With Quote
  #9  
Old 05-22-2009
sapristi is offline.
Site n00b.. (A leecher if I've been here for more than a month and can't earn 5 rep)
  
 
Join Date: May 2009
Posts: 1
Reputation: 1
Points: 84, Level: 1
Points: 84, Level: 1 Points: 84, Level: 1 Points: 84, Level: 1
Level up: 21%, 316 Points needed
Level up: 21% Level up: 21% Level up: 21%
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%

Great guide for a lua beginner like me. Looking forward to the bit about teleporting as its something my kids really want.
Reply With Quote
  #10  
Old 05-22-2009
Death_Master's Avatar
Death_Master is offline.
Site Donator
  
 
Join Date: Mar 2009
Location: at my PC
Posts: 25
Reputation: 4
Points: 199, Level: 1
Points: 199, Level: 1 Points: 199, Level: 1 Points: 199, Level: 1
Level up: 50%, 201 Points needed
Level up: 50% Level up: 50% Level up: 50%
Activity: 0.4%
Activity: 0.4% Activity: 0.4% Activity: 0.4%

nice guide
Reply With Quote
  #11  
Old 05-24-2009
samppaa's Avatar
samppaa is offline.
New User
  
 
Join Date: Aug 2007
Posts: 29
Reputation: 1
Points: 562, Level: 1
Points: 562, Level: 1 Points: 562, Level: 1 Points: 562, Level: 1
Level up: 33%, 338 Points needed
Level up: 33% Level up: 33% Level up: 33%
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%

Very nice thanks! And would you add how to play sound when npc attacks like bosses usually talk ?

Last edited by samppaa; 05-24-2009 at 09:40 AM.
Reply With Quote
Reply

Thread Tools

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 Off
Pingbacks are Off
Refbacks are On



All times are GMT -4. The time now is 07:42 PM.




Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493