AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   Module: Custom Entity Data (https://forums.alliedmods.net/showthread.php?t=294188)

klippy 02-22-2017 00:03

Module: Custom Entity Data
 
Description:

This module lets you bind custom user data to entities without dealing with fields like pev_iuser[1-4] or similar. The reason this module is created is that this way you are not limited by the amount of pev_* fields and plugins or the game dll won't interfere with each other (modifying the same pev_* fields).


API:

The API is pretty similar to the Trie API - you can retrieve or set cells, arrays and strings, which are identified by a string key.
When an entity is destroyed, all data bound to it gets destroyed too - that means that you have to free any handles (like Trie, Array, Stack or others) bound to that entity or they will get lost/leaked.

customentdata.inc



Install instructions:

Put customentdata_amxx.dll (Windows) or customentdata_amxx_i386.so (Linux) into $moddir/addons/amxmodx/modules.


Todo:
  • Create an "OnEntityDestroyed" hook or similar to let the user easily free any bound handles.


Downloads:

Source code on GitHub

gabuch2 02-22-2017 06:12

Re: Module: Custom Entity Data
 
Awesome

georgik57 02-22-2017 07:07

Re: Module: Custom Entity Data
 
One entity data module to rule them all.
Thank you master Klippy.

PRoSToTeM@ 02-22-2017 11:50

Re: Module: Custom Entity Data
 
Good job, but you can hook OnFreeEntPrivateData from API instead of hooking ED_Free.

klippy 02-22-2017 14:27

Re: Module: Custom Entity Data
 
Thank you peeps.

@PRoSToTeM@: I just took a look, that would be more proper, thanks, I'll fix that soon.

klippy 02-23-2017 19:18

Re: Module: Custom Entity Data
 
Updated per PRoSToTeM@'s suggestion.

PRoSToTeM@ 02-23-2017 20:40

Re: Module: Custom Entity Data
 
You misunderstood me. I mean hook OnFreeEntPrivateData via NewDLL API. You should uncomment
PHP Code:

#define FN_OnFreeEntPrivateData                OnFreeEntPrivateData 

or
PHP Code:

#define FN_OnFreeEntPrivateData_Post            OnFreeEntPrivateData_Post 

in moduleconfig to use it.

klippy 02-23-2017 21:00

Re: Module: Custom Entity Data
 
I am aware of that it exists there, but calls to engine/game dll functions via Metamod plugins aren't propagated to other Metamod plugins IIRC. That's why for example you can't hook FM_PrecacheModel that other AMXX plugin executed. That's why I kept on using CHooker.

PRoSToTeM@ 02-23-2017 21:17

Re: Module: Custom Entity Data
 
There are two kinds of functions in API that you can call (they are located in engfuncs) and that you can hook (events) (I mean original API from engine, not metamod, they are located in EntityAPI(2) and NewDLLFunctions). PrecacheModel is that you can call, so basically you can hook it to customize gamedll behaviour only. FreeEntPrivateData has two versions FreeEntPrivateData that you can call (engfunc) and OnFreeEntPrivateData event (NewDllFunction). FreeEntPrivateData engfunc calls OnFreeEntPrivateData (you can see that in ReHLDS). So, you can hook OnFreeEntPrivateData via API without any problems. Emulating OnFreeEntPrivateData can break some code in gamedll, this is like undefined behaviour (I mean fakecall from some plugin).

meTaLiCroSS 02-24-2017 02:16

Re: Module: Custom Entity Data
 
I was thinking on doing something like this, I complained because I thought it would be slow. Good job, this kind of addons will have a big impact if is integrated in the main AMXX package.


All times are GMT -4. The time now is 21:26.

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