Skip to content

Instantly share code, notes, and snippets.

@tjone270
Last active December 14, 2015 18:10
Show Gist options
  • Save tjone270/9ed1ae9b43c897699c37 to your computer and use it in GitHub Desktop.
Save tjone270/9ed1ae9b43c897699c37 to your computer and use it in GitHub Desktop.
rysiu_sounds.py, a minqlx plugin for RysiuWroc of RysiuBot servers in Poland.
# get access to the minqlx code base so we can access the server and game
import minqlx
# import the randint function from the random class, so we can make random numbers
from random import randint
class rysiu_sounds(minqlx.Plugin):
def __init__(self):
# Adding hooks, so everytime the map changes or the round ends, the code runs :)
self.add_hook("map", self.reference_soundpack)
self.add_hook("round_end", self.play_round_end_sound)
# Adding the !roundsound command, making it run for players with level 5 permissions only.
self.add_command("roundsound", self.toggle_round_sound, 5, usage="on/off")
self.soundpack_id = "00000000"
self.round_sound_path_0 = "rysiu_sounds/path/to/sound/file"
self.round_sound_path_1 = "rysiu_sounds/path/to/sound/file"
self.round_sound_path_2 = "rysiu_sounds/path/to/sound/file"
self.round_sound_path_3 = "rysiu_sounds/path/to/sound/file"
self.round_sound_path_4 = "rysiu_sounds/path/to/sound/file"
self.round_sound_path_5 = "rysiu_sounds/path/to/sound/file"
def reference_soundpack(self, mapname, factory):
# Download your sound pack from the workshop onto your player's computers when they first join.
self.game.steamworks_items += [self.soundpack_id]
def play_round_end_sound(self, round_number):
# If the variable is set to True, then pick a random sound and play it to everyone, otherwise don't.
if self.round_sound_enabled == True:
# generate a random number between 0 and 5, and store that number in the randomNumber variable
randomNumber = randint(0,5)
# play one of the six sounds randomly based of the number generated.
if randomNumber == 0:
self.play_sound(self.round_sound_path_0)
if randomNumber == 1:
self.play_sound(self.round_sound_path_1)
if randomNumber == 2:
self.play_sound(self.round_sound_path_2)
if randomNumber == 3:
self.play_sound(self.round_sound_path_3)
if randomNumber == 4:
self.play_sound(self.round_sound_path_4)
if randomNumber == 5:
self.play_sound(self.round_sound_path_5)
def toggle_round_sound(self, player, msg, channel):
# If the person just wrote !roundsound, without a off or on option, display a message explaining how to use it.
if len(msg) < 2:
return minqlx.RET_USAGE
# If the message said after !roundsound is on, like "!roundsound on", then set the variable to True
if msg[1] == "on":
self.round_sound_enabled = True
player.tell("The round end sound is now enabled.")
# Else If the message said after !roundsound is off, like "!roundsound off", then set the variable to False
elif msg[1] == "off":
self.round_sound_enabled = False
player.tell("The round end sound is now disabled.")
# Else the message said after !roundsound isn't either on or off, tell the player the command is wrong.
else:
player.tell("{}^7 isn't a valid option, only ^4on^7 and ^4off^7 are accepted.".format(msg[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment