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

[ H3LP ] Entity members


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 12-23-2017 , 16:59   [ H3LP ] Entity members
Reply With Quote #1

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);
__________________









Last edited by CrazY.; 12-23-2017 at 16:59.
CrazY. is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 12-24-2017 , 10:02   Re: [ H3LP ] Entity members
Reply With Quote #2

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);

Last edited by KiLLeR.; 12-24-2017 at 10:06.
KiLLeR. is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 12-24-2017 , 13:02   Re: [ H3LP ] Entity members
Reply With Quote #3

Basically this is a "hack" method, I was thinking of something like bit-fields, but even so, it was worth the try.
__________________








CrazY. is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 12-24-2017 , 14:14   Re: [ H3LP ] Entity members
Reply With Quote #4

Quote:
Originally Posted by CrazY. View Post
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 )

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.

Last edited by KiLLeR.; 12-24-2017 at 14:28.
KiLLeR. is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 12-24-2017 , 14:53   Re: [ H3LP ] Entity members
Reply With Quote #5

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
__________________

Last edited by Depresie; 12-24-2017 at 14:54.
Depresie is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 12-24-2017 , 14:54   Re: [ H3LP ] Entity members
Reply With Quote #6

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.
__________________








CrazY. is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 12-24-2017 , 15:04   Re: [ H3LP ] Entity members
Reply With Quote #7

Then get this https://forums.alliedmods.net/showthread.php?t=294188
__________________
Depresie is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 12-24-2017 , 15:47   Re: [ H3LP ] Entity members
Reply With Quote #8

You can store for one entity up to 8 integers (or 24, but it's a bit tricky) and up to 16 floats.
KiLLeR. is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 12-24-2017 , 21:19   Re: [ H3LP ] Entity members
Reply With Quote #9

Quote:
Originally Posted by KiLLeR. View Post
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.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Natsheh
Veteran Member
Join Date: Sep 2012
Old 12-27-2017 , 13:06   Re: [ H3LP ] Entity members
Reply With Quote #10

You can use also dynamic array.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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 09:33.


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