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