Raised This Month: $32 Target: $400
 8% 

[STOCK] Custom Data Entities


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SVC
Junior Member
Join Date: Mar 2021
Old 04-03-2023 , 11:23   [STOCK] Custom Data Entities
Reply With Quote #1

Hello again!. This time I come to share this series of functions that I created a while ago for the dynamic handling of data in entities.

_______________________________________

CUSTOM ENTITIES DATA

Q: Do you need to handle a large amount of data associated with entities?.
Q: Tired of always using internal entity data (pev -> iuser1, iuser2, fuser1, vuser1, etc...)? .
Q: Ran out of pevs available to use?.

A: Don't worry, here is the solution. Just use this series of functions/stocks that will make your job much easier. And the best thing is that you can work with a wide variety of data, which will be associated with the entity you want (even players [YES, YOU READ WELL, PLAYERS!]).


• WHAT IS THIS UTILITY

Custom Entities Data (CED) is based on the module of the same name published here, which, as its name suggests, allows you to manage an infinite number of data associated with a specific entity.

For example: I have an entity and I want to store the "state" data. So I would do this:
PHP Code:
CED_SetCell(entity"state"entity_state
And to get it I just do:
PHP Code:
new state
CED_GetCell
(entity"state"state)

print(
"the entity state is: %d"state
It can work with:
  • CELLS (they can be integers/floats/logical -> int/float/bool)
  • STRING
  • ARRAY

• HOW IS IT USED?

It has 8 main stocks for data management:

● Save/update data:
PHP Code:
CED_SetCell
CED_SetString
CED_SetArray 
● Load data
PHP Code:
CED_GetCell
CED_GetString
CED_GetArray 
● Clears (deletes) all data saved in the entity
PHP Code:
CED_Clear 
● Same as above, but for all entities; frees the memory used to store the data (MANDATORY TO USE [preference every time the server changes maps and/or where needed])
PHP Code:
CED_Free 
• WHAT DIFFERENCES IT FROM THE MODULE?

I have never seen the source code of the module, but it is known that since it is a (*theory*) module, it is faster when performing operations (although the times we are living in, your PC will not hang for using this....)

But above all, the named module does not work well, so I found myself in need of making this stock.

• CODE

Inside the include there are several examples for handling data. I will also leave some examples
Attached Files
File Type: inc custom_entities_data.inc (15.5 KB, 67 views)

Last edited by SVC; 04-11-2023 at 07:42.
SVC is offline
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 - 93 views - 1.6 KB)
File Type: sma Get Plugin or Get Source (ced_example2.sma - 88 views - 2.1 KB)

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



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


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