89
89
# >> CLASSES
90
90
# =============================================================================
91
91
class Entity (BaseEntity ):
92
- """Class used to interact directly with entities."""
92
+ """Class used to interact directly with entities.
93
+
94
+ Beside the standard way of doing stuff via methods and properties this
95
+ class also provides dynamic attributes that depend on the entity that is
96
+ being accessed with this class. You can print all dynamic properties by
97
+ iterating over the following generators:
98
+
99
+ 1. :attr:`properties`
100
+ 2. :attr:`inputs`
101
+ 3. :attr:`outputs`
102
+ 4. :attr:`keyvalues`
103
+ """
93
104
94
105
def __init__ (self , index ):
95
106
"""Initialize the Entity object."""
@@ -165,7 +176,13 @@ def __dir__(self):
165
176
166
177
@classmethod
167
178
def create (cls , classname ):
168
- """Create a new networked entity with the given classname."""
179
+ """Create a new networked entity with the given classname.
180
+
181
+ :param str classname:
182
+ Classname of the entity to create.
183
+ :raise ValueError:
184
+ Raised if the given classname is not a networked entity.
185
+ """
169
186
entity = BaseEntity .create (classname )
170
187
if entity .is_networked ():
171
188
return cls (entity .index )
@@ -212,13 +229,16 @@ def _obj(cls, ptr):
212
229
213
230
@property
214
231
def index (self ):
215
- """Return the entity's index."""
232
+ """Return the entity's index.
233
+
234
+ :rtype: int
235
+ """
216
236
return self ._index
217
-
237
+
218
238
@property
219
239
def owner (self ):
220
240
"""Return the entity's owner.
221
-
241
+
222
242
:return: None if the entity has no owner.
223
243
:rtype: Entity
224
244
"""
@@ -263,11 +283,18 @@ def keyvalues(self):
263
283
yield from server_class .keyvalues
264
284
265
285
def get_color (self ):
266
- """Return the entity's color as a Color instance."""
286
+ """Return the entity's color.
287
+
288
+ :rtype: Color
289
+ """
267
290
return self .render_color
268
291
269
292
def set_color (self , color ):
270
- """Set the entity's color."""
293
+ """Set the entity's color.
294
+
295
+ :param Color color:
296
+ Color to set.
297
+ """
271
298
# Set the entity's render mode
272
299
self .render_mode = RenderMode .TRANS_COLOR
273
300
@@ -283,11 +310,18 @@ def set_color(self, color):
283
310
doc = """Property to get/set the entity's color values.""" )
284
311
285
312
def get_model (self ):
286
- """Return the entity's model."""
313
+ """Return the entity's model.
314
+
315
+ :rtype: Model
316
+ """
287
317
return Model (self .model_name )
288
318
289
319
def set_model (self , model ):
290
- """Set the entity's model to the given model."""
320
+ """Set the entity's model to the given model.
321
+
322
+ :param Model model:
323
+ The model to set.
324
+ """
291
325
self .model_index = model .index
292
326
self .model_name = model .path
293
327
@@ -523,7 +557,14 @@ def _callback(*args, **kwargs):
523
557
return delay
524
558
525
559
def get_input (self , name ):
526
- """Return the InputFunction instance for the given name."""
560
+ """Return the input function matching the given name.
561
+
562
+ :parma str name:
563
+ Name of the input function.
564
+ :rtype: InputFunction
565
+ :raise ValueError:
566
+ Raised if the input function wasn't found.
567
+ """
527
568
# Loop through each server class for the entity
528
569
for server_class in self .server_classes :
529
570
@@ -540,11 +581,27 @@ def get_input(self, name):
540
581
name , self .classname ))
541
582
542
583
def call_input (self , name , * args , ** kwargs ):
543
- """Call the InputFunction instance for the given name."""
584
+ """Call the input function matching the given name.
585
+
586
+ :param str name:
587
+ Name of the input function.
588
+ :param args:
589
+ Optional arguments that should be passed to the input function.
590
+ :param kwargs:
591
+ Optional keyword arguments that should be passed to the input
592
+ function.
593
+ :raise ValueError:
594
+ Raised if the input function wasn't found.
595
+ """
544
596
self .get_input (name )(* args , ** kwargs )
545
597
546
598
def lookup_attachment (self , name ):
547
- """Return the attachment index matching the given name."""
599
+ """Return the attachment index matching the given name.
600
+
601
+ :param str name:
602
+ The name of the attachment.
603
+ :rtype: int
604
+ """
548
605
# Get the ModelHeader instance of the entity
549
606
model_header = self .model_header
550
607
@@ -569,24 +626,38 @@ def emit_sound(
569
626
download = False , stream = False ):
570
627
"""Emit a sound from this entity.
571
628
572
- :param str sample: Sound file relative to the "sounds" directory.
573
- :param RecipientFilter recipients: Recipients to emit the sound to.
574
- :param int index: Index of the entity to emit the sound from.
575
- :param float volume: Volume of the sound.
576
- :param Attenuation attenuation: How far the sound should reaches.
577
- :param int channel: Channel to emit the sound with.
578
- :param SoundFlags flags: Flags of the sound.
579
- :param Pitch pitch: Pitch of the sound.
580
- :param Vector origin: Origin of the sound.
581
- :param Vector direction: Direction of the sound.
582
- :param tuple origins: Origins of the sound.
583
- :param bool update_positions: Whether or not the positions should be
584
- updated.
585
- :param float sound_time: Time to play the sound for.
586
- :param int speaker_entity: Index of the speaker entity.
587
- :param bool download: Whether or not the sample should be added to the
588
- downloadables.
589
- :param bool stream: Whether or not the sound should be streamed.
629
+ :param str sample:
630
+ Sound file relative to the ``sounds`` directory.
631
+ :param RecipientFilter recipients:
632
+ Recipients to emit the sound to.
633
+ :param int index:
634
+ Index of the entity to emit the sound from.
635
+ :param float volume:
636
+ Volume of the sound.
637
+ :param Attenuation attenuation:
638
+ How far the sound should reaches.
639
+ :param int channel:
640
+ Channel to emit the sound with.
641
+ :param SoundFlags flags:
642
+ Flags of the sound.
643
+ :param Pitch pitch:
644
+ Pitch of the sound.
645
+ :param Vector origin:
646
+ Origin of the sound.
647
+ :param Vector direction:
648
+ Direction of the sound.
649
+ :param tuple origins:
650
+ Origins of the sound.
651
+ :param bool update_positions:
652
+ Whether or not the positions should be updated.
653
+ :param float sound_time:
654
+ Time to play the sound for.
655
+ :param int speaker_entity:
656
+ Index of the speaker entity.
657
+ :param bool download:
658
+ Whether or not the sample should be added to the downloadables.
659
+ :param bool stream:
660
+ Whether or not the sound should be streamed.
590
661
"""
591
662
# Get the correct Sound class...
592
663
if not stream :
@@ -609,14 +680,24 @@ def emit_sound(
609
680
def stop_sound (self , sample , channel = Channel .AUTO ):
610
681
"""Stop the given sound from being emitted by this entity.
611
682
612
- :param str sample: Sound file relative to the "sounds" directory.
613
- :param Channel channel: The channel of the sound.
683
+ :param str sample:
684
+ Sound file relative to the ``sounds`` directory.
685
+ :param Channel channel:
686
+ The channel of the sound.
614
687
"""
615
688
engine_sound .stop_sound (self .index , channel , sample )
616
689
617
690
def is_in_solid (
618
691
self , mask = ContentMasks .ALL , generator = BaseEntityGenerator ):
619
- """Return whether or not the entity is in solid."""
692
+ """Return whether or not the entity is in solid.
693
+
694
+ :param ContentMasks mask:
695
+ Contents the ray can possibly collide with.
696
+ :param generator:
697
+ A callable that returns an iterable which contains
698
+ :class:`BaseEntity` instances that are ignored by the ray.
699
+ :rtype: bool
700
+ """
620
701
# Get a Ray object of the entity physic box
621
702
ray = Ray (self .origin , self .origin , self .mins , self .maxs )
622
703
@@ -634,7 +715,24 @@ def take_damage(
634
715
self , damage , damage_type = DamageTypes .GENERIC , attacker_index = None ,
635
716
weapon_index = None , hitgroup = HitGroup .GENERIC , skip_hooks = False ,
636
717
** kwargs ):
637
- """Method used to hurt the entity with the given arguments."""
718
+ """Deal damage to the entity.
719
+
720
+ :param int damage:
721
+ Amount of damage to deal.
722
+ :param DamageTypes damage_type:
723
+ Type of the dealed damage.
724
+ :param int attacker_index:
725
+ If not None, the index will be used as the attacker.
726
+ :param int weapon_index:
727
+ If not None, the index will be used as the weapon. This method
728
+ also tries to retrieve the attacker from the weapon, if
729
+ ``attacker_index`` wasn't set.
730
+ :param HitGroup hitgroup:
731
+ The hitgroup where the damage should be applied.
732
+ :param bool skip_hooks:
733
+ If True, the damage will be dealed directly by skipping any
734
+ registered hooks.
735
+ """
638
736
# Import Entity classes
639
737
# Doing this in the global scope causes cross import errors
640
738
from weapons .entity import Weapon
@@ -730,7 +828,7 @@ def take_damage(
730
828
@wrap_entity_mem_func
731
829
def teleport (self , origin = None , angle = None , velocity = None ):
732
830
"""Change the origin, angle and/or velocity of the entity.
733
-
831
+
734
832
:param Vector origin:
735
833
New location of the entity.
736
834
:param QAngle angle:
@@ -762,7 +860,8 @@ def set_parent(self, parent, attachment=INVALID_ATTACHMENT_INDEX):
762
860
def _on_entity_deleted (base_entity ):
763
861
"""Called when an entity is removed.
764
862
765
- :param BaseEntity base_entity: The removed entity.
863
+ :param BaseEntity base_entity:
864
+ The removed entity.
766
865
"""
767
866
# Make sure the entity is networkable...
768
867
if not base_entity .is_networked ():
0 commit comments