Raised This Month: $12 Target: $400
 3% 

Hook OnEntityDestroyed Helper (update 25.8.2022)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 08-24-2022 , 11:17   Hook OnEntityDestroyed Helper (update 25.8.2022)
Reply With Quote #1

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 EntRefany 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 EntRefHookOnEntityDestroyedCB callbackany 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); 


I red this feature request from github.
https://github.com/alliedmodders/sourcemod/issues/1827

So I practised little coding...

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"EntRefEntRefToEntIndex(EntRef));






Rant:
Attached Files
File Type: zip hookonentitydestroyed.zip (3.6 KB, 54 views)
File Type: zip hookonentitydestroyed-25.8.2022.zip (3.8 KB, 41 views)

Last edited by Bacardi; 08-25-2022 at 12:38.
Bacardi is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:40.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode