Raised This Month: $13 Target: $400
 3% 

[DEBUG] plugin api_custom_entities


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alferd
Veteran Member
Join Date: Dec 2019
Old 05-31-2020 , 12:16   [DEBUG] plugin api_custom_entities
Reply With Quote #1

hello, Does anyone know what the problem is?

error:
Code:
L 05/31/2020 - 20:37:40: [AMXX] Displaying debug trace (plugin "api_custom_entities.amxx")
L 05/31/2020 - 20:37:40: [AMXX] Run time error 10: native error (native "TrieGetCell")
L 05/31/2020 - 20:37:40: [AMXX]    [0] api_custom_entities.sma::OnKeyValue (line 332)
L 05/31/2020 - 20:37:40: Invalid trie handle provided (0)
Plugin:
PHP Code:
#pragma semicolon 1

#include <amxmodx>
#include <amxmisc>

#include <engine>
#include <fakemeta>
#include <hamsandwich>

#include <cellarray>
#include <celltrie>

#include <xs>

#define PLUGIN    "[API] Custom Entities"
#define VERSION    "1.2.1"
#define AUTHOR    "Hedgehog Fog"

#define CE_BASE_CLASSNAME "info_target"
#define LOG_PREFIX "[CE]"

#define TASKID_SUM_DISAPPEAR 1000
#define TASKID_SUM_RESPAWN   2000
#define TASKID_SUM_REMOVE    3000

/*--------------------------------[ Constants ]--------------------------------*/

enum CEPreset
{
    
CEPreset_None 0,
    
CEPreset_Item,
    
CEPreset_NPC,
    
CEPreset_Prop
};

enum CEFunction
{
    
CEFunction_Spawn,
    
CEFunction_Kill,
    
CEFunction_Killed,
    
CEFunction_Remove,
    
CEFunction_Picked,
    
CEFunction_Pickup,
    
CEFunction_KVD
};

enum CEHookData
{
    
CEHookData_PluginID,
    
CEHookData_FuncID
};

enum _:RegisterArgs
{
    
RegisterArg_Name 1,
    
RegisterArg_ModelIndex,
    
RegisterArg_Mins,
    
RegisterArg_Maxs,
    
RegisterArg_LifeTime,
    
RegisterArg_RespawnTime,
    
RegisterArg_IgnoreRounds,
    
RegisterArg_Preset
};

enum _:CEData
{
    
CEData_Handler,
    
CEData_TempIndex,
    
CEData_WorldIndex,
    
CEData_StartOrigin
};

/*--------------------------------[ Variables ]--------------------------------*/

new g_ptrBaseClassname;

new 
Trie:g_entityHandlers;
new Array:
g_entityName;
new Array:
g_entityPluginID;
new Array:
g_entityModelIndex;
new Array:
g_entityMins;
new Array:
g_entityMaxs;
new Array:
g_entityLifeTime;
new Array:
g_entityRespawnTime;
new Array:
g_entityPreset;
new Array:
g_entityIgnoreRounds;
new Array:
g_entityHooks;

new 
g_entityCount 0;

new Array:
g_worldEntities;
new Array:
g_tmpEntities;

new 
g_lastCEIdx 0;
new 
g_lastCEEnt 0;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    if (
g_lastCEEnt) {
        
dllfunc(DLLFunc_Spawng_lastCEEnt); // spawn last handled entity
    
}
    
    
RegisterHam(Ham_TouchCE_BASE_CLASSNAME"OnTouch", .Post 1);
    
RegisterHam(Ham_KilledCE_BASE_CLASSNAME"OnKilled", .Post 0);
    
    
register_event("HLTV""OnNewRound""a""1=0""2=0");
    
    
register_concmd("ce_spawn""OnClCmd_CESpawn"ADMIN_CVAR);
}

public 
plugin_end()
{
    for (new 
0g_entityCount; ++i) {
        
DestroyFunctions(i);
    }

    if (
g_entityCount) {
        
TrieDestroy(g_entityHandlers);
        
ArrayDestroy(g_entityName);
        
ArrayDestroy(g_entityPluginID);
        
ArrayDestroy(g_entityModelIndex);
        
ArrayDestroy(g_entityMins);
        
ArrayDestroy(g_entityMaxs);
        
ArrayDestroy(g_entityLifeTime);
        
ArrayDestroy(g_entityRespawnTime);
        
ArrayDestroy(g_entityIgnoreRounds);
        
ArrayDestroy(g_entityPreset);
        
ArrayDestroy(g_entityHooks);
    }

    if (
g_tmpEntities) {
        
ArrayDestroy(g_tmpEntities);
    }
    
    if (
g_worldEntities) {
        
ArrayDestroy(g_worldEntities);
    }
}

public 
plugin_precache()
{
    
g_ptrBaseClassname engfunc(EngFunc_AllocStringCE_BASE_CLASSNAME);
    
    
register_forward(FM_KeyValue"OnKeyValue"1);    
    
RegisterHam(Ham_SpawnCE_BASE_CLASSNAME"OnSpawn", .Post 1);
}

public 
plugin_natives()
{
    
register_library("api_custom_entities");
    
    
register_native("CE_Register""Native_Register");    
    
register_native("CE_Create""Native_Create");
    
register_native("CE_Kill""Native_Kill");
    
register_native("CE_Remove""Native_Remove");
    
    
register_native("CE_GetSize""Native_GetSize");
    
register_native("CE_GetModelIndex""Native_GetModelIndex");
    
    
register_native("CE_RegisterHook""Native_RegisterHook");

    
register_native("CE_CheckAssociation_""Native_CheckAssociation");

    
register_native("CE_GetHandler""Native_GetHandler");
    
register_native("CE_GetHandlerByEntity""Native_GetHandlerByEntity");
}

/*--------------------------------[ Natives ]--------------------------------*/

public Native_Register(pluginIDargc)
{
    static 
szClassName[32];
    
get_string(RegisterArg_NameszClassNamecharsmax(szClassName));
    
    new 
modelIndex get_param(RegisterArg_ModelIndex);
    new 
Float:fLifeTime get_param_f(RegisterArg_LifeTime);
    new 
Float:fRespawnTime get_param_f(RegisterArg_RespawnTime);
    new 
bool:ignoreRounds bool:get_param(RegisterArg_IgnoreRounds);
    new 
CEPreset:preset CEPreset:get_param(RegisterArg_Preset);
    
    new 
Float:vMins[3];
    
get_array_f(RegisterArg_MinsvMins3);
    
    new 
Float:vMaxs[3];
    
get_array_f(RegisterArg_MaxsvMaxs3);
    
    return 
Register(szClassNamepluginIDmodelIndexvMinsvMaxsfLifeTimefRespawnTimeignoreRoundspreset);
}

public 
Native_Create(pluginIDargc)
{
    new 
szClassName[32];
    
get_string(1szClassNamecharsmax(szClassName));
    
    new 
Float:vOrigin[3];
    
get_array_f(2vOrigin3);
    
    new 
bool:temp = !!get_param(3);
    
    return 
Create(szClassNamevOrigintemp);
}

public 
Native_Kill(pluginIDargc)
{
    new 
ent get_param(1);
    new 
killer get_param(2);

    
Kill(entkiller);
}

public 
bool:Native_Remove(pluginIDargc)
{
    new 
ent get_param(1);
    return 
Remove(ent);
}

public 
Native_GetSize(pluginIDargc)
{
    new 
szClassName[32];
    
get_string(1szClassNamecharsmax(szClassName));
    
    new 
ceIdx;
    if (!
TrieGetCell(g_entityHandlersszClassNameceIdx)) {
        return 
false;
    }
    
    new 
Float:vMins[3];
    
ArrayGetArray(g_entityMinsceIdxvMins);

    new 
Float:vMaxs[3];
    
ArrayGetArray(g_entityMaxsceIdxvMaxs);
    
    
set_array_f(2vMins3);
    
set_array_f(3vMaxs3);

    return 
true;
}

