Entity property listener

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Entity property listener

Postby BackRaw » Tue Aug 14, 2018 11:18 am

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
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Entity property listener

Postby Ayuto » Tue Aug 14, 2018 11:52 am

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.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Re: Entity property listener

Postby BackRaw » Tue Aug 14, 2018 12:34 pm

Dang! Anyways, I'll look around the Source SDK and SourceMod sources, maybe I can find some clues.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 24 guests