Page 1 of 1

Get/set entity array properties

Posted: Mon May 31, 2021 3:19 pm
by rovizon
Hi!
How to get / set entity properties which are arrays e.g. m_flPoseParameter ?

I want to change pose parameters of my entity. It has two of them.

Syntax: Select all

my_entity.get_property_float('m_flPoseParameter') # it works for first pose


How to get for second pose?

Re: Get/set entity array properties

Posted: Mon May 31, 2021 3:57 pm
by L'In20Cible
rovizon wrote:Hi!
How to get / set entity properties which are arrays e.g. m_flPoseParameter ?

I want to change pose parameters of my entity. It has two of them.

Syntax: Select all

my_entity.get_property_float('m_flPoseParameter') # it works for first pose


How to get for second pose?

If you use the following command:

Code: Select all

sp dump server_classes classes

It will generates a ../logs/source-python/classes.txt file listing all the networked properties available. From that list, you can see that this specific table have 24 properties:

Syntax: Select all

m_flPoseParameter.000
m_flPoseParameter.001
m_flPoseParameter.002
m_flPoseParameter.003
m_flPoseParameter.004
m_flPoseParameter.005
m_flPoseParameter.006
m_flPoseParameter.007
m_flPoseParameter.008
m_flPoseParameter.009
m_flPoseParameter.010
m_flPoseParameter.011
m_flPoseParameter.012
m_flPoseParameter.013
m_flPoseParameter.014
m_flPoseParameter.015
m_flPoseParameter.016
m_flPoseParameter.017
m_flPoseParameter.018
m_flPoseParameter.019
m_flPoseParameter.020
m_flPoseParameter.021
m_flPoseParameter.022
m_flPoseParameter.023


Alternatively, you could wrap it as an array with something like that:

Syntax: Select all

from core.cache import cached_property
from entities.entity import Entity
from memory.manager import manager
from memory.helpers import Array

class MyEntity(Entity):
caching = True

@cached_property
def pose_parameters(self):
"""Returns the pose parameters of this entity as an array."""
for p in self.server_class.find_server_class('CBaseAnimating').table:
if p.name == 'm_flPoseParameter':
break
else:
raise ValueError('Unable to find the pose parameters property.')
return Array(
manager, False, 'float',
self.pointer + p.offset, p.data_table.length
)

print(list(MyEntity(1).pose_parameters))

"""
[0.5, 0.4899536073207855, 0.5021207928657532, 0.5169552564620972, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
"""

Re: Get/set entity array properties

Posted: Mon May 31, 2021 5:04 pm
by rovizon
Thank you!