Usage of sounds

Please post any questions about developing your plugin here. Please use the search function before posting!
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Usage of sounds

Postby Tuck » Sat May 10, 2014 3:53 pm

I have this old code, if anybody could answer a few questions or maybe show a quick example i would appriciate it

Syntax: Select all

from core import GameEngine
from Source import Shared


def server_spawn(GameEvent):
#in this event i usally precached 'sprites/laserbeam.vmt'
#How would i go for a custom sound file do i precache it? and how would i add it to downloadables

Recipients = Shared.MRecipientFilter()
index = Player.IndexOfUserid(userid)
Recipients.AddRecipient(index)
UserMessage = GameEngine.UserMessageBegin(Recipients, 17, None)
UserMessage.WriteString(audio)
GameEngine.MessageEnd()


Thanks in advance
-Tuck
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sat May 10, 2014 4:05 pm

The sound API will eventually take care of a lot of this for you, but for the time being I will just answer the questions.

Precache sound:
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/src/core/modules/engines/engines_wrap_python.cpp#L811

To get the EngineSound instance:

Syntax: Select all

from engines.sound import EngineSound


And you add sounds to downloadables just like you would add any downloadable:

Syntax: Select all

from stringtables.downloads import Downloadables

my_downloadables = Downloadables()
my_downloadables.add('<path to file>')
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sat May 10, 2014 4:15 pm

Syntax: Select all

Shared.MRecipientFilter()


do i still import shared from source? and create a recipeintfilter like this ?
-Tuck
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat May 10, 2014 4:42 pm

No, you would do this:

Syntax: Select all

from filters.recipients import RecipientFilter


The Source package doesn't exist anymore.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sat May 10, 2014 5:13 pm

Also, the message in your script is definitely based off of a really old version of SP. If you want to send a sound, you wouldn't necessarily use a message anyway.
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/src/core/modules/engines/engines_wrap_python.cpp#L248
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/src/core/modules/engines/engines_wrap_python.cpp#L837

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 34 guests