[CS:GO] Playing sounds
Posted: Sat Jul 09, 2016 6:06 am
According to this AM article
You can't, though:
1. Use "download" kwarg in GenericSound constructor - it won't work
2. Properly get sound duration
SP really lacks this functionality. Simple file separation (generic fallback Sound class in engines/sound/__init__.py and an improved Sound class in engines/sound/csgo/__init__.py that inherits from it) would do the trick.
Syntax: Select all
from core import GAME_NAME
from engines.sound import Sound
from events import Event
from players.entity import Player
from stringtables import string_tables
from stringtables.downloads import Downloadables
SOUND_PATH = "arcjail/welcome.mp3"
class GenericSound(Sound):
def precache(self):
"""Precache the sample."""
if GAME_NAME in ("csgo", ): # Probably more games: L4D2 etc
string_tables.soundprecache.add_string(self.sample, self.sample)
else:
engine_sound.precache_sound(self.sample)
@property
def sample(self):
"""Return the filename of the Sound instance."""
if GAME_NAME in ("csgo", ):
return "*/{}".format(self._sample)
return self._sample
my_sound = GenericSound(SOUND_PATH)
downloadables = Downloadables()
downloadables.add("sound/{}".format(SOUND_PATH))
@Event('player_spawn')
def on_player_spawn(game_event):
player = Player.from_userid(game_event['userid'])
my_sound.play(player.index)
You can't, though:
1. Use "download" kwarg in GenericSound constructor - it won't work
2. Properly get sound duration
SP really lacks this functionality. Simple file separation (generic fallback Sound class in engines/sound/__init__.py and an improved Sound class in engines/sound/csgo/__init__.py that inherits from it) would do the trick.