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

[API] Custom Entities


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Plugin Info:     Modification:   ALL        Category:   Technical/Development       
Hedgehog Fog
Senior Member
Join Date: Jun 2010
Location: Ukraine
Old 11-03-2016 , 08:18   [API] Custom Entities
Reply With Quote #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 map
Just create entity with custom classname, which registered in CE API
Create custom entity

PHP Code:
new ceEnt CE_Create(szClassnamevOrigin);
if (
ceEnt) {
    
dllfunc(DLLFunc_SpawnceEnt);


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.08.08.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(entkiller 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.


Attached Files
File Type: sma Get Plugin or Get Source (api_custom_entities.sma - 203 views - 22.2 KB)
File Type: inc api_custom_entities.inc (3.0 KB, 117 views)
File Type: sma Get Plugin or Get Source (entity_ce_spawner.sma - 1222 views - 5.3 KB)
__________________

❄️ CS Snow Wars - Mod based on snowballs fights
🧟 CS Zombie Panic - A port of HL Zombie Panic!
🎃 CS Halloween Mod - Completely new gamemode for Halloween Holidays
📦 AMXXPack - CLI and build system for amxx projects
🔧 Custom Entities API - API to register custom entities

Last edited by Hedgehog Fog; 11-17-2022 at 10:05.
Hedgehog Fog is offline
 



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


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