[Help] OnHeal Event

Hey, So i’m trying to use OnHeal Event but it doesn’t seems to work.

This is my script :

void OnHeal(Unit* healer, Unit* reciever, uint32& gain) override
{
Player* pHealer = healer->ToPlayer();
Player* pReciever = reciever->ToPlayer();

	if (!pHealer || !pReciever)
		return;

	if (!pReciever->IsFriendlyTo(pHealer))
		return;

	if (gain >= 1) {
	pHealer->GetSession()->SendNotification("Okay", LANG_UNIVERSAL);
	pReciever->GetSession()->SendNotification("Okay", LANG_UNIVERSAL);
	}
}





Anyone know why it's not working ?

Can you post the whole script? Did you use UnitScript or CreatureScript like you should?

Try printing at the start of the function for example with
std::cout << “TEST MESSAGE” << std::endl;
and it should print to the worldserver.exe console and you can see if it executes at all. Another option could be debugging.

What does “not work” mean? Does the code not execute at all or was something else the issue?

This is the full Script :

https://gist.github.com/callmephil/06b735912554366736d5

OnHeal Event doesn’t work, nothing execute and i use it for players.

For X Amount Healed, Healer Should Receive an item.

Other Part of the Script Is Working Correctly.

[COLOR=rgb(39,42,52)]"OnHeal Event doesn’t work, nothing execute "

how did you test this?

I just checked on 6.x branch of TC and it works fine: http://prntscr.com/a1ln6j

I Heal myself or another player.

I Use 3.3.5. but i checked both function 3.3.5/6.X seems to be the same. so i can’t really understand why.

Lets assume the function triggers.
You could debug with some debugger or by simple prints and see where the function execution stops so it wont reach the end, or if it actually reaches the end.

EDIT:

Hmm, it seems the function doesnt indeed trigger on player healing himself for example even though the scriptmgr code triggers.
Seems “addtoscripts” here is false: https://github.com/TrinityCore/TrinityCore/blob/e24a6e52e99ca76f27b70feb086922ce46a0445e/src/server/game/Scripting/ScriptMgr.cpp#L1558
And thus the script is never added to the unitscript list and is never called.

So unitscript is useless in both player and creaturescripts. Instead maybe try simply UnitScript?
Otherwise I think this may need separate calls to the hook for both player and creature or some other workaround.

Made an issue about this: https://github.com/TrinityCore/TrinityCore/issues/16543