Page 1 of 1

Entity property listener

Posted: Tue Aug 14, 2018 11:18 am
by BackRaw
Hello everyone,

is it possible to create a "listener" of sorts that will notify all its subscribers whenever the value of a property changes without the use of an OnTick listener and hacking my way around it?

Something like:

Syntax: Select all

class EntityPropertyListener(object):

def __init__(self, *properties, classname=None):
self.callback = None

self.properties = properties # 'origin', 'index', ...
self.classname = classname

# mybe add is_filters and not_filters to be consistent with the SP API

# I hope I do this the right way, but I just want to remember the listener callback here
def __call__(self, callback, *args, kwargs={}):
self.callback = callback

def on_value_changed(self, entity, old_value, new_value):
self.callback(entity, old_value, new_value)


@EntityPropertyListener('origin'):
def on_origin_changed(entity, old_value, new_value):
print(f'Entity (index: {entity.index}, classname: {entity.classname}) changed its origin from {old_value} to {new_value}')


That principle can then be applied to players, weapons, etc. I think this would be a nice addition. Though, I guess it would require changing the C++ side of things, because only there we can get to the actual property changes as soon as they happen, if I'm not mistaken.

What do you think about it? I'd love to implement it myself, but I'm not sure where to start. :D

Re: Entity property listener

Posted: Tue Aug 14, 2018 11:52 am
by Ayuto
Unfortunately, there is no way to determine that without checking the attribute constantly. It might be possible to do that for networked properties, because a function (NetworkStateChanged or something like that) is getting called after the attribute has been changed.

Re: Entity property listener

Posted: Tue Aug 14, 2018 12:34 pm
by BackRaw
Dang! Anyways, I'll look around the Source SDK and SourceMod sources, maybe I can find some clues.