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?
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.
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.