Posted: Thu Nov 26, 2015 11:32 am
Try this. This limits users to have only one sound playing.
Syntax: Select all
from engines.sound import SOUND_FROM_WORLD
from engines.sound import Sound
from events import Event
from listeners.tick import tick_delays
from messages import SayText2
ANTI_SPAM_TIMEOUT = 5
_sounds = {
'test': Sound((), SOUND_FROM_WORLD, 'vo/npc/female01/hellodrfm02.wav', download=True),
}
_duplicates = {
'test1': 'test',
}
_userids = set()
@Event('player_say')
def on_player_say(game_event):
"""Play a sound if necessary."""
userid = game_event.get_int('userid')
if userid in _userids:
return
text = game_event.get_string('text')
if text in _duplicates:
text = _duplicates[text]
if text in _sounds:
_userids.add(userid)
def remove_userid_callback():
_userids.remove(userid)
tick_delays.delay(ANTI_SPAM_TIMEOUT, remove_userid_callback)
_sounds[text].play()
@Event('round_start')
def on_round_start(game_event):
"""Reset _userids set."""
_userids.clear()