How to give kill credit using a script


I’m trying to make a quest work. In this quest, the player must kill a boss, when the boss dies if the player has the quest then it will have an aura and the player must use an item on the body to get the killcredit, then the aura will disappear.
The problem is that when I use the item (specifically, a staff), the aura disappears, but the player doesn’t get the kill credit. So i found in Wowhead the ID of the kill credit and tried to fix it using a script.

This is what I did:

			[COLOR=rgb(167,29,93)]void [COLOR=rgb(121,93,163)]SpellHit(Unit* [COLOR=rgb(150,152,150)]caster, [COLOR=rgb(167,29,93)]const SpellInfo* spell) OVERRIDE


			[COLOR=rgb(167,29,93)]if (spell->Id == SPELL_USED_BY_THE_STAFF)

caster->ToPlayer()->KilledMonsterCredit(NPC_CREDIT, 0);


However, it doesn’t work, it doesn’t give the kill credit. Could you give me some help?

You can most certainly achieve that by using SmartAI. Take a look at this Editor: