Code:
-- We don't define Naga2
local NPCID = 100043
function Naga2_OnCombat(pUnit, event)
pUnit:SendChatMessage(14, 0, "What's this?! DIE MORTALS!!")
end
function Naga2_OnLeaveCombat(pUnit, event)
pUnit:SendChatMessage(14, 0, "HAHA RUN COWARDS!!")
-- There are no events to remove yet, removing events are stopping registered events with what does it, e.g: pUnit:RegisterEvent
end
function Naga2_OnKilledTarget(pUnit, event)
pUnit:SendChatMessage(14, 0, "Now that i killed you, I shall use your skull as a bowl for my Lucky Charms!")
end
function Naga2_OnDeath(pUnit, event)
pUnit:SendChatMessage(14, 0, "ARRGGHH THIS CAN'T BE!!!")
--pUnit:GetTarget() -- We need to define this, but easier to do the following:
pUnit:GetClosestPlayer():AddItem(1908,1)
-- Alternatively, pUnit:GetMainTank():AddItem(1908,1) -- Although I'm not sure if it looses the main target on death
--
-- Could be done similarly using variables:
-- local player = pUnit:GetClosestPlayer()
-- player:AddItem(1908,1)
--
--pUnit:AddItem(1908, 1) -- Were not adding the item to the unit
-- No events to remove, see above
end
RegisterUnitEvent(100043, 1, "Naga2_OnCombat")
RegisterUnitEvent(100043, 2, "Naga2_OnLeaveCombat")
RegisterUnitEvent(100043, 3, "Naga2_OnKilledTarget")
RegisterUnitEvent(100043, 4, "Naga2_OnDeath")
A -- = a comment. Get notepad++ if you haven't already, it helps so much when scripting.
I fixed up your script to get it to work how you want it to, but it's a really bad way to do it.
With your SQL, your getting a duplicate because a mob with that loot ID already exists in the database. Do:
SELECT * FROM `loot_creatures` WHERE `entry` = '999';
^
For example, change to correct values. Edit it to the correct details, or:
Change INSERT to REPLACE when executing your original query, so now it will look like:
REPLACE INTO `loot_creatures` VALUES (x,x,x,x,x,x,x);