PDA

View Full Version : [Lua] How to make an NPC unattackable in Lua



Lbniese
18-09-09, 10:48 AM
Making an NPC unattackable in Lua.
This tutorial requires the ArcEmu rev: 2700+

Making an NPC unattackable is the perfect thing for your cutscenes for your boss. You don't want your boss in the middle of a cut-scene to be killed by an inpatient Warlock shadow bolting it, do you? Well, there is only one way at this time of writing to do this.
function NegEtheriumBossOnOnePercent(Unit, Event)
if Etherium:GetHealthPct() == 1 then
Etherium:RemoveEvents()
Etherium:SetUInt32Value(58, 2) -- Set the NPC to be unattackable,
Etherium:RemoveAllAuras()
Etherium:SetCombatCapable(1)
print("Etherium has been defeated. Spawning cache...")
Etherium:RegisterEvent("NegEtheriumCINESix", 1, 1)
Etherium:RegisterEvent("NegEtheriumCINESeven", 5000, 1)
Etherium:RegisterEvent("NegEtheriumCINEEight", 15000, 1)
Etherium:RegisterEvent("NegEtheriumCINENine", 22000, 1)
Etherium:RegisterEvent("NegEtheriumCINETen", 27000, 1)
Etherium:RegisterEvent("NegEtheriumCINEEleven", 29000, 1)
Etherium:RegisterEvent("NegEtheriumKill", 30000, 1)
--[[
Spawn Cache Event here..
]]--
else
end
end

This is an excerpt from my own, unfinished, script. The bit we are interested in is this bit:

Etherium:SetUInt32Value(58, 2) -- Set the NPC to be unattackable,
Etherium:RemoveAllAuras()
Etherium:SetCombatCapable(1)
What this code does is that it sets the NPC to be unattackable (but still displays it as hostile), removes all debuffs/buffs from him, and then makes him unable to attack.

Unit:SetUInt32Value(58, 2)
This bit sets the NPC as unattackable. If you click him, he is displayed as hostile, but you won't see the sword when you mouse-over. You won't be able to attack him, at all.

Unit:SetUInt32Value(58, 26)
The above code will make the NPC unselectable from the client.

To make him attackable again, you use this code:

Unit:SetUInt32Value(58, 0)
Quite simple eh? It's certainly not the most ideal solution, but it is the only way to do this in Lua as of this writing.

So, to recap. SetUInt32Value(58, 2) will set the NPC as unattackable, SetUInt32Value(52, 0) will set the NPC as attackable.


Furthermore, here are all of the Unit flags (That are known as of r2850)

2 -- Client won't let you attack the mob
4 -- Makes players & NPCs attackable/unattackable
256 -- Changes attackable status
13 -- Sets PVP Flag
14 -- Silenced
15 -- Dead
17 -- Alive
18 -- Pacified
19 -- Stunned
20 -- Sets Combat Flag
21 -- Sets the same flag as mounted on a taxi (Can't cast spells)
22 -- Disarmed
23 -- Confused
24 -- Fleeing/Fear
25 -- Makes players & NPCs attackable/unattackable
26 -- Unselectable
27 -- Skinnable
30 -- Feign Death
NOTE THAT THE UNIT FLAGS CHANGE EVERY CLIENT UPDATE.
Hope this helps you,

lbniese

enegue
21-09-09, 06:54 AM
Nice guide.

Lbniese
21-09-09, 10:50 AM
thanks

LiLLeCarl
21-09-09, 05:01 PM
all this lua :D go over to C++ so the emulation development can continue :D

Lbniese
22-09-09, 01:05 AM
Nope, i like lua... not c++ :D :P

enegue
22-09-09, 07:47 AM
LUA is like kiddy language in coding. Grow up! Learn the MAN/WOMAN language aka C++!!!

Lbniese
23-09-09, 09:23 AM
LUA is like kiddy language in coding. Grow up! Learn the MAN/WOMAN language aka C++!!!
No way, i like LUA and i stay on lua :D .....

enegue
24-09-09, 08:14 AM
Then you're a kid!

Avidgamer
24-09-09, 08:40 AM
Enegue, you cant speak. You dont know C++ properly either. :)

enegue
25-09-09, 05:09 AM
I'm learning it! And I do know from other developers that LUA is kid language. Developers like... K.

Avidgamer
25-09-09, 10:56 AM
Actually.. LUA is not a kid language... It's a Language that simple.. but works - doesn't mean it's for kids. Just cause you cant learn it, doesn't mean you should have a go and say it's Kid language..

And those Devvelopers, I'd say are idiotic twats if they feel a language that's easier but usefull is 'Kid Language'

Lbniese
30-09-09, 10:37 AM
I'm learning it! And I do know from other developers that LUA is kid language. Developers like... K.
Epic Fail m8, Kids cant understand Lua and c++...
maybe a bit. but not good enough to make a teleport, boss or a pvp system :P

Avidgamer
30-09-09, 10:57 AM
Well, actually they can. So stop giving kids less credit than they deserve. Half of them are (probably) smarter than you Lbniese.

I know quite a few kids that know C++ better than the majority of people, Lua also.

B00M
30-09-09, 12:20 PM
Very nice - Rep+

Lbniese
02-10-09, 07:25 AM
Well, actually they can. So stop giving kids less credit than they deserve. Half of them are (probably) smarter than you Lbniese.

I know quite a few kids that know C++ better than the majority of people, Lua also.
Lol m8, i am a "Kid" i am 16 years old, then kid or teenager :P

enegue
02-10-09, 09:56 PM
Indeed. 16 year old kid acting like a 5 year old and reviving topics that dates back to September 2008 is so not stupid shit. You think by acting smart on the forums, you can gain respect? Go learn how to earn respect instead of posting shit which are not yours. Sharing is fine, L2 give credits. Don't give any to yourself cause you posted it here.

I know the creator of MaNGOS and he started MaNGOS when he was just 7 years old. Looks like kids are much better than people like you.