ArcEmu: [Lua] Creature Event Additional Arguments - ArcEmu

Jump to content

Toggle shoutbox Lastest Announcements

dfighter  : (07 December 2014 - 12:06 PM) Arcemu is in hibernation mode, please read
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
Hasbro  : (14 August 2011 - 03:25 PM) Join us on irc, grab an irc client and connect to join channel #arcemu /server /join #arcemu
jackpoz  : (03 August 2011 - 05:33 AM) to all Lua Engine (old one) users: please check
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 - 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] Creature Event Additional Arguments

#1 User is offline   hypersniper 

  • Advanced Member
  • Group: Retired
  • Posts: 227
  • Joined: 21-November 08
  • Gender:Male

Posted 16 November 2009 - 04:07 AM

[left] Welcome to the first installment of the The More You Know™ Lua tutorial series. The idea of these are to give small but extremely useful pockets of information for Lua scripters. They are small so I can write them in my spare time when I have a lot going on, but still make contributions to the community.
Posted Image
Creature Events
I'm sure you all know what these are. When you're making an NPC script, the functions you register at the bottom are called Creature Events. You know:
RegisterUnitEvent(entryid, eventid, "function name")

Ringing any bells? I knew it would.
Just a reminder, there are 23 creature events. They are:
ON_HIT = 13
ON_FEAR = 15
ON_FLEE = 16
ON_LOAD = 18

You probably won't use - or perhaps haven't even heard of - most of them. 1, 2, 3, 4 and 18 are the most common.
Anyway, to the point of this guide. Let's take a look at a sweet script I made. On Combat, it causes the npc to yell "I'll eat your heart".
function Evil_Vrygul_OnCombat(pUnit, event)
    pUnit:SendChatMessage(14,0,"I'll eat your heart!")

RegisterUnitEvent(74001, 1, "Evil_Vrygul_OnCombat")

Wow. Spectacular. But haven't you always wanted him to say your name? Like, just to point out the idiot who pulled him accidently? Or perhaps you just want to be told on a more personal level of Mr. Vrygul's plans for dinner? Well, here's where it gets exciting.
function Evil_Vrygul_OnCombat(pUnit, event, pMisc)
    local name = pMisc:GetName()
    pUnit:SendChatMessage(14,0,"I'll eat your heart, ""!")

RegisterUnitEvent(74001, 1, "Evil_Vrygul_OnCombat")

Oh shi- I just did that. Just in case you don't know, the part just joins the variable name to the message. But that's not what I want you to notice. what IS that pMisc shiz I'm doing there?
Well, that pMisc is called an additional argument. Basically, in Creature Events, you as a scripter have access to more than you know. They have been kept secret for absolutely no reason. In this case, pMisc holds the player that started combat. In your Creature Event functions, you can add these additional arguments to give you more options. Each Creature Event comes with different additional arguments. Here's a neat list for you.
Event				Name	 Desc					Name2	Desc
ON_ENTER_COMBAT = 1	 	pMisc	 Who started combat		
ON_LEAVE_COMBAT = 2	 	pMisc	 Who was the target when combat ended		
ON_TARGET_DIED = 3	 	pMisc	 Who the unit killed		
ON_DIED = 4	 		pMisc	 Who dealt the killing blow to the unit		
ON_TARGET_PARRIED = 5	 	pMisc	 the target		
ON_TARGET_DODGED = 6		pMisc	 the target		
ON_TARGET_BLOCKED = 7	 	pMisc	 the target	 			Misc1	 Amount
ON_TARGET_CRIT_HIT = 8	 	pMisc	 the target	 			Misc1	 Amount
ON_PARRY = 9	 		pMisc	 the unit's current target		
ON_DODGED = 10	 		pMisc	 the unit's current target		
ON_BLOCKED = 11	 		pMisc	 the unit's current target	 	Misc1	 Amount
ON_CRIT_HIT = 12	 	pMisc	 the unit's current target		Misc1	 Amount
ON_HIT = 13	 		pMisc	 the unit's current target	 	Misc1	 Amount
ON_ASSIST_TARGET_DIED = 14	pMisc	 the unit's assist target		
ON_FEAR = 15	 		pMisc	 the feared target	 		Misc1	 spell id
ON_FLEE = 16	 		pMisc	 the fearer		
ON_CALL_FOR_HELP = 17	 	N/A			
ON_LOAD = 18	 		N/A			
ON_REACH_WP = 19	 	Misc1	 WaypointID	 			Misc2	 Moving forward (T/F)
ON_LOOT_TAKEN = 20	 	pMisc	 Player looting	 			pItem	 Looted item object
ON_AIUPDATE = 21	 	N/A			
ON_EMOTE = 22	 		pMisc	 Player	 				Misc1	 EmoteID
ON_DAMAGE_TAKEN = 23	 	pMisc	 Attacker	 			Misc1	 Amount

Common Examples
1. Making a ghoul spawn at a player's location On Kill:
function LichKing_OnKill(pUnit, event, pMisc)
    local name = pMisc:GetName()
    local X = pMisc:GetX()
    local Y = pMisc:GetY()
    local Z = pMisc:GetZ()
    pUnit:SendChatMessage(14,0,"You're corpse will not go to waste, ""!")
    pUnit:SpawnCreature(16244, X, Y, Z, 0, 14, 0)

RegisterUnitEvent(75001, 3, "LichKing_OnKill")

2. Giving reward to the player who deals the Killing Blow:
function LichKing_OnDeath(pUnit, event, pMisc)
    local name = pMisc:GetName()
    pMisc:SendAreaTriggerMessage("Congratulations, you dealt the killing blow to the Lich King.")
    pMisc:AddItem(80001, 1) --you're frostmourne id here
    pMisc:SendAreaTriggerMessage("The power of the Frostmourne flows through you, and only you. All shall hail you, the new Lich King!")
    pUnit:SendChatMessage(42, 0, "All hail "", the new Lich King!")

RegisterUnitEvent(75001, 4, "LichKing_OnDeath")

Posted Image
Final words: The best way to make the most of this is to play around with it! Give it a go. Make something unique today.
Please don't PM me asking to fix, correct or look-over your scripts. Please post a new thread in the Lua Scripting section so others can learn and help.

#2 User is offline   Cornflakes 

  • Newbie
  • Group: Members
  • Posts: 1
  • Joined: 08-November 09

Posted 25 November 2009 - 03:25 PM

I was exactly looking for the thing when creature says someone's name. :)
Thank you very much! Keep up the good work! :)


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