<emitter object>:
type: soundemit
sound:
flags:
- is3dsound
- localonly
file: <sound file>
volume: 0.4
type: ambience
minfdist: 6
maxfdist: 60
logic:
modifiers:
- tag: RandResp
actions:
- type: pythonfile
ref: $Pyth_Random
actions:
- type: pythonfile
tag: Pyth_Random
pythonfile:
file: <python file>
parameters:
- type: responder
ref: $Resp_Random
- type: string
value: <emitter object>
- type: int
value: <timer ID>
- type: float
value: <timer interval>
- type: int
value: <chance value>
- type: sceneobject
ref: scnobj:<emitter object>
- type: responder
tag: Resp_Random
responder:
states:
- cmds:
- type: soundmsg
params:
receivers:
- 0011:<emitter object>
cmds:
- play
- setvolume
volume: 0.4
waiton: -1
nextstate: 0
waittocmd: 0
curstate: 0
flags:
- detecttrigger
from Plasma import *
from PlasmaTypes import *
import xRandom
respSound = ptAttribResponder(1, 'Sound responder')
strObj = ptAttribString(2, 'Object String')
intID = ptAttribInt(3, 'Timer ID')
floatTime = ptAttribFloat(4, 'Timer interval')
intChance = ptAttribInt(5, 'Chance value')
testObj = ptAttribSceneobject(6, 'Owner test object')
class <python file>(ptModifier,):
def __init__(self):
ptModifier.__init__(self)
self.version = '1'
print ('__init__%s v.%s' % (self.__class__.__name__,
self.version))
def OnFirstUpdate(self):
print ('%s: OnFirstUpdate: Getting local avatar' % self.__class__.__name__)
self.LocalAvatar = PtGetLocalAvatar()
def OnServerInitComplete(self):
print ('%s: OnServerInitComplete: Starting timer %d with interval %d for %s' % (self.__class__.__name__,
intID.value, floatTime.value, strObj.value))
PtAtTimeCallback(self.key, floatTime.value, intID.value)
def BeginAgeUnLoad(self, avatar):
if (avatar == self.LocalAvatar):
print ('%s: BeginAgeUnLoad: Leave your timer at the door' % self.__class__.__name__)
PtClearTimerCallbacks(self.key)
def OnTimer(self, id):
print ('%s: OnTimer: id = %d' % (self.__class__.__name__, id))
if (id == intID.value):
cur_chance = xRandom.randint(0, 100)
print (' - Chance value = %d, Local chance roll = %d' % (intChance.value, cur_chance))
if (cur_chance <= intChance.value):
# Responders are netpropagated by default which means that every player will hear the sound, even if it is localonly!
# We want the same sounds to be heard by all but letting all players run them will mess up the chance rolls.
# So only the game owner must run the responder!
if (type(testObj) != type(None)):
if testObj.sceneobject.isLocallyOwned():
print (' - I am game owner. Running sound from %s' % (strObj.value))
respSound.run(self.key)
else:
print (' - Unknown game owner, running sound locally from %s' % (strObj.value))
respSound.run(self.key, netPropagate=0)
PtAtTimeCallback(self.key, floatTime.value, intID.value)
#insert glue section here
Paradox wrote:Is it really necessary to use a Python file to play a sound?
An easier way would be to use a responder with netforcing, and send a plSoundMsg to play/stop/etc. the sound.
Users browsing this forum: No registered users and 3 guests