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
PHP Code:
/** * Sets custom entity data as cell * * @param entity Entity to set data for * @param key Identifier for data * @param data Data to be set * * @noreturn */ native CED_SetCell(entity, const key[], any:data);
/** * Sets custom entity data as array * * @param entity Entity to set data for * @param key Identifier for data * @param data Data to be set * @param size Size of the data array * * @noreturn */ native CED_SetArray(entity, const key[], const any:data[], size);
/** * Sets custom entity data as string * * @param entity Entity to set data for * @param key Identifier for data * @param buffer Data to be set * * @noreturn */ native CED_SetString(entity, const key[], const buffer[]);
/** * Gets custom entity data as cell * * @param entity Entity to get data for * @param key Identifier for data * @param data Variable to put data in * * @return true if data identified by |key| exists, false otherwise */ native bool:CED_GetCell(entity, const key[], &any:data);
/** * Gets custom entity data as array * * @param entity Entity to get data for * @param key Identifier for data * @param data Array to fill with data * @param size Maximum size of |data| array * * @return true if data identified by |key| exists, false otherwise */ native bool:CED_GetArray(entity, const key[], any:data[], size);
/** * Gets custom entity data as string * * @param entity Entity to get data for * @param key Identifier for data * @param buffer Buffer to put string data in * @param maxLength Maximum length of |buffer| buffer * * @return true if data identified by |key| existed, false otherwise */ native bool:CED_GetString(entity, const key[], buffer[], maxLength);
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.