ESS shell to Source python [bms]

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

Please request only one plugin per thread.
User avatar
hugo5511
Junior Member
Posts: 25
Joined: Mon Jun 29, 2015 1:20 am

ESS shell to Source python [bms]

Postby hugo5511 » Mon Jun 29, 2015 1:35 am

Hello,
I have this script it has worked fine for years on my server , would it be possible to covert to Source Python for Black mesa source? Also the scripts go here "C:\bms_ded\bms\addons\source-python\plugins" does it auto load or do i need to add
a line somewhere to "load" the script. Thanks.

Code: Select all


block load
{
        es_xsetinfo word_sound 1
        es_makepublic word_sound
        es_xmsg #multi #green[WordSound]#default loaded
}

block unload
{
        es_xsetinfo word_sound 0
        es_xset #multi #green[WordSound]#default unloaded
}

//It is necessary, that sounds could be downloaded
event es_map_start
{
        es downloadable sound/word_sound/lol.wav
        es downloadable sound/word_sound/bye.wav
        es downloadable sound/word_sound/hello.wav
        es downloadable sound/word_sound/cool.wav
        es downloadable sound/word_sound/duckyou.mp3
        es downloadable sound/word_sound/good.wav
        es downloadable sound/word_sound/move.mp3
        es downloadable sound/word_sound/ohmygod.mp3
        es downloadable sound/word_sound/sorry.mp3
        es downloadable sound/word_sound/start.mp3
}

//It shows the message in the beginning of the round
event round_start
{
        if (server_var(word_sound) > 0) do
        {
              if (server_var(word_sound) > 0) then es_xmsg #multi #green[WordSound]#default Say "lol, bye, hi..." and will be played sound.
        }
}

//It designates a word and a sound
event player_say
{
        if (event_var(text) equalto "lol") then es_cexec_all play word_sound/lol.wav
        if (event_var(text) equalto "bye") then es_cexec_all play word_sound/bye.wav
        if (event_var(text) equalto "goodbye") then es_cexec_all play word_sound/bye.wav
        if (event_var(text) equalto "hello") then es_cexec_all play word_sound/hello.wav
        if (event_var(text) equalto "hi") then es_cexec_all play word_sound/hello.wav
        if (event_var(text) equalto "cool") then es_cexec_all play word_sound/cool.wav
        if (event_var(text) equalto "good") then es_cexec_all play word_sound/good.wav
        if (event_var(text) equalto "fuck") then es_cexec_all play word_sound/duckyou.mp3
        if (event_var(text) equalto "fuck you") then es_cexec_all play word_sound/duckyou.mp3
        if (event_var(text) equalto "move") then es_cexec_all play word_sound/move.mp3
        if (event_var(text) equalto "god") then es_cexec_all play word_sound/ohmygod.mp3
        if (event_var(text) equalto "my god") then es_cexec_all play word_sound/ohmygod.mp3
        if (event_var(text) equalto "sorry") then es_cexec_all play word_sound/sorry.mp3
        if (event_var(text) equalto "sry") then es_cexec_all play word_sound/sorry.mp3
        if (event_var(text) equalto "start") then es_cexec_all play word_sound/start.mp3
}


Located here [HTML]http://addons.eventscripts.com/addons/view/WordSound[/HTML]
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Jun 29, 2015 2:17 am

Just like EventScripts, you will need to load the script. This is typically done in a config. For more info on loading it:
sp load

As for the script itself, try this:

Syntax: Select all

from engines.sound import SOUND_FROM_WORLD
from engines.sound import Sound
from events import Event
from messages import SayText2


# Create a dictionary with sounds and their primary say trigger
_sounds = {
'lol': Sound((), SOUND_FROM_WORLD, 'word_sound/lol.wav', download=True),
'bye': Sound((), SOUND_FROM_WORLD, 'word_sound/bye.wav', download=True),
'hello': Sound((), SOUND_FROM_WORLD, 'word_sound/hello.wav', download=True),
'cool': Sound((), SOUND_FROM_WORLD, 'word_sound/cool.wav', download=True),
'duck': Sound((), SOUND_FROM_WORLD, 'word_sound/duckyou.mp3', download=True),
'good': Sound((), SOUND_FROM_WORLD, 'word_sound/good.wav', download=True),
'move': Sound((), SOUND_FROM_WORLD, 'word_sound/move.mp3', download=True),
'god': Sound((), SOUND_FROM_WORLD, 'word_sound/ohmygod.mp3', download=True),
'sorry': Sound((), SOUND_FROM_WORLD, 'word_sound/sorry.mp3', download=True),
'start': Sound((), SOUND_FROM_WORLD, 'word_sound/start.mp3', download=True),
}

