This plugin example gives you:
- Ability to Hook an entity with your callback, calls when hooked entity goes through OnEntityDestroyed (SDKHooks)
Hook automatically removed from destroyed entity
- Option to pass your own any value from native to callback
PHP Code:
/** * Defines a HookOnEntityDestroyed Callback. * * @param EntRef Entity reference * @param data Data passed to the HookOnEntityDestroyed native. */ typeset HookOnEntityDestroyedCB { function void (int EntRef); function void (int EntRef, any data); }
/** * Calls the hooked entity function when entity is destroyed. * Hook removes automatically when entity destroyed * * @param EntRef Entity reference * @param callback HookOnEntityDestroyedCB function * @param data Value to be passed on the invocation of the Function. * @return True when entity hooked successfully. * False when already hooked or failure. * @error There are lot of things what could cause error */ native bool HookOnEntityDestroyed(int EntRef, HookOnEntityDestroyedCB callback, any data = 0);
/** * Unhook HookOnEntityDestroyed from entity * * @param EntRef Entity reference * @return True when entity unhooked successfully. * False when already unhooked or failure. * @error There are lot of things what could cause error */ native bool UnHookOnEntityDestroyed(int EntRef);
How to use it ?
- Don't edit hookonentitydestroyed.sp file
- Compile hookonentitydestroyed.sp, move your compiled hookonentitydestroyed.smx into server.
- hookonentitydestroyed.smx plugin process those hooked entities so you need keep it running on server all the time.
- Create your own SM plugin, #include <hookonentitydestroyed>
Use those natives.
There are two test plugins, compile and run both on server, you see results.
In those examples, plugin hook players when connected and when client disconnect, callbacks are executed.
quick
PHP Code:
#include <hookonentitydestroyed>
public void OnClientPostAdminCheck(int client) { HookOnEntityDestroyed(EntIndexToEntRef(client), MyOnEntityDestroyedCB); }
public void MyOnEntityDestroyedCB(int EntRef) { PrintToServer("MyOnEntityDestroyedCB %i index %i", EntRef, EntRefToEntIndex(EntRef)); }