AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [ H3LP ] Entity members (https://forums.alliedmods.net/showthread.php?t=303842)

CrazY. 12-23-2017 16:59

[ H3LP ] Entity members
 
Hello, is there any way to set values to an entity (life time, for example) by means of a variable?

Instead of:
Code:
new Float:g_flLifeTime[2056]; g_flLifeTime[entity] = 100.0;

Something like this:
Code:
new Float:g_flLifeTime; SetEntFloatVal(entity, g_flLifeTime, 100.0);

KiLLeR. 12-24-2017 10:02

Re: [ H3LP ] Entity members
 
Code:
#define g_flLifeTime EV_FL_fuser1 entity_set_float(entity, g_flLifeTime, 100.0);

- or -

Code:
#define g_flLifeTime EV_FL_fuser1 #define SetEntFloatVal(%0, %1, %2), entity_set_float(%0, %1, %2) SetEntFloatVal(entity, g_flLifeTime, 100.0);

CrazY. 12-24-2017 13:02

Re: [ H3LP ] Entity members
 
Basically this is a "hack" method, I was thinking of something like bit-fields, but even so, it was worth the try.

KiLLeR. 12-24-2017 14:14

Re: [ H3LP ] Entity members
 
Quote:

Originally Posted by CrazY. (Post 2567975)
Basically this is a "hack" method, I was thinking of something like bit-fields, but even so, it was worth the try.

Basically this is what you have to use and there is no better solution. Using array of 2056 cells is painful. (Thats 8 kB of memory :D)

Bit-fields can only be used to store several boolean values (8) in a single byte. So you can't just store float numbers such as 100.0 in one bit. Also a variable can store up to 32 values (4 bytes * 8 bits = 32 boolean values) and that's the reason why often can be seen, bit-flags to be used for players instead of array of 32 cells.

Depresie 12-24-2017 14:53

Re: [ H3LP ] Entity members
 
Anything you want to store on entities, you have to do it using the following pev fields
Storing the data in arrays like you were trying is not safe, because entities can get very high indexes
Another good alternative is to use klippy's module which allows you to store data on entities

Also, don't use these fields on players

Code:

pev_iuser - for integers
pev_euser - for integers
pev_fuser - for floats
pev_vuser - for vectors
pev_noise - for strings


CrazY. 12-24-2017 14:54

Re: [ H3LP ] Entity members
 
Then it would probably be more feasible to store an array in one of the members if I want to pass several values, however this may cause a conflict in the entity.

Depresie 12-24-2017 15:04

Re: [ H3LP ] Entity members
 
Then get this https://forums.alliedmods.net/showthread.php?t=294188

KiLLeR. 12-24-2017 15:47

Re: [ H3LP ] Entity members
 
You can store for one entity up to 8 integers (or 24, but it's a bit tricky) and up to 16 floats.

PRoSToTeM@ 12-24-2017 21:19

Re: [ H3LP ] Entity members
 
Quote:

Originally Posted by KiLLeR. (Post 2567997)
You can store for one entity up to 8 integers (or 24, but it's a bit tricky) and up to 16 floats.

You also can use pev_noise with base64 encoded data.

Natsheh 12-27-2017 13:06

Re: [ H3LP ] Entity members
 
You can use also dynamic array.


All times are GMT -4. The time now is 06:07.

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