public 
Native_GetModelIndex(pluginIDargc)
{
    new 
szClassName[32];
    
get_string(1szClassNamecharsmax(szClassName));
    
    new 
ceIdx;
    if (!
TrieGetCell(g_entityHandlersszClassNameceIdx)) {
        return 
false;
    }
    
    return 
ArrayGetCell(g_entityModelIndexceIdx);
}

public 
Native_RegisterHook(pluginIDargc)
{
    new 
CEFunction:function = CEFunction:get_param(1);
    
    new 
szClassname[32];
    
get_string(2szClassnamecharsmax(szClassname));
    
    new 
szCallback[32];
    
get_string(3szCallbackcharsmax(szCallback));

    
RegisterHook(function, szClassnameszCallbackpluginID);
}

public 
Native_CheckAssociation(pluginIDargc)
{
    new 
ent get_param(1);
    new 
ceIdx GetHandlerByEntity(ent);

    return (
ceIdx && pluginID == ArrayGetCell(g_entityPluginIDceIdx));
}

public 
Native_GetHandler(pluginIDargc)
{
    new 
szClassname[32];
    
get_string(1szClassnamecharsmax(szClassname));
    
    return 
GetHandler(szClassname);
}

public 
Native_GetHandlerByEntity(pluginIDargc)
{
    new 
ent get_param(1);

    return 
GetHandlerByEntity(ent);
}

/*--------------------------------[ Hooks ]--------------------------------*/

public OnClCmd_CESpawn(idlevelcid)
{
    if(!
cmd_access(idlevelcid2)) {
        return 
PLUGIN_HANDLED;
    }
    
    static 
szClassname[128];
    
read_args(szClassnamecharsmax(szClassname));
    
remove_quotes(szClassname);
    
    if(
szClassname[0] == '^0') {
        return 
PLUGIN_HANDLED;
    }
    
    static 
Float:vOrigin[3];
    
pev(idpev_originvOrigin);
    
    new 
ent Create(szClassnamevOrigin);
    if (
ent) {
        
dllfunc(DLLFunc_Spawnent);
    }
    
    return 
PLUGIN_HANDLED;
}

public 
OnKeyValue(entkvd)
{
    static 
szKey[32];
    
get_kvd(kvdKV_KeyNameszKeycharsmax(szKey));
    
    static 
szValue[32];
    
get_kvd(kvdKV_ValueszValuecharsmax(szValue));
    
    if (
equal(szKey"classname"))
    {
        if (
g_lastCEEnt) {
            
dllfunc(DLLFunc_Spawng_lastCEEnt); // spawn last handled entity
            
g_lastCEEnt 0;
        }
    
        if (
TrieGetCell(g_entityHandlersszValueg_lastCEIdx)) {
            
g_lastCEEnt Create(szValue, .temp false); // clone entity
        
}

        return;
    }
    
    if (!
g_lastCEEnt) {
        return;
    }
    
    
DispatchKeyValue(g_lastCEEntszKeyszValue); // dispatch kvd to cloned entity
    
ExecuteFunction(CEFunction_KVDg_lastCEIdxg_lastCEEntszKeyszValue);
}

public 
OnSpawn(ent)
{
    if (!
Check(ent)) {
        return;
    }

    new Array:
ceData GetPData(ent);
    new 
ceIdx ArrayGetCell(ceDataCEData_Handler);
    
    
//Save start origin
    
if (ArrayGetCell(ceDataCEData_StartOrigin) == Invalid_Array) {
        new 
Float:vOrigin[3];
        
pev(entpev_originvOrigin);    
    
        new Array:
startOrigin ArrayCreate(31);
        
ArrayPushArray(startOriginvOrigin);

        
ArraySetCell(ceDataCEData_StartOriginstartOrigin);
    }
    
    new 
tmpIdx ArrayGetCell(ceDataCEData_TempIndex);
    
InitEntity(entceIdx, (tmpIdx >= 0));

    
ExecuteFunction(CEFunction_SpawnceIdxent);
}

