Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. from listeners import OnEntitySpawned
  2. from filters.entities import EntityIter
  3. from entities.entity import Entity
  4. from entities.constants import EntityEffects
  5. from entities import CheckTransmitInfo
  6. from entities.entity import BaseEntity
  7. from memory import make_object
  8. from memory.hooks import PreHook
  9. from entities.helpers import index_from_edict
  10.  
  11. TRIGGER_START = 'trigger_'
  12.  
  13. def on_trigger_transmit(trigger, classname, index):
  14.     """Called when a trigger should be transmitted.
  15.  
  16.    :param BaseEntity trigger:
  17.        The trigger that should be transmitted to the client.
  18.    :param str classname:
  19.        The classname of the trigger to transmit (e.g. ``trigger_multiple``).
  20.        The value equals ``trigger.classname``.
  21.    :param int index:
  22.        The index of the player who should receive the data of the trigger.
  23.    :return:
  24.        Return ``True`` if the trigger should be transmitted. Return ``False``
  25.        if it shouldn't be transmitted (it will be invisible to the client).
  26.    :rtype: bool
  27.    """
  28.     return True
  29.  
  30. def show_entity(entity):
  31.     entity.edict.clear_transmit_state()
  32.     entity.effects &= ~EntityEffects.NODRAW
  33.  
  34. # We can use the worldspawn entity, because it's using
  35. # CBaseEntity::SetTransmit just like all triggers
  36. @PreHook(Entity(0).set_transmit)
  37. def pre_set_transmit(args):
  38.     entity = make_object(BaseEntity, args[0])
  39.     classname = entity.classname
  40.     if not classname.startswith(TRIGGER_START):
  41.         return
  42.  
  43.     info = make_object(CheckTransmitInfo, args[1])
  44.     index = index_from_edict(info.client)
  45.     if not on_trigger_transmit(entity, classname, index):
  46.         return False
  47.  
  48. @OnEntitySpawned
  49. def on_entity_spawned(base_entity):
  50.     if base_entity.classname.startswith(TRIGGER_START):
  51.         show_entity(Entity(base_entity.index))
  52.  
  53. for trigger in EntityIter(TRIGGER_START, False):
  54.     show_entity(trigger)