Plugin Info:
|
Modification: ALL
Category: Technical/Development
|
Senior Member
Join Date: Jun 2010
Location: Ukraine
|
11-03-2016
, 08:18
[API] Custom Entities
|
#1
|
Custom Entities API
Description
This API help you create some custom entities for your mod with some presets like models, size, etc.
It's can be used to create gameplay entities, items, props.
Create custom entity on your mapJust create entity with custom classname, which registered in CE API Create custom entity
PHP Code:
new ceEnt = CE_Create(szClassname, vOrigin);
if (ceEnt) {
dllfunc(DLLFunc_Spawn, ceEnt);
}
Remove custom entity correctly
PHP Code:
CE_Remove(ent);
API
PHP Code:
#define CE_LOG_PREFIX "[CE]"
#define CE_BASE_CLASSNAME "info_target"
enum CEPreset
{
CEPreset_None = 0,
CEPreset_Item, // For items
CEPreset_NPC, // For NPC
CEPreset_Prop // For static props
};
enum CEFunction
{
CEFunction_Spawn, // Call when entity spawned
CEFunction_Kill, // Call when some plugin try to kill entity. return PLUGIN_HANDLED to discard kill.
CEFunction_Killed, // Call when entity killed
CEFunction_Remove, // Call when entity removed
CEFunction_Picked, // Call when player pick item
CEFunction_Pickup, // Call when player touch item. Should return PLUGIN_HANDLED if picked.
CEFunction_KVD // Call when new key value obtained
};
/*
* Register entity.
*
* @param szName Name of entity.
* @param modelIndex Precached model index.
* @param size Size of entity.
* @param offset Offset of entity origin.
* @param lifeTime Life time of entity.
* @param preset Preset for entity.
* @return Handler of registered entity.
*/
native CE_Register
(
const szName[],
modelIndex = 0,
const Float:vMins[3] = {-8.0, -8.0, -8.0},
const Float:vMaxs[3] = {8.0, 8.0, 8.0},
Float:fLifeTime = 0.0,
Float:fRespawnTime = 10.0,
bool:ignoreRounds = false,
CEPreset:preset = CEPreset_None
);
/*
* Spawn entity.
*
* @param szName Name of entity.
* @param vOrigin Spawn origin.
* @return Entity index.
*/
native CE_Create(const szName[], const Float:vOrigin[3], bool:temp = true);
/*
* Kill entity.
*
* @param ent Index of entity.
* @param killer Index of killer.
*/
native bool:CE_Kill(ent, killer = 0);
/*
* Gets size of entity.
*
* @param szClassname Classname of entity.
* @param vSize Output vector.
*/
native CE_GetSize(const szName[], Float:vMins[3], Float:vMaxs[3]);
/*
* Gets modelindex of entity.
*
* @param szClassname Classname of entity.
* @return Modelindex of entity
*/
native CE_GetModelIndex(const szName[]);
/*
* Remove entity correctly.
*
* @param ent Index of entity.
* @return Result true/false
*/
native bool:CE_Remove(ent);
/*
* Register new hook for entity.
*
* @param function Function handler
* @param szClassname Classname of entity
* @param szCallback Callback
*/
native CE_RegisterHook(CEFunction:function, const szClassname[], const szCallback[]);
/*
* Check if entity is associated with current plugin.
*
* @param ent Index of entity.
* @return Result true/false
*/
native CE_CheckAssociation_(ent);
stock bool:CE_CheckAssociation(ent) {
static bool:notified = false;
if (!notified) {
log_amx("%s function ^"CE_CheckAssociation^" is deprecated. Check ^"CE_GetHandlerByEntity^" function.", CE_LOG_PREFIX);
notified = true;
}
return CE_CheckAssociation_(ent);
}
native CE_GetHandler(const szClassname[]);
native CE_GetHandlerByEntity(ent);
CE_SPAWNER
Custom Entity Spawner.
Spawner KVD- ce_name (string) - Entity to spawn
- delay (float) - Delay before spawn (0.0 - spawn once per round)
- impulse (float) - Max velocity for entity after spawn.
__________________
Last edited by Hedgehog Fog; 11-17-2022 at 10:05.
|
|
|
|