public 
OnTouch(entid)
{
    if (
pev(entpev_flags) & ~FL_ONGROUND) {
        return;
    }

    if (!
is_user_connected(id)) {
        return;
    }
    
    if (!
is_user_alive(id)) {
        return;
    }

    static 
szClassname[32];
    
pev(entpev_classnameszClassnamecharsmax(szClassname));    
    
    new 
ceIdx;
    if (!
TrieGetCell(g_entityHandlersszClassnameceIdx)) {
        return;
    }
    
    new 
CEPreset:preset ArrayGetCell(g_entityPresetceIdx);
    if (
preset != CEPreset_Item) {
        return;
    }
    
    if (
ExecuteFunction(CEFunction_PickupceIdxentid) > 0) {
        
ExecuteFunction(CEFunction_PickedceIdxentid);
        
Kill(entid, .picked true);
    }
}

public 
OnKilled(entkiller)
{
    if (!
Check(ent)) {
        return 
HAM_IGNORED;
    }
    
    
Kill(entkiller);
    return 
HAM_SUPERCEDE;
}

public 
OnNewRound()
{
    
Cleanup();
    
RespawnEntities();
}

/*--------------------------------[ Methods ]--------------------------------*/

Register(
    const 
szClassname[],
    
pluginID,
    
modelIndex,
    const 
Float:vMins[3],
    const 
Float:vMaxs[3],
    
Float:fLifeTime,
    
Float:fRespawnTime,
    
bool:ignoreRounds,
    
CEPreset:preset
)
{
    if (!
g_entityCount) {
        
g_entityHandlers TrieCreate();
        
g_entityName ArrayCreate(32);
        
g_entityPluginID ArrayCreate(1);
        
g_entityModelIndex ArrayCreate(1);
        
g_entityMaxs ArrayCreate(3);
        
g_entityMins ArrayCreate(3);
        
g_entityLifeTime ArrayCreate(1);
        
g_entityRespawnTime ArrayCreate(1);
        
g_entityIgnoreRounds ArrayCreate(1);
        
g_entityPreset ArrayCreate(1);
        
g_entityHooks ArrayCreate(1);
    }

    new 
index g_entityCount;

    
TrieSetCell(g_entityHandlersszClassnameindex);
    
    
ArrayPushString(g_entityNameszClassname);
    
ArrayPushCell(g_entityPluginIDpluginID);
    
ArrayPushCell(g_entityModelIndexmodelIndex);
    
ArrayPushArray(g_entityMinsvMins);
    
ArrayPushArray(g_entityMaxsvMaxs);
    
ArrayPushCell(g_entityLifeTimefLifeTime);
    
ArrayPushCell(g_entityRespawnTimefRespawnTime);
    
ArrayPushCell(g_entityIgnoreRoundsignoreRounds);
    
ArrayPushCell(g_entityPresetpreset);
    
ArrayPushCell(g_entityHooks0);
    
    
g_entityCount++;
    
    
log_amx("%s Entity %s successfully registred."LOG_PREFIXszClassname);
    
    return 
index;
}

