Plugins converts from Eventscripts to Source Python

A place for requesting new Source.Python plugins to be made for your server.

Please request only one plugin per thread.
User avatar
iPlayer
Developer
Posts: 445
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Postby iPlayer » 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()
User avatar
Killer0561
Junior Member
Posts: 20
Joined: Tue Aug 26, 2014 5:34 pm
Location: Germany

Postby Killer0561 » Thu Nov 26, 2015 12:34 pm

Thank you very much for replay, i will test it today and give Feedback.

- Killer0561
User avatar
Ayuto
Project Leader
Posts: 1543
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Thu Nov 26, 2015 2:38 pm

I think Satoon's code was doing exactly what Killer0561 requested. The only problem is that <Sound>.duration always seems to return 0. I guess we need to fix that.
User avatar
satoon101
Project Leader
Posts: 2290
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Nov 26, 2015 3:14 pm

I have been meaning to look into the duration issue. We might need to include mp3lib to get the duration of mp3 files.
Image
User avatar
iPlayer
Developer
Posts: 445
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Postby iPlayer » Thu Nov 26, 2015 3:50 pm

Ayuto wrote:I think Satoon's code was doing exactly what Killer0561 requested. The only problem is that <Sound>.duration always seems to return 0. I guess we need to fix that.


Wow, I actually missed Satoon's answer and took the code from the previous post. My bad.
User avatar
Ayuto
Project Leader
Posts: 1543
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Thu Nov 26, 2015 6:33 pm

satoon101 wrote:I have been meaning to look into the duration issue. We might need to include mp3lib to get the duration of mp3 files.
I think sndhdr should suffice and it's already included.

I noticed that we also need something to access files packed in VPK files.

Edit: Just noticed that mp3 files are not supported.
Edit2: mutagen seems to support many file types.
User avatar
satoon101
Project Leader
Posts: 2290
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Nov 26, 2015 10:59 pm

I keep forgetting to test this, but we could use it for vpk files:
https://pypi.python.org/pypi/vpk

I have used mutagen locally. I will have to check my local files to see how I used them.
Image
User avatar
iPlayer
Developer
Posts: 445
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Postby iPlayer » Thu Nov 26, 2015 11:16 pm

Is there no way to access VPK content internally? I mean, from the engine level as it mounts VPK. I guess working with VPK from outside means a lot of wasted RAM.
User avatar
Ayuto
Project Leader
Posts: 1543
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Fri Nov 27, 2015 9:56 am

The engine provides us the IFileSystem class.

It's really annoying that Valve uses VPK files, because of two reasons:
  1. Files don't have a file name on the file system.
  2. It causes us a lot extra work, because we need to differenciate between normal files and files packed in VPK files.
User avatar
Killer0561
Junior Member
Posts: 20
Joined: Tue Aug 26, 2014 5:34 pm
Location: Germany

Postby Killer0561 » Wed Mar 30, 2016 8:42 am

Any news for sound duration 0? Because a long time has indeed passed.

- Killer0561
User avatar
satoon101
Project Leader
Posts: 2290
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Mar 30, 2016 1:29 pm

Thank you for reminding us about this. I am doing a bit of work on that right now. I seem to be having issues with wav files, but I have it working using mutagen for mp3 and ogg files (BMS allows ogg but not mp3). We also still don't have a way to interact using vpk files with sounds in them, though. That is going to take a bit more work.

*Edit: for reference, I added a new branch called sound_duration for these changes. There is currently only one commit:
https://github.com/Source-Python-Dev-Team/Source.Python/commit/f222438835d9491a225212cc9b8dacd1269eee25
Image
User avatar
Killer0561
Junior Member
Posts: 20
Joined: Tue Aug 26, 2014 5:34 pm
Location: Germany

Postby Killer0561 » Sat Apr 02, 2016 6:18 pm

Hello satoon, thanks for the intermediate state.

- Killer0561
User avatar
Killer0561
Junior Member
Posts: 20
Joined: Tue Aug 26, 2014 5:34 pm
Location: Germany

Re: Plugins converts from Eventscripts to Source Python

Postby Killer0561 » Fri Nov 25, 2016 6:52 pm

Hi,

i have all times this error:

19:42:48 [SP] Loading plugin 'saysounds'...

[SP] Caught an Exception:
Traceback (most recent call last):
File "../addons/source-python/packages/source-python/plugins/manager.py", line 75, in __missing__
instance = self.instance(plugin_name, self.base_import)
File "../addons/source-python/packages/source-python/plugins/instance.py", line 82, in __init__
self._plugin = import_module(import_name)
File "../addons/source-python/plugins/saysounds/saysounds.py", line 9, in <module>
'aua': <TAB>Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/aua.wav', <TAB>download=True),
File "../addons/source-python/packages/source-python/engines/sound.py", line 120, in __init__
self._sample = sample.replace('\\', '/')

AttributeError: 'tuple' object has no attribute 'replace'

[SP] Plugin 'saysounds' was unable to be loaded.


Can anyone help me please? :)


Syntax: Select all

from engines.sound import SOUND_FROM_WORLD
from engines.sound import Sound
from events import Event
from listeners.tick import Delay
from messages import SayText2
from players.helpers import index_from_userid

_sounds = {
'aua': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/aua.wav', download=True),
'axel': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/axel.mp3', download=True),
'badboys': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/badboys.wav', download=True),
'benny': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/benny.wav', download=True),
'blut': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/blut.mp3', download=True),
'body': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/body.mp3', download=True),
'cry': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/cry.mp3', download=True),
'feelgood': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/feelgood.mp3', download=True),
'frage': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/frage.mp3', download=True),
'fu': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/fu.mp3', download=True),
'haha': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/haha.mp3', download=True),
'hehe': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/hehe.wav', download=True),
'hi': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/hi.mp3', download=True),
'impossible': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/impossible.mp3', download=True),
'komm': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/komm.wav', download=True),
'leben': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/leben.mp3', download=True),
'lol': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/lol.mp3', download=True),
'lucker': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/lucker.mp3', download=True),
'oops': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/oops.mp3', download=True),
'power': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/power.mp3', download=True),
'schnauze': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/schnauze.mp3', download=True),
'silence': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/silence.wav', download=True),
'sry': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/sry.mp3', download=True),
'taliban': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/taliban.mp3', download=True),
'time': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/time.mp3', download=True),
'verbot': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/verbot.mp3', download=True),
'woohoo': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/woohoo.wav', download=True),
'wtf': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/wtf.mp3', download=True),
'yeah': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/yeah.wav', download=True),
'zzz': Sound((), SOUND_FROM_WORLD, 's_sounds/saysounds/***/zzz.wav', download=True),
}

_duplicates = {
'': '',
}

_current_sound = None


@Event('player_say')
def player_say(game_event):
"""Play a sound if necessary."""
global _current_sound

text = game_event['text']

if text in _duplicates:
text = _duplicates[text]

if text not in _sounds:
return

if _current_sound is not None:

SayText2('\x03[Saysounds] \x04Es wird bereits der Sound \x03{0} \x04abgespielt!'.format(_current_sound)).send(index_from_userid(game_event['userid']))
return

sound = _sounds[text]

sound.play()

_current_sound = sound.sample

Delay(sound.duration, _reset_sound)


def _reset_sound():
global _current_sound
_current_sound = None


- Killer0561
Last edited by Killer0561 on Fri Nov 25, 2016 8:24 pm, edited 3 times in total.
User avatar
Ayuto
Project Leader
Posts: 1543
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Plugins converts from Eventscripts to Source Python

Postby Ayuto » Fri Nov 25, 2016 8:12 pm

The plugin was out-dated. Here is the updated one:

Syntax: Select all

from engines.sound import Sound
from events import Event
from listeners.tick import Delay
from messages import SayText2
from players.helpers import index_from_userid

