View Single Post
SVC
Junior Member
Join Date: Mar 2021
Old 04-03-2023 , 13:23   Re: [STOCK] Custom Data Entities
Reply With Quote #2

EXAMPLE #1
PHP Code:
#include        <AMXMODX>
#include        <ENGINE>

#include        CUSTOM_ENTITIES_DATA

public plugin_init()
{
    
register_clcmd("test_entity""OnClientCommand_TestEntity");
}

public 
OnClientCommand_TestEntity(const iPlayer)
{
    new 
iEntity create_entity("info_target");
    {
        
CED_SetCell(iEntity"int field"150);
        
CED_SetCell(iEntity"float field"25.0)
        
CED_SetCell(iEntity"bool field"true);
        
        
CED_SetString(iEntity"constant name""info_target");
        
        new 
szName[32];
        
get_user_name(iPlayerszNamecharsmax(szName));
        
CED_SetString(iEntity"owner name"szName);
        
        
CED_SetArray(iEntity"constant array", { 1503340999 });
    }
    
    
set_task(1.0"GetData"iEntity);
}

public 
GetData(const iEntity)
{
    
log_amx("GETTING DATA FOR ENTITY #%d"iEntity);
    
    new 
Int;
    
CED_GetCell(iEntity"int field"Int);
    
log_amx("'int' field: %d"Int);
    
    new 
Float:Floatv;
    
CED_GetCell(iEntity"float field"Floatv);
    
log_amx("'float' field: %.5f"Floatv);
    
    new 
bool:Bool;
    
CED_GetCell(iEntity"bool field"Bool);
    
log_amx("'bool' field: %d (%s)"BoolBool "true" "false");
    
    new 
szConstantName[25];
    
CED_GetString(iEntity"constant name"szConstantName);
    
log_amx("'constant-name' field: %s"szConstantName);
    
    new 
szOwnerName[32];
    
CED_GetString(iEntity"owner name"szOwnerName);
    
log_amx("'owner-name' field: %s"szOwnerName);
    
    new 
ConstantArray[4];
    
CED_GetArray(iEntity"constant array"ConstantArray);
    
log_amx("'constant array' field: { %d, %d, %d, %d }"ConstantArray[0], ConstantArray[1], ConstantArray[2], ConstantArray[3]);
}

public 
plugin_end()
{
    
CED_Free();

EXAMPLE #2

PHP Code:
#include        <AMXMODX>
#include        <ENGINE>

#include        CUSTOM_ENTITIES_DATA

enum _:STATE
{
    
STATE_ALIVE,
    
STATE_DIYING,
    
STATE_DEAD,
    
STATE_DEAD_FOREVER
};

new const 
StatesNames[STATE][] =
{
    
"ALIVE",
    
"DIYING",
    
"DEAD",
    
"DEAD FOREVER",
};

new const 
EntName[] = "Monster";

new 
g_iEntity

public plugin_init()
{
    
g_iEntity create_entity("info_target");
    {
        
CED_SetCell(g_iEntity"MaxHealth"12500);
        
CED_SetCell(g_iEntity"CanRespawn"true);
        
CED_SetCell(g_iEntity"RespawnTime"25.0)
        
CED_SetCell(g_iEntity"State"STATE_ALIVE);
        
CED_SetString(g_iEntity"Name"EntName);
    }
    
    
register_clcmd("get_ent_data""OnClientCommand_GetEntData");
    
register_clcmd("update_ent_data""OnClientCommand_UpdateEntData");
}

public 
OnClientCommand_GetEntData(const iPlayer)
{
    new 
iMaxHealth;
    
CED_GetCell(g_iEntity"MaxHealth"iMaxHealth);
    
    new 
bool:bCanRespawn;
    
CED_GetCell(g_iEntity"CanRespawn"bCanRespawn);
    
    new 
Float:fRespawnTime;
    
CED_GetCell(g_iEntity"RespawnTime"fRespawnTime);
    
    new 
iState;
    
CED_GetCell(g_iEntity"State"iState);
    
    new 
Name[15];
    
CED_GetString(g_iEntity"Name"Name);
    
    
log_amx("---------- DUMP ENTITY DATA ----------");
    
log_amx("MaxHealth: %d"iMaxHealth);
    
log_amx("CanRespawn: %s"bCanRespawn "true" "false");
    
log_amx("RespawnTime: %.4f"fRespawnTime);
    
log_amx("State: %s"StatesNames[iState]);
    
log_amx("Name: %s"Name);
}

public 
OnClientCommand_UpdateEntData(const iPlayer)
{
    new 
iState;
    if (!
CED_GetCell(g_iEntity"State"iState))
    {
        
// 'State' field has not been set yet
        
return;
    }
    
    if (
iState == STATE_ALIVE)
    {
        
CED_SetCell(g_iEntity"MaxHealth"125);
        
CED_SetCell(g_iEntity"State"STATE_DIYING);
    }
    else if (
iState == STATE_DIYING)
    {
        
CED_SetCell(g_iEntity"MaxHealth"0);
        
CED_SetCell(g_iEntity"State"STATE_DEAD);
    }
    else if (
iState == STATE_DEAD)
    {
        
CED_SetCell(g_iEntity"MaxHealth"0);
        
CED_SetCell(g_iEntity"State"STATE_DEAD_FOREVER);
        
CED_SetCell(g_iEntity"CanRespawn"false);
    }
}

public 
plugin_end()
{
    
CED_Free();

Attached Files
File Type: sma Get Plugin or Get Source (ced_example1.sma - 105 views - 1.6 KB)
File Type: sma Get Plugin or Get Source (ced_example2.sma - 103 views - 2.1 KB)

Last edited by SVC; 04-11-2023 at 07:44.
SVC is offline