|
19 | 19 | from engines.server import engine_server |
20 | 20 | from engines.server import execute_server_command |
21 | 21 | from engines.server import server_game_dll |
| 22 | +from engines.sound import Attenuation |
| 23 | +from engines.sound import Channel |
| 24 | +from engines.sound import engine_sound |
| 25 | +from engines.sound import Pitch |
| 26 | +from engines.sound import Sound |
| 27 | +from engines.sound import SoundFlags |
| 28 | +from engines.sound import SOUND_FROM_WORLD |
| 29 | +from engines.sound import StreamSound |
| 30 | +from engines.sound import VOL_NORM |
22 | 31 | from engines.trace import engine_trace |
23 | 32 | from engines.trace import ContentMasks |
24 | 33 | from engines.trace import GameTrace |
|
39 | 48 | # Filters |
40 | 49 | from filters.entities import EntityIter |
41 | 50 | # Mathlib |
| 51 | +from mathlib import NULL_VECTOR |
42 | 52 | from mathlib import Vector |
43 | 53 | from mathlib import QAngle |
44 | 54 | # Memory |
@@ -619,6 +629,58 @@ def ban(self, duration=0, kick=True, write_ban=True): |
619 | 629 | if write_ban: |
620 | 630 | execute_server_command('writeid') |
621 | 631 |
|
| 632 | + def play_sound( |
| 633 | + self, sample, volume=VOL_NORM, attenuation=Attenuation.NONE, |
| 634 | + channel=Channel.AUTO, flags=SoundFlags.NO_FLAGS, |
| 635 | + pitch=Pitch.NORMAL, origin=NULL_VECTOR, direction=NULL_VECTOR, |
| 636 | + origins=(), update_positions=True, sound_time=0.0, |
| 637 | + speaker_entity=INVALID_ENTITY_INDEX, download=False, |
| 638 | + stream=False): |
| 639 | + """Play a sound to the player. |
| 640 | +
|
| 641 | + :param str sample: Sound file relative to the "sounds" directory. |
| 642 | + :param float volume: Volume of the sound. |
| 643 | + :param Attenuation attenuation: How far the sound should reaches. |
| 644 | + :param int channel: Channel to emit the sound with. |
| 645 | + :param SoundFlags flags: Flags of the sound. |
| 646 | + :param Pitch pitch: Pitch of the sound. |
| 647 | + :param Vector origin: Origin of the sound. |
| 648 | + :param Vector direction: Direction of the sound. |
| 649 | + :param tuple origins: Origins of the sound. |
| 650 | + :param bool update_positions: Whether or not the positions should be |
| 651 | + updated. |
| 652 | + :param float sound_time: Time to play the sound for. |
| 653 | + :param int speaker_entity: Index of the speaker entity. |
| 654 | + :param bool download: Whether or not the sample should be added to the |
| 655 | + downloadables. |
| 656 | + :param bool stream: Whether or not the sound should be streamed. |
| 657 | + """ |
| 658 | + # Don't bother playing sounds to bots... |
| 659 | + if self.is_fake_client(): |
| 660 | + return |
| 661 | + |
| 662 | + # Get the correct Sound class... |
| 663 | + if not stream: |
| 664 | + sound_class = Sound |
| 665 | + else: |
| 666 | + sound_class = StreamSound |
| 667 | + |
| 668 | + # Get the sound... |
| 669 | + sound = sound_class(sample, SOUND_FROM_WORLD, volume, attenuation, |
| 670 | + channel, flags, pitch, origin, direction, origins, |
| 671 | + update_positions, sound_time, speaker_entity, download) |
| 672 | + |
| 673 | + # Play the sound to the player... |
| 674 | + sound.play(self.index) |
| 675 | + |
| 676 | + def stop_sound(self, sample, channel=Channel.AUTO): |
| 677 | + """Stop the given sound from being played to the player. |
| 678 | +
|
| 679 | + :param str sample: Sound file relative to the "sounds" directory. |
| 680 | + :param Channel channel: Te channel of the sound. |
| 681 | + """ |
| 682 | + engine_sound.stop_sound(self.index, channel, sample) |
| 683 | + |
622 | 684 | # ========================================================================= |
623 | 685 | # >> PLAYER WEAPON FUNCTIONALITY |
624 | 686 | # ========================================================================= |
|
0 commit comments