# Create a dictionary to store other words for sound triggers
_duplicates = {
'goodbye': 'bye',
'hi': 'hello',
'duck you': 'duck',
'my god': 'god',
'sry': 'sorry',
}


def load():
"""Send the loaded message."""
SayText2(message='\x04[WordSound]\x01 loaded').send()


def unload():
"""Send the unloaded message."""
SayText2(message='\x04[WordSound]\x01 unloaded').send()


@Event
def round_start(game_event):
"""Send the notification message."""
SayText2(message='\x04[WordSound]\x01 Say "lol, bye, hi..." and will be played sound.').send()


@Event
def player_say(game_event):
"""Play a sound if necessary."""
# Get the text from chat
text = game_event.get_string('text')

# If the text is in the duplicates dictionary,
# get the primary word trigger.
if text in _duplicates:
text = _duplicates[text]

# Is the text supposed to trigger a sound?
if text in _sounds:

# Play the sound
_sounds[text].play()


Bare in mind that I have only done minimal testing on BMS, so this might not work or possibly even crash. Let us know how it goes.
Image
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Mon Jun 29, 2015 2:23 am

Untested but should work:

Syntax: Select all

# ../word_sound/word_sound.py

# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Python Imports
# Colors
from colors import GREEN
from colors import ORANGE
# Engines
from engines.sound import Sound
# Events
from events import Event
# Messages
from messages import SayText2
# Paths
from paths import SOUND_PATH


# =============================================================================
# >> GLOBAL VARIABLES
# ============================================================================
# Store the path to the sound files: ../sound/source-python/word_sound
word_sound_path = SOUND_PATH.joinpath('word_sound')

# Create a map for the sound name (without the .wav extension) and its path dynamically
sounds = (
dict([x[:x.find('.wav')], Sound((), 0, word_sound_path.joinpath(x), download=True)]
for x in word_sound_path.listdir())
)

# Store messages
message_round = SayText2(message='{0}[WordSound]{1] Say "lol, bye, hi... and will be played sound.'.format(GREEN, ORANGE))
message_loaded = SayText2(message='{0}[WordSound]{1] loaded.'.format(GREEN, ORANGE))
message_unloaded = SayText2(message='{0}[WordSound]{1] unloaded'.format(GREEN, ORANGE))


# =============================================================================
# >> EVENTS
# ============================================================================
@Event
def round_start(game_event):
"""Send 'message_round' to all players."""
message_round.send()


@Event
def player_say(game_event):
"""Play a sound for all players if a player typed in the name of a sound to play."""
# Get the text
text = game_event.get_string('text')

# Is the text the name of a sound?
if text in sounds:

# If yes, play it
sounds[text].play()


# =============================================================================
# >> LOAD & UNLOAD
# ============================================================================
def load():
"""Send 'message_load' to all players."""
message_loaded.send()


def unload():
"""Send 'message_unload' to all players."""
message_unloaded.send()

You need to execute the following command to run it:

Code: Select all

sp load word_sound
You can also put it in your cfg/autoexec.cfg file.

To make it work you have to put your sounds (lol.wav, bye.wav, ...) into the folder: ../sound/source-python/word_sound
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Jun 29, 2015 2:47 pm

I notice 3 issues with your script at first glance, BackRaw. First, you are only supposed to provide the path from the ../sound/ directory and not the entire path. Second, it only accounts for .wav files when several of the ones listed are .mp3 files. Lastly, as a minor issue, you accidentally used {1] instead of {1} in your message creation lines.

Also, there are several sounds that have multiple triggers that are not accounted for in your script. And some of the sounds (ohmygod and duckyou) do not use exact names as triggers at all. That is why I chose to write it all out in my version instead of just getting them dynamically.
Image
User avatar
hugo5511
Junior Member
Posts: 25
Joined: Mon Jun 29, 2015 1:20 am

Postby hugo5511 » Tue Jun 30, 2015 1:20 am

I tested the script tonight and it worked, with only two little bugs.

1. The message "type lol gg ect" did not show in chat (might of but, bms has long load times)(no big deal)
2.It downloaded to the client 10 sounds, but only played the .wav sounds none of the .mp3 ones
maybe bms only allows .wav files(also no big deal, easy to covert to .wav)



