本文整理汇总了Python中minqlx.console_command函数的典型用法代码示例。如果您正苦于以下问题:Python console_command函数的具体用法?Python console_command怎么用?Python console_command使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了console_command函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unlock
def unlock(cls, team=None):
if team is None:
return minqlx.console_command("unlock")
elif team.lower() not in minqlx.TEAMS.values():
raise ValueError("Invalid team.")
return minqlx.console_command("unlock {}".format(team.lower()))
示例2: cmd_rcon
def cmd_rcon(self, player, msg, channel):
"""Sends an rcon command to the server."""
if len(msg) < 2:
return minqlx.RET_USAGE
with minqlx.redirect_print(channel):
minqlx.console_command(" ".join(msg[1:]))
示例3: cmd_addbot
def cmd_addbot(self, player, msg, channel):
if player.team == "spectator":
player.tell("You can't use this command as a spectator.")
return minqlx.RET_STOP_ALL
elif self.current_bot:
player.tell("The bot is already active.")
return minqlx.RET_STOP_ALL
elif len(msg) < 2:
return minqlx.RET_USAGE
try:
thinktime = int(msg[1])
if (thinktime < 0 or thinktime > 200):
raise ValueError
except ValueError:
player.tell("Please select a skill between 0 and 200. 0 is very difficult, 60 is hard, 200 is easier but still not noob-friendly")
return minqlx.RET_STOP_ALL
self.set_cvar("bot_thinktime", thinktime)
teams = self.teams()
team = "b" if len(teams["red"]) > len(teams["blue"]) else "r"
self.expecting_bot = True
minqlx.console_command("addbot {} {} 0 {} \"{}\""
.format(self.get_cvar("qlx_bot"), self.get_cvar("qlx_botSkill"), team, self.get_cvar("qlx_botName")))
self.expecting_bot = False
示例4: fetch
def fetch(self, player, gt, callback):
try:
sid = player.steam_id
except:
sid = player
attempts = 0
last_status = 0
while attempts < MAX_ATTEMPTS:
attempts += 1
url = "http://qlstats.net:8080/{elo}/{}".format(sid, elo=self.get_cvar('qlx_balanceApi'))
res = requests.get(url)
last_status = res.status_code
if res.status_code != requests.codes.ok:
continue
js = res.json()
if "players" not in js:
last_status = -1
continue
for p in js["players"]:
_sid = int(p["steamid"])
if _sid == sid: # got our player
if gt not in p:
return minqlx.console_command("echo No {} rating for {}".format(gt, _sid))
_gt = p[gt]
return callback(player, _gt["elo"], _gt["games"])
minqlx.console_command("echo Problem fetching glicko: " + str(last_status))
return
示例5: handle_client_command
def handle_client_command(self, player, command):
command = command.lower()
command = command.split()
if command[0] == "stopserver":
if player == self.Owner:
minqlx.console_command("quit")
if command[0] == "addmod":
if player == self.Owner:
try:
target = self.player(int(command[1]))
except:
player.tell("Invalid ID.")
return minqlx.RET_STOP_ALL
self.addmod(target)
return minqlx.RET_STOP_ALL
if command[0] == "demote":
if player == self.Owner:
try:
target = self.player(int(command[1]))
except:
player.tell("Invalid ID.")
return minqlx.RET_STOP_ALL
if target == self.Owner:
player.tell("You cannot demote the server owner.")
return minqlx.RET_STOP_ALL
self.demote(target)
return minqlx.RET_STOP_ALL
示例6: handle_player_spawn
def handle_player_spawn(self, player):
"""Spawns player instantly and gives quad/haste on some maps.
Moves player to position if they used !goto or !loadpos.
Removes player from frame dict."""
map_name = self.game.map.lower()
if self.map_restart:
self.map_restart = False
minqlx.console_command("map_restart")
if player.team == "free":
player.is_alive = True
if map_name == "wsm":
player.powerups(quad=999999)
elif map_name in HASTE:
player.powerups(haste=999999)
elif map_name == "bokluk":
player.flight(fuel=3500, max_fuel=3500)
if player.steam_id in self.move_player and player.is_alive:
if player.steam_id not in self.goto:
player.tell("^6Your time will not count, unless you kill yourself.")
self.goto[player.steam_id] = player.score
minqlx.set_position(player.id, self.move_player.pop(player.steam_id))
if map_name == "kraglejump":
player.powerups(haste=60) # some stages need haste and some don't, so 60 is a compromise...
self.frame.pop(player.steam_id, None)
示例7: handle_player_connect
def handle_player_connect(self, player):
# If admin, check version number
if self.db.has_permission(player, 5):
self.check_version(player=player)
# If you are not an exception, you must be checked for elo limit
if not (player.steam_id in self.exceptions):
if int(self.get_cvar("qlx_elo_block_connecters")):
try:
url = "http://qlstats.net:8080/{elo}/{}".format(player.steam_id, elo=self.get_cvar('qlx_balanceApi'))
res = requests.get(url)
if res.status_code != requests.codes.ok: raise
js = res.json()
gt = self.game.type_short
if "players" not in js: raise
for p in js["players"]:
if int(p["steamid"]) == player.steam_id and gt in p:
eval_elo = self.evaluate_elo_games(player, p[gt]['elo'], p[gt]['games'])
if eval_elo:
return "^1Sorry, but your skill rating {} is too {}! Accepted ratings: {} - {}".format(eval_elo[1], eval_elo[0], self.ELO_MIN, self.ELO_MAX)
except Exception as e:
minqlx.console_command("echo Error: {}".format(e))
pass
else:
self.fetch(player, self.game.type_short, self.callback)
# Record their join times regardless
self.jointimes[player.steam_id] = time.time()
示例8: cmd_ruleset
def cmd_ruleset(self, player, msg, channel):
if len(msg) < 2:
return minqlx.RET_USAGE
if msg[1].lower() == "pql":
minqlx.set_cvar("pmove_airControl", "1")
minqlx.set_cvar("pmove_rampJump", "1")
minqlx.set_cvar("weapon_reload_rg", "1200")
minqlx.set_cvar("pmove_weaponRaiseTime", "10")
minqlx.set_cvar("pmove_weaponDropTime", "10")
minqlx.set_cvar("g_damage_lg", "7")
minqlx.set_cvar("dmflags", "60")
if self.game.type_short == "ca":
minqlx.set_cvar("g_startingHealth", "200")
minqlx.set_cvar("g_startingArmor", "200")
minqlx.console_command("map_restart")
self.msg("PQL ruleset is now set.")
if msg[1].lower() == "vql":
minqlx.set_cvar("pmove_airControl", "0")
minqlx.set_cvar("pmove_rampJump", "0")
minqlx.set_cvar("weapon_reload_rg", "1500")
minqlx.set_cvar("pmove_weaponRaiseTime", "200")
minqlx.set_cvar("pmove_weaponDropTime", "200")
minqlx.set_cvar("g_damage_lg", "6")
if self.game.type_short == "ca":
minqlx.set_cvar("dmflags", "28")
else:
minqlx.console_command("reset dmflags")
minqlx.console_command("reset g_startingHealth")
minqlx.console_command("reset g_startingArmor")
minqlx.console_command("map_restart")
self.msg("VQL ruleset is now set.")
示例9: update_realscores
def update_realscores(teams):
minqlx.console_command("echo Updating realscores (red: {} - blue: {})".format(self.game.red_score, self.game.blue_score))
# Calculate if we are in a special case (in case of plugin reload)
first_round = self.game.red_score + self.game.blue_score == 1
special_case = not (self.scores_snapshot or first_round)
for _p in teams['red'] + teams['blue']:
# Gather the data
sid = _p.steam_id
score = _p.stats.score
frags = _p.stats.kills
curr_dmg = _p.stats.damage_dealt
hc = int(_p.cvars.get('handicap', 100))
prev_dmg = self.scores_snapshot.get(sid, [None, curr_dmg if special_case else 0])[1]
diff = curr_dmg - prev_dmg
actual_diff = diff / hc
# Calculate / update the 'real' scores
self.realdamage[sid] = self.realdamage.get(sid, 0) + actual_diff
self.realscores[sid] = int(self.realdamage[sid] + frags)
# while we're here, update snapshots for next round
self.scores_snapshot[sid] = [_p.team, curr_dmg]
dbg = "echo DBG: {}({}%) pdmg: {} cdmg: {} diff: {} tot.kills: {} scr: {} rscr: {}"
minqlx.console_command(dbg.format(_p.name, hc, prev_dmg, curr_dmg, diff, frags, score, self.realscores[sid]))
示例10: check_version
def check_version(self, player=None, channel=None):
url = "https://raw.githubusercontent.com/barelymissed/minqlx-plugins/master/{}.py"\
.format(self.__class__.__name__)
res = requests.get(url)
if res.status_code != requests.codes.ok:
return
for line in res.iter_lines():
if line.startswith(b'VERSION'):
line = line.replace(b'VERSION = ', b'')
line = line.replace(b'"', b'')
# If called manually and outdated
if channel and VERSION.encode() != line:
channel.reply("^4Server: ^7Currently using ^4BarelyMiSSeD^7's ^6{}^7 plugin ^1outdated^7 version"
" ^6{}^7. The latest version is ^6{}"
.format(self.__class__.__name__, VERSION, line.decode()))
channel.reply("^4Server: ^7See ^3https://github.com/BarelyMiSSeD/minqlx-plugins")
# If called manually and alright
elif channel and VERSION.encode() == line:
channel.reply("^4Server: ^7Currently using ^4BarelyMiSSeD^7's latest ^6{}^7 plugin version ^6{}^7."
.format(self.__class__.__name__, VERSION))
channel.reply("^4Server: ^7See ^3https://github.com/BarelyMiSSeD/minqlx-plugins")
# If routine check and it's not alright.
elif player and VERSION.encode() != line:
try:
player.tell("^4Server: ^3Plugin update alert^7:^6 {}^7's latest version is ^6{}^7 and you're"
" using ^6{}^7!".format(self.__class__.__name__, line.decode(), VERSION))
player.tell("^4Server: ^7See ^3https://github.com/BarelyMiSSeD/minqlx-plugins")
except Exception as e:
minqlx.console_command("echo {}".format(e))
return
示例11: cmd_inviteOnlyAdd
def cmd_inviteOnlyAdd(self, player, msg, channel):
if len(msg) < 2:
player.tell("^3usage^7=^7<^2player id^7|^2steam id^7> <^2name^7>")
return minqlx.RET_STOP_EVENT
target_player = False
file = os.path.join(self.get_cvar("fs_homepath"), INVITEONLY_FILE)
try:
with open(file) as test:
pass
except Exception as e:
player.tell("^1Error ^3reading the Invite Only list file: {}".format(e))
return minqlx.RET_STOP_EVENT
# Checks to see if client_id or steam_id was used
try:
id = int(msg[1])
if 0 <= id <= 63:
try:
target_player = self.player(id)
except minqlx.NonexistentPlayerError:
player.tell("^3There is no one on the server using that Client ID.")
return minqlx.RET_STOP_EVENT
if not target_player:
player.tell("^3There is no one on the server using that Client ID.")
return minqlx.RET_STOP_EVENT
id = int(target_player.steam_id)
elif len(msg) < 3 or id < 0:
player.tell("^3usage^7=^7<^2player id^7|^2steam id^7> <^2name^7>")
return minqlx.RET_STOP_EVENT
elif len(str(id)) != 17:
player.tell("^3The STEAM ID given needs to be 17 digits in length.")
return minqlx.RET_STOP_EVENT
except ValueError:
player.tell("^3Invalid ID. Use either a client ID or a SteamID64.")
return minqlx.RET_STOP_EVENT
if not target_player:
target_player = " ".join(msg[2:])
# Checks to see if the player is already on the Invite Only list and adds if not.
if id in self.inviteonly:
player.tell("^2{}^3 is already in the Invite Only list.".format(target_player))
return minqlx.RET_STOP_EVENT
h = open(file, "a")
h.write(str(id) + " " + str(target_player) + "\n")
h.close()
self.inviteonly.append(id)
player.tell("^2{}^3 has been added to the Invite Only list.".format(target_player))
if id in self.notOnIOList:
self.notOnIOList.remove(id)
player_list = self.players()
for p in player_list:
if id == p.steam_id:
minqlx.console_command("tell {} ^3You have been added to the Invited Player list for this server. Enjoy your game!".format(p.id))
return minqlx.RET_STOP_EVENT
return minqlx.RET_STOP_EVENT
示例12: get_maps
def get_maps(self, player=None, msg=None, channel=None):
with self.gather_maps():
minqlx.console_command("dir maps")
if player:
player.tell("^4Server^7: The server maps have been stored in the file ^3{}^7.".format(FILE_NAME))
return True
示例13: grabmaps
def grabmaps(self):
if self.supported_maps: return
def callback(maps=[]):
self.supported_maps = maps
with minqlx.redirect_print(GetMaps(callback)):
minqlx.console_command("dir maps bsp")
示例14: handle_map
def handle_map(self, mapname, factory):
if self.get_cvar("bot_enable", bool):
self.botError = False
minqlx.console_command("addbot trainer 5 a 0 TestingBotSupport")
minqlx.console_command("kick TestingBotSupport")
self.atGameEnd = False
@minqlx.delay(11)
def f():
if self.botError:
self.msg("^3Warning:^7 Bots are not supported on this map.")
self.talk_beep()
f()
示例15: cmd_get_hc
def cmd_get_hc(self, player, msg, channel):
"""Check a person's handicap percentage. If no one was specified,
display the handicap of the command calling player
Ex: !hc - Returns callers' own HC
Ex: !hc 2 - Returns the HC of player with ingame id 2
Ex: !hc 2 silent - Returns a pm of the HC of player with ingame id 2
Ex: !hc iou - Returns the HC of person with iou in their name.
Ex: !hc iou silent - Returns a PM of the HC of person with iou in their name.
"""
if len(msg) == 1:
target_player = player
silent = False
elif len(msg) == 2:
target_player = self.find_by_name_or_id(player, msg[1])
silent = False
elif len(msg) == 3 and msg[2] == "silent":
target_player = self.find_by_name_or_id(player, msg[1])
silent = True
else:
return minqlx.RET_USAGE
if target_player:
name = target_player.name
try:
target_player.update()
hc = target_player.cvars["handicap"]
if int(hc) < 100:
m = "^7Player ^6{} ^7is currently playing with handicap ^3{}^7%".format(target_player.name, hc)
if silent:
player.tell("^6Psst: "+m)
return minqlx.RET_STOP_ALL
else:
channel.reply(m)
else:
m = "^7Player ^6{} ^7has no active handicap.".format(target_player.name)
if silent:
player.tell("^6Psst: "+m)
return minqlx.RET_STOP_ALL
else:
channel.reply(m)
except Exception as e:
minqlx.console_command("echo Error: {}".format(e))
m = "^7Something unexpected happened while getting ^6{}^7's handicap.".format(name)
if silent:
player.tell("^6Psst: "+m)
else:
channel.reply(m)