Page 1 of 1

Usage of sounds

Posted: Sat May 10, 2014 3:53 pm
by Tuck
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

Posted: Sat May 10, 2014 4:05 pm
by satoon101
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>')

Posted: Sat May 10, 2014 4:15 pm
by Tuck

Syntax: Select all

Shared.MRecipientFilter()


do i still import shared from source? and create a recipeintfilter like this ?

Posted: Sat May 10, 2014 4:42 pm
by Ayuto
No, you would do this:

Syntax: Select all

from filters.recipients import RecipientFilter


The Source package doesn't exist anymore.

Posted: Sat May 10, 2014 5:13 pm
by satoon101
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