Thanks for you help
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Jun 30, 2015 3:15 am

I did not know about the mp3 issues. I will ask ynh about that one. Though, as you said, you can just convert them.

As for the message, I didn't notice before, but in your original script, it is in the round_start event. I just converted that over as-is. BMS, since it doesn't have rounds, will never fire that event. I could add it in a couple different ways, so let me know which you prefer. First, the message could be sent to all current players every x seconds. Second, the message could be sent every time a player spawns (or every x spawns per player). Third, the message could just be sent once to each client when they join the match (or possibly once per map). Just let me know which of those options you would prefer, and I will update the script.
Image
User avatar
hugo5511
Junior Member
Posts: 25
Joined: Mon Jun 29, 2015 1:20 am

Postby hugo5511 » Tue Jun 30, 2015 3:47 pm

Now that you mention it i do not remember seeing a message on my other server, I used the webshortcutlist to display a .jpeg of the sounds "type sounds to see word sounds"
Does Source python support the text to a URL in a window? if not then "sent once to each client when they join the match " would be great.
Thanks
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Tue Jun 30, 2015 10:04 pm

I'm sorry I just wrote it down quick. Satoon's right - should I check it over? :)

Edit: lol didn't see your version, Satoon.
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Jun 30, 2015 10:12 pm

We do support the MOTD, though that functionality is a little broken currently.

I did ask ynh and he said that wav and ogg were the only sound types BMS supports.
Image
User avatar
hugo5511
Junior Member
Posts: 25
Joined: Mon Jun 29, 2015 1:20 am

Postby hugo5511 » Wed Jul 01, 2015 1:54 am

Thanks on the info for the .wav/.mp3. and for the word_sound script. I have a few more i will post when i see which ones i really need.(lol) The big one would be the MOTD (player connects to server,short delay, then gets redirected to a fastdownload file server, display's
rules 725X365 .jpeg, click Ok and it closes.
User avatar
La Muerte
Administrator
Posts: 180
Joined: Sun Jul 15, 2012 1:48 pm
Location: Belgium
Contact:

Postby La Muerte » Thu Jul 02, 2015 3:54 pm

Hello hugo5511,

The big one would be the MOTD (player connects to server,short delay, then gets redirected to a fastdownload file server, display's
rules 725X365 .jpeg, click Ok and it closes.


I'm not entirely sure what you mean with that, but what you could do is add not one but two HTML files to your fastdownload server:
1. HTML page with e.g. your logo or other content.
2. HTML page with your rules.jpeg embedded (you could just redirect to your rules.jpeg directly)

In the first HTML page with your logo you can add a counter (with e.g. javascript) to redirect to your second HTML page.
E.g.:

Syntax: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Fortitude</title>
<link rel="icon" type="image/x-icon" href="favicon.ico">
<style type="text/css">
html, body {width: 99%; height: 97%; color: lightgray; background: #030304 url("background.png") 50% 20% no-repeat; background-size:contain;}
h4 {float: right;}
</style>
<script type="text/javascript">
window.onload=function() {
function countdown() {
if ( typeof countdown.counter == 'undefined' ) {
countdown.counter = 15; // initial count
}
if(countdown.counter > 0) {
document.getElementById('count').innerHTML = countdown.counter--;
setTimeout(countdown, 1000);
}
else {
location.href = 'http://fortitude-gaming.com';
}
}
countdown();
};
</script>
</head>
<body>
<h4>You will be redirected in <span id="count"></span> seconds</h4>
</body>
</html>
User avatar
hugo5511
Junior Member
Posts: 25
Joined: Mon Jun 29, 2015 1:20 am

Postby hugo5511 » Fri Jul 03, 2015 2:39 am

Thanks for the reply on the MOTD i made a copy of yours and added at bms/cfg/. I'am not sure if bms yet supports MOTD as there is no typical motd_default.txt files or the like (css,hl2mp,l4d2 has these)
what i have done before on hldms with eventscripts and mani-admin plugin was add a folder named events to the cfg folder and inside add this line "es_delayed 16 es_sexec event_var(userid) say rules"
this would appear like the client typed "rules" then mani would pick this up as a redirect to my fastdownload server to "show" a 725x365 .jpeg rules page.Is there anyway this could be done as a sp script?
Thanks

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 28 guests