Create(const szClassname[], const Float:vOrigin[3] = {0.00.00.0}, bool:temp true)
{
    new 
ceIdx;
    if (!
TrieGetCell(g_entityHandlersszClassnameceIdx)) {
        
log_error(0"%s Entity %s is not registered as custom entity."LOG_PREFIXszClassname);
        return 
0;
    }
    
    new 
ent engfunc(EngFunc_CreateNamedEntityg_ptrBaseClassname);
    
set_pev(entpev_classnameszClassnamestrlen(szClassname));
    
    
engfunc(EngFunc_SetOriginentvOrigin);
    
    new 
tmpIdx = -1;
    new 
worldIdx = -1;
    if (
temp) {
        if (!
g_tmpEntities) {
            
g_tmpEntities ArrayCreate();
        }    
    
        
tmpIdx ArraySize(g_tmpEntities);
        
ArrayPushCell(g_tmpEntitiesent);
    } else {
        if (!
g_worldEntities) {
            
g_worldEntities ArrayCreate();
        }
        
        
worldIdx ArraySize(g_worldEntities);
        
ArrayPushCell(g_worldEntitiesent);
    }
    
    new Array:
ceData CreatePData(ent);
    
    
ArraySetCell(ceDataCEData_HandlerceIdx);
    
ArraySetCell(ceDataCEData_TempIndextmpIdx);
    
ArraySetCell(ceDataCEData_WorldIndexworldIdx);
    
ArraySetCell(ceDataCEData_StartOriginInvalid_Array);
    
    
set_pev(entpev_deadflagDEAD_NO);
    
    return 
ent;
}

Respawn(ent)
{
    
remove_task(ent+TASKID_SUM_RESPAWN);

    new Array:
ceData GetPData(ent);
        
    new Array:
startOrigin ArrayGetCell(ceDataCEData_StartOrigin);
    if (
startOrigin != Invalid_Array) {
        static 
Float:vOrigin[3];
        
ArrayGetArray(startOrigin0vOrigin);
        
engfunc(EngFunc_SetOriginentvOrigin);
    }

    
set_pev(entpev_deadflagDEAD_NO);
    
set_pev(entpev_effectspev(entpev_effects) & ~EF_NODRAW);
    
    
set_pev(entpev_flagspev(entpev_flags) & ~FL_ONGROUND);
    
dllfunc(DLLFunc_Spawnent);
}

Kill(entkiller 0bool:picked false)
{
    new Array:
ceData GetPData(ent);

    new 
ceIdx ArrayGetCell(ceDataCEData_Handler);

    if (
ExecuteFunction(CEFunction_KillceIdxentkillerpicked) != PLUGIN_CONTINUE) {
        return;
    }

    
set_pev(entpev_takedamageDAMAGE_NO);
    
set_pev(entpev_effectspev(entpev_effects) | EF_NODRAW);
    
set_pev(entpev_solidSOLID_NOT);
    
set_pev(entpev_movetypeMOVETYPE_NONE);
    
set_pev(entpev_flagspev(entpev_flags) & ~FL_ONGROUND);
    
    
//Get temp index
    
new tmpIdx ArrayGetCell(ceDataCEData_TempIndex);
    
    
//Check if entity is temp
    
if (tmpIdx 0) {
        new 
Float:fRespawnTime ArrayGetCell(g_entityRespawnTimeceIdx);
        if (
fRespawnTime 0.0) {
            
set_pev(entpev_deadflagDEAD_RESPAWNABLE);
            
set_task(fRespawnTime"TaskRespawn"ent+TASKID_SUM_RESPAWN);
        } else {
            
set_pev(entpev_deadflagDEAD_DEAD);
        }
    } else {
        
set_pev(entpev_deadflagDEAD_DISCARDBODY);
    }

    
remove_task(ent+TASKID_SUM_DISAPPEAR);

    
ExecuteFunction(CEFunction_KilledceIdxentkillerpicked);

    if (
tmpIdx >= 0) {
        
set_task(0.0"TaskRemove"ent+TASKID_SUM_REMOVE);
    }
}

