Skip to content

Instantly share code, notes, and snippets.

@em92
Created March 3, 2019 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save em92/98814fe4f545a7162e72b6b5df59c5a3 to your computer and use it in GitHub Desktop.
Save em92/98814fe4f545a7162e72b6b5df59c5a3 to your computer and use it in GitHub Desktop.
minqlx demo for 1.0.0
import minqlx
import random
CS_ITEMS = 15
class demo(minqlx.Plugin):
def __init__(self):
self.add_command("demo1", self.cmd_demo1)
self.add_command("demo2", self.cmd_demo2, usage="low|high|default")
self.add_command("demo3", self.cmd_demo3, usage="green|yellow|red")
self.add_command("demo4", self.cmd_demo4)
self.add_hook("player_spawn", self.handle_player_spawn)
self.add_hook("player_items_toss", self.handle_player_items_toss)
self.add_hook("set_configstring", self.handle_set_configstring)
minqlx.set_configstring(CS_ITEMS, minqlx.get_configstring(CS_ITEMS))
def handle_set_configstring(self, index, value):
# this will force client to load all items
if index == CS_ITEMS:
return '1' * len(value)
def handle_player_spawn(self, player):
player.center_print("AIRCONTROL AND SPEED RATIO ARE DEFAULTS")
def handle_player_items_toss(self, player):
# do nothing with disconnected players
if player.connection_state != "active":
return
# disable droping railgun
# quite useful to make railwhoring in spacectf problematic
if player.weapon == minqlx.WP_RAILGUN:
player.weapon(1) # switches player's current weapon to gauntlet, not to drop weapon
player.powerups(reset=True)
# throws 2 random items
return [
random.randint(1, 60),
random.randint(1, 60),
]
def cmd_demo1(self, player, msg, channel):
player.air_control = not player.air_control
channel.reply("Aircontrol for ^6{} ^1{}".format(player.name, "ENABLED" if player.air_control else "DISABLED"))
def cmd_demo2(self, player, msg, channel):
if len(msg) < 2:
return minqlx.RET_USAGE
param = msg[1].lower().strip()
if param == "low":
player.speed_ratio = 0.5
elif param == "high":
player.speed_ratio = 2
elif param == "default":
player.speed_ratio = 1
channel.reply("Speed ratio for ^6{} is ^1{}".format(player.name, player.speed_ratio))
def cmd_demo3(self, player, msg, channel):
if not self.get_cvar("armor_tiered", bool):
channel.reply("Set ^5armor_tiered 1 ^7first")
return
if len(msg) < 2:
return minqlx.RET_USAGE
try:
chosen = msg[1].lower().strip()
player.armor_type = {
"green": 0,
"yellow": 1,
"red": 2
}[chosen]
except KeyError:
return minqlx.RET_USAGE
player.armor = 200
channel.reply("^6{}^7's armor is {}".format(player.name, chosen))
def cmd_demo4(self, player, msg, channel):
player.slay_with_mod(0)
channel.reply("^6{} dropped some items".format(player.name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment