Play sound

Please post any questions about developing your plugin here. Please use the search function before posting!
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Play sound

Postby decompile » Mon Jan 18, 2016 4:15 pm

Hey, how can I play a sound for a player and stop it?

Is there something like

playSound(path)
stopSound(path)
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Postby iPlayer » Mon Jan 18, 2016 4:49 pm

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()
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Jan 18, 2016 5:19 pm

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.
Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 150 guests