bool:Remove(ent)
{
    if (!
Check(ent)) {
        
log_error(0"%s Entity %i is not a custom entity."LOG_PREFIXent);
        return 
false;
    }
    
    new Array:
ceData GetPData(ent);
    
    
//Get temp index
    
new tmpIdx ArrayGetCell(ceDataCEData_TempIndex);
    
    
//Check if entity is temp
    
if (tmpIdx >= 0) {
        
//Remove entity from storage of temp entities
        
ArraySetCell(g_tmpEntitiestmpIdx0);
    } else {
        
//Get world index
        
new worldIdx ArrayGetCell(ceDataCEData_WorldIndex);
        if (
worldIdx >= 0) {
            
ArraySetCell(g_worldEntitiesworldIdx0);    
        }
    }

    
ClearTasks(ent);
    
    
//Get handler
    
new ceIdx ArrayGetCell(ceDataCEData_Handler);
    
    
//Execute remove function
    
ExecuteFunction(CEFunction_RemoveceIdxent);
    
    
DestroyPData(ent);

    
//Remove entity
    
set_pev(entpev_flagspev(entpev_flags) | FL_KILLME);
    
dllfunc(DLLFunc_Thinkent);
    
    return 
true;
}

Check(ent)
{
    return (
pev(entpev_gaitsequence) == 'c'+'e');
}

ClearTasks(ent)
{
    
remove_task(ent+TASKID_SUM_DISAPPEAR);
    
remove_task(ent+TASKID_SUM_RESPAWN);
    
remove_task(ent+TASKID_SUM_REMOVE);
}

GetHandlerByEntity(ent)
{
    if (!
Check(ent)) {
        return -
1;
    }
    
    new Array:
ceData GetPData(ent);
    
    return 
ArrayGetCell(ceDataCEData_Handler);
}

GetHandler(const szClassname[])
{
    new 
ceIdx;
    if (!
TrieGetCell(g_entityHandlersszClassnameceIdx)) {
        return -
1;
    }

    return 
ceIdx;
}

Cleanup()
{
    if (!
g_tmpEntities) {
        return;
    }

    new 
size ArraySize(g_tmpEntities);

    for (new 
size 1>= 0; --i)
    {
        new 
ent ArrayGetCell(g_tmpEntitiesi);
        
        if (
ent && pev_valid(ent))
        {
            new 
ceIdx GetHandlerByEntity(ent);
            if (
ceIdx == -1) {
                
log_error(0"%s Entity %i is not a custom entity."LOG_PREFIXent);
                continue;
            }

            new 
ignoreRounds ArrayGetCell(g_entityIgnoreRoundsceIdx);
            if (!
ignoreRounds) {
                
Remove(ent);
                
ArrayDeleteItem(g_tmpEntitiesi);
            }
        }
    }
}

RespawnEntities()
{
    if (!
g_worldEntities) {
        return;
    }
    
    new 
size ArraySize(g_worldEntities);
    for (new 
0size; ++i) {
        new 
ent ArrayGetCell(g_worldEntitiesi);
        if (
ent) {
            
Respawn(ent);
        }
    }
}

bool:InitEntity(entceIdxbool:temp)
{    
    static 
Float:vMins[3];
    
ArrayGetArray(g_entityMinsceIdxvMins);
    
    static 
Float:vMaxs[3];
    
ArrayGetArray(g_entityMaxsceIdxvMaxs);
    
    static 
Float:vOrigin[3];
    
pev(entpev_originvOrigin);
    
    
engfunc(EngFunc_SetSizeentvMinsvMaxs);
    
engfunc(EngFunc_SetOriginentvOrigin);
    
    {
        new 
preset ArrayGetCell(g_entityPresetceIdx);
        
ApplyPreset(entpreset);
    }
    
    new 
modelIndex ArrayGetCell(g_entityModelIndexceIdx);
    if (
modelIndex 0) {
        
set_pev(entpev_modelindexmodelIndex);
    }

    if (
temp) {
        new 
Float:fLifeTime ArrayGetCell(g_entityLifeTimeceIdx);
        if (
fLifeTime 0.0) {
            
set_task(fLifeTime"TaskDisappear"ent+TASKID_SUM_DISAPPEAR);
        }
    }
    
    return 
true;
}

