Raised This Month: $ Target: $400
 0% 

Hook Entity Removal/Deletion/Killing


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Depresie
Veteran Member
Join Date: Nov 2013
Old 06-30-2017 , 14:23   Re: Hook Entity Removal/Deletion/Killing
Reply With Quote #1

Updated, also

1. is there any empty field on entities to store strings ? like pev_iuser1 ?
2. is there any other way to hook all weapons on Ham_ItemDeploy/Ham_ItemKill than hooking each one of them one by one or with a loop ?
__________________

Last edited by Depresie; 06-30-2017 at 14:25.
Depresie is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 06-30-2017 , 16:38   Re: Hook Entity Removal/Deletion/Killing
Reply With Quote #2

Quote:
Originally Posted by Depresie View Post
1. is there any empty field on entities to store strings ? like pev_iuser1 ??
You can use the Custom Entity Data module.
klippy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-01-2017 , 08:06   Re: Hook Entity Removal/Deletion/Killing
Reply With Quote #3

Quote:
Originally Posted by KliPPy View Post
You can use the Custom Entity Data module.
I did not look at the code, so could you explain how it's different than using a trie and saving data with entity id as key?

Quote:
Originally Posted by Depresie View Post
Hams, i remember somewhere you were explaining us how to retrieve the weapon entity index from within the weaponbox in FM_SetModel forward, but i don't remember where..
?
Retrieving in FM_SetModel is the same as retrieving anywhere else.

PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define MAX_ITEM_TYPES 6

new const m_rgpPlayerItems_CWeaponBox[MAX_ITEM_TYPES] = {3435, ...}

const 
m_pNext           42 
const XoCWeaponBox      4
const XoCBasePlayerItem 4

public plugin_init()
{
    
register_forward(FM_SetModel"pfnSetModel"false)
}

public 
pfnSetModel(const entity, const model[])
{
    if(
pev_valid(entity))
    {
        new 
className[32]
        
pev(entitypev_classnameclassNamecharsmax(className))
        if(
equal(className"weaponbox"))
        {
            new 
weaponEntity
            
for(new 1sizeof m_rgpPlayerItems_CWeaponBoxi++) 
            { 
                
weaponEntity get_pdata_cbase(entitym_rgpPlayerItems_CWeaponBox[i], XoCWeaponBox)
                while(
pev_valid(weaponEntity)) 
                { 
                    
//do your stuff
                    
weaponEntity get_pdata_cbase(weaponEntitym_pNextXoCBasePlayerItem)
                } 
            } 
        }
    }

While a weaponbox can contain multiple weapons and ammo types, in CS they usually contain only one. You could have weaponboxes with multiple weapons if a coder/mapper decides to do that, but by default there is only one.
This means that the while() loop is not really needed and the simplified code will be like:

PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define MAX_ITEM_TYPES 6

new const m_rgpPlayerItems_CWeaponBox[MAX_ITEM_TYPES] = {3435, ...}
const 
XoCWeaponBox      4

public plugin_init()
{
    
register_forward(FM_SetModel"pfnSetModel"false)
}

public 
pfnSetModel(const entity, const model[])
{
    if(
pev_valid(entity))
    {
        new 
className[32]
        
pev(entitypev_classnameclassNamecharsmax(className))
        if(
equal(className"weaponbox"))
        {
            new 
weaponEntity
            
for(new 1sizeof m_rgpPlayerItems_CWeaponBoxi++) 
            { 
                
weaponEntity get_pdata_cbase(entitym_rgpPlayerItems_CWeaponBox[i], XoCWeaponBox)
                if(
pev_valid(weaponEntity)) 
                { 
                    
//do your stuff
                    
break
                } 
            } 
        }
    }

I would still advise you to use the first code, the difference in performance is almost non-existent.
__________________
HamletEagle is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 07-02-2017 , 07:54   Re: Hook Entity Removal/Deletion/Killing
Reply With Quote #4

Quote:
Originally Posted by HamletEagle View Post
I did not look at the code, so could you explain how it's different than using a trie and saving data with entity id as key?
You don't have to worry about other plugins using the same entvar for storing data. Other than that, probably that it's just straight forward and more intuitive with proper native names.
klippy is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 07-02-2017 , 19:20   Re: Hook Entity Removal/Deletion/Killing
Reply With Quote #5

Quote:
Originally Posted by HamletEagle View Post
I did not look at the code, so could you explain how it's different than using a trie and saving data with entity id as key?
It also handles entity remove.
Quote:
Originally Posted by HamletEagle View Post
Because if there is no practical advantage over a trie I would not create unneded dependencies.
1. Readability - get/set functions, but you can also create them in your local implementation.
2. Error prone. But looks like that entity data implementation isn't complicated. (but, for example, player tasks in amxx are error prone, because even skilled amxx scripters sometimes forget to remove them on disconnect and other events)
__________________

Last edited by PRoSToTeM@; 07-02-2017 at 19:30.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Reply



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 23:11.


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