_sounds = {
'aua': Sound('s_sounds/saysounds/***/aua.wav', download=True),
'axel': Sound('s_sounds/saysounds/***/axel.mp3', download=True),
'badboys': Sound('s_sounds/saysounds/***/badboys.wav', download=True),
'benny': Sound('s_sounds/saysounds/***/benny.wav', download=True),
'blut': Sound('s_sounds/saysounds/***/blut.mp3', download=True),
'body': Sound('s_sounds/saysounds/***/body.mp3', download=True),
'cry': Sound('s_sounds/saysounds/***/cry.mp3', download=True),
'feelgood': Sound('s_sounds/saysounds/***/feelgood.mp3', download=True),
'frage': Sound('s_sounds/saysounds/***/frage.mp3', download=True),
'fu': Sound('s_sounds/saysounds/***/fu.mp3', download=True),
'haha': Sound('s_sounds/saysounds/***/haha.mp3', download=True),
'hehe': Sound('s_sounds/saysounds/***/hehe.wav', download=True),
'hi': Sound('s_sounds/saysounds/***/hi.mp3', download=True),
'impossible': Sound('s_sounds/saysounds/***/impossible.mp3', download=True),
'komm': Sound('s_sounds/saysounds/***/komm.wav', download=True),
'leben': Sound('s_sounds/saysounds/***/leben.mp3', download=True),
'lol': Sound('s_sounds/saysounds/***/lol.mp3', download=True),
'lucker': Sound('s_sounds/saysounds/***/lucker.mp3', download=True),
'oops': Sound('s_sounds/saysounds/***/oops.mp3', download=True),
'power': Sound('s_sounds/saysounds/***/power.mp3', download=True),
'schnauze': Sound('s_sounds/saysounds/***/schnauze.mp3', download=True),
'silence': Sound('s_sounds/saysounds/***/silence.wav', download=True),
'sry': Sound('s_sounds/saysounds/***/sry.mp3', download=True),
'taliban': Sound('s_sounds/saysounds/***/taliban.mp3', download=True),
'time': Sound('s_sounds/saysounds/***/time.mp3', download=True),
'verbot': Sound('s_sounds/saysounds/***/verbot.mp3', download=True),
'woohoo': Sound('s_sounds/saysounds/***/woohoo.wav', download=True),
'wtf': Sound('s_sounds/saysounds/***/wtf.mp3', download=True),
'yeah': Sound('s_sounds/saysounds/***/yeah.wav', download=True),
'zzz': Sound('s_sounds/saysounds/***/zzz.wav', download=True),
}

_duplicates = {
'': '',
}

_current_sound = None


@Event('player_say')
def player_say(game_event):
"""Play a sound if necessary."""
global _current_sound

text = game_event['text']

if text in _duplicates:
text = _duplicates[text]

if text not in _sounds:
return

if _current_sound is not None:

SayText2('\x03[Saysounds] \x04Es wird bereits der Sound \x03{0} \x04abgespielt!'.format(text)).send(index_from_userid(game_event['userid']))
return

sound = _sounds[text]

sound.play()

_current_sound = sound.sample

Delay(sound.duration, _reset_sound)


def _reset_sound():
global _current_sound
_current_sound = None

But please post the full traceback in future and not just the error message.
User avatar
Killer0561
Junior Member
Posts: 20
Joined: Tue Aug 26, 2014 5:34 pm
Location: Germany

Re: Plugins converts from Eventscripts to Source Python

Postby Killer0561 » Sun Nov 27, 2016 3:02 pm

Code: Select all

SayText2('\x04[Saysounds] \x03Es wird bereits der Sound {0} abgespielt!'.format(text)).send(index_from_userid(game_event['userid']))

I wanted to have the team color after the \x03, but it is shown to me lightgreen. Has something gone wrong?

- Killer0561
User avatar
L'In20Cible
Project Leader
Posts: 914
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Plugins converts from Eventscripts to Source Python

Postby L'In20Cible » Sun Nov 27, 2016 3:09 pm

You need to set the index of the message.

Syntax: Select all

index = index_from_userid(game_event['userid'])
SayText2('\x04[Saysounds] \x03Es wird bereits der Sound {0} abgespielt!'.format(text), index=index).send(index)


Please, use

Code: Select all

[python][/python]
when posting python codes.

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 1 guest