ApplyPreset(entpreset)
{
    switch (
preset)
    {
        case 
CEPreset_Item:
        {
            
set_pev(entpev_solidSOLID_TRIGGER);
            
set_pev(entpev_movetypeMOVETYPE_TOSS);
            
set_pev(entpev_takedamageDAMAGE_NO);
        }
        case 
CEPreset_NPC:
        {
            
set_pev(entpev_solidSOLID_BBOX);
            
set_pev(entpev_movetypeMOVETYPE_PUSHSTEP);
            
set_pev(entpev_takedamageDAMAGE_AIM);
            
            
set_pev(entpev_controller_0125);
            
set_pev(entpev_controller_1125);
            
set_pev(entpev_controller_2125);
            
set_pev(entpev_controller_3125);
            
            
set_pev(entpev_gamestate1);
            
set_pev(entpev_gravity1.0);
            
set_pev(entpev_flagspev(entpev_flags) | FL_MONSTER);
            
set_pev(entpev_fixangle1);
            
set_pev(entpev_friction0.25);
        }
        case 
CEPreset_Prop:
        {
            
set_pev(entpev_solidSOLID_BBOX);
            
set_pev(entpev_movetypeMOVETYPE_FLY);
            
set_pev(entpev_takedamageDAMAGE_NO);
        }
    }
}

RegisterHook(CEFunction:function, const szClassname[], const szCallback[], pluginID = -1)
{
    new 
ceIdx;
    if (!
TrieGetCell(g_entityHandlersszClassnameceIdx)) {
        
log_error(0"%s Entity %s is not registered."LOG_PREFIXszClassname);
        return -
1;
    }
    
    new 
funcID get_func_id(szCallbackpluginID);
    if (
funcID 0) {
        new 
szFilename[32];
        
get_plugin(pluginIDszFilenamecharsmax(szFilename));
        
log_error(0"Function %s not found in plugin %s."szCallbackszFilename);
        return -
1;
    }
    
    new Array:
functions ArrayGetCell(g_entityHooksceIdx);
    if (!
functions) {
        
functions InitializeFunctions(ceIdx);
    }
    
    new Array:
functionHooks ArrayGetCell(functions_:function);    

    new Array:
hookData CreateHookData(pluginIDfuncID);
    return 
ArrayPushCell(functionHookshookData);
}

Array:
InitializeFunctions(ceIdx)
{
    new Array:
functions ArrayCreate(1_:CEFunction);
    
    for (new 
0_:CEFunction; ++i) {
        new Array:
functionHooks ArrayCreate();
        
ArrayPushCell(functionsfunctionHooks);
    }
    
    
ArraySetCell(g_entityHooksceIdxfunctions);
    
    return 
functions;
}

DestroyFunctions(ceIdx)
{
    new Array:
functions ArrayGetCell(g_entityHooksceIdx);
    
    if (!
functions) {
        return;
    }
    
    for (new 
0_:CEFunction; ++i) {
        new Array:
functionHooks ArrayGetCell(functionsi);
        
ArrayDestroy(functionHooks);
    }
    
    
ArrayDestroy(functions);
    
ArraySetCell(g_entityHooksceIdx0);
}

Array:
CreateHookData(pluginIDfuncID)
{
    new Array:
hookData ArrayCreate(1_:CEHookData);
    
ArrayPushCell(hookDatapluginID);
    
ArrayPushCell(hookDatafuncID);
    
    return 
hookData;
}

ExecuteFunction(CEFunction:function, ceIdxany:...)
{
    new 
result 0;
    new 
ent getarg(2);

    new Array:
functions ArrayGetCell(g_entityHooksceIdx);
    if (
functions == Invalid_Array) {
        return 
0;
    }

    new Array:
functionHooks ArrayGetCell(functions_:function);
    
    new 
count ArraySize(functionHooks);
    for (new 
0count; ++i)
    {
        new Array:
hookData ArrayGetCell(functionHooksi);
        new 
pluginID ArrayGetCell(hookData_:CEHookData_PluginID);
        new 
funcID ArrayGetCell(hookData_:CEHookData_FuncID);

        if (
funcID 0) {
            continue;
        }
        
        if (
callfunc_begin_i(funcIDpluginID) == 1
        {
            
callfunc_push_int(ent);

            switch (function)
            {
                case 
CEFunction_KillCEFunction_Killed: {
                    new 
killer getarg(3);
                    new 
bool:picked bool:getarg(4);
                    
callfunc_push_int(killer);
                    
callfunc_push_int(picked);
                }
                case 
CEFunction_PickupCEFunction_Picked: {
                    new 
id getarg(3);
                    
callfunc_push_int(id);
                }
                case 
CEFunction_KVD: {
                    static 
szKey[32];
                    for (new 
0charsmax(szKey); ++i) {
                        
szKey[i] = getarg(3i);                        
                        
                        if (
szKey[i]  == '^0') {
                            break;
                        }
                    }
                    
                    static 
szValue[32];
                    for (new 
0charsmax(szValue); ++i) {
                        
szValue[i] = getarg(4i);                        
                        
                        if (
szValue[i]  == '^0') {
                            break;
                        }
                    }
                    
                    
callfunc_push_str(szKey);
                    
callfunc_push_str(szValue);
                }
            }

            
result += callfunc_end();        
        }
    }
    
    return 
result;
}

Array:
CreatePData(ent)
{
    new Array:
ceData ArrayCreate(1CEData);    
    for (new 
0CEData; ++i) {
        
ArrayPushCell(ceData0);
    }
    
    
set_pev(entpev_gaitsequence'c'+'e');
    
set_pev(entpev_iStepLeftceData);    
    
    return 
ceData;
}

DestroyPData(ent)
{
    
//Destroy data array
    
new Array:ceData GetPData(ent);
    {
        new Array:
startOrigin ArrayGetCell(ceDataCEData_StartOrigin);
        if (
startOrigin != Invalid_Array) {
            
ArrayDestroy(startOrigin);
        }
    } 
ArrayDestroy(ceData);
    
    
set_pev(entpev_gaitsequence0);
    
set_pev(entpev_iStepLeft0);
}

Array:
GetPData(ent)
{
    new Array:
ceData any:pev(entpev_iStepLeft);
    if (
ceData == Invalid_Array) {
        
log_error(0"%s Invalid Custom Entity data provided for %i."LOG_PREFIXent);
    }
    
    return 
ceData;
}

/*--------------------------------[ Tasks ]--------------------------------*/

public TaskDisappear(taskID)
{
    new 
ent taskID TASKID_SUM_DISAPPEAR;
    
Kill(ent0);
}

public 
TaskRespawn(taskID)
{
    new 
ent taskID TASKID_SUM_RESPAWN;
    
Respawn(ent);
}

public 
TaskRemove(taskID)
{
    new 
ent taskID TASKID_SUM_REMOVE;
    
Remove(ent);


Last edited by alferd; 05-31-2020 at 12:19.
alferd is online now
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-31-2020 , 14:06   Re: [DEBUG] plugin api_custom_entities
Reply With Quote #2

The plugin is trying to retrieve a value from a trie using TrieGetCell() before creating the trie with TrieCreate().
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
alferd
Veteran Member
Join Date: Dec 2019
Old 06-01-2020 , 02:51   Re: [DEBUG] plugin api_custom_entities
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
The plugin is trying to retrieve a value from a trie using TrieGetCell() before creating the trie with TrieCreate().
hom,Can you fix the problem in the plugin?
alferd is online now
Reply


Thread Tools
Display Modes

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 04:15.


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