Page 1 of 1

Play sound

Posted: Mon Jan 18, 2016 4:15 pm
by decompile
Hey, how can I play a sound for a player and stop it?

Is there something like

playSound(path)
stopSound(path)

Posted: Mon Jan 18, 2016 4:49 pm
by iPlayer
Hey there

http://wiki.sourcepython.com/pages/engines.sound#Sound

Syntax: Select all

from engines.sound import Sound
from events import Event
from players.helpers import index_from_userid


sound = Sound("ambient/music/latin.wav")


@Event('player_jump')
def on_player_jump(game_event):
index = index_from_userid(game_event.get_int('userid'))
sound.play(index)


def unload():
sound.stop()

Posted: Mon Jan 18, 2016 5:19 pm
by satoon101
That information is slightly outdated now. Use the new wiki:
http://build.affecta.net/job/Source.Python%20-%20Documentation/lastSuccessfulBuild/artifact/cstrike/addons/source-python/docs/source-python/build/modules/engines.sound.html#engines.sound.Sound

Also, just a note, but if you use a specific index to emit the sound from, or channel, make sure to pass those values in the stop method if they differ from the Sound instance's values of index/channel.