Skip to content

Instantly share code, notes, and snippets.

@x0rnn
Last active August 31, 2021 12:47
Show Gist options
  • Save x0rnn/fcd73d95c894a04cb91fd876390510e6 to your computer and use it in GitHub Desktop.
Save x0rnn/fcd73d95c894a04cb91fd876390510e6 to your computer and use it in GitHub Desktop.
#q2/et save/load position feature
#usage: bind key say !savepos, bind key say !loadpos
import minqlx
HASTE = ("df_handbreaker4", "handbreaker4_long", "handbreaker", "df_piyofunjumps", "df_verihard", "insane1",
"df_luna", "df_nodown", "df_etleague", "df_extremepkr", "labyrinth", "airmaxjumps",
"sarcasmjump", "criclejump", "cursed_temple", "skacharohuth", "randommap", "just_jump_3",
"criclejump", "eatme", "funjumpsmap", "bounce", "just_jump_2", "wernerjump")
class saveload(minqlx.Plugin):
def __init__(self):
self.add_hook("stats", self.handle_stats)
self.add_hook("player_spawn", self.handle_player_spawn)
self.add_hook("player_disconnect", self.handle_player_disconnect)
self.add_hook("player_loaded", self.player_loaded)
self.add_command("savepos", self.cmd_savepos)
self.add_command("loadpos", self.cmd_loadpos)
# dict of players which have used !goto, !savepos or !loadpos.
self.goto = {} # {steam_id: score}
self.savepos = {} # {steam_id: player.state.position}
self.loadpos = {} # {steam_id: score}
def handle_stats(self, stats):
"""Resets a player's score if they used !goto or !loadpos."""
if stats["TYPE"] == "PLAYER_RACECOMPLETE":
steam_id = int(stats["DATA"]["STEAM_ID"])
if steam_id in self.goto:
player = self.player(steam_id)
player.score = self.goto[steam_id]
player.tell("^6Your time does not count because you used !goto.")
elif steam_id in self.loadpos:
player = self.player(steam_id)
player.score = self.loadpos[steam_id]
player.tell("^6Your time does not count because you used !loadpos.")
def handle_player_spawn(self, player):
"""Removes player from goto & loadpos dicts when they spawn."""
try:
del self.goto[player.steam_id]
del self.loadpos[player.steam_id]
except KeyError:
return
def handle_player_disconnect(self, player, reason):
"""Removes player from goto, savepos and loadpos dicts when they disconnect."""
try:
del self.goto[player.steam_id]
del self.savepos[player.steam_id]
del self.loadpos[player.steam_id]
except KeyError:
return
def player_loaded(self, player):
"""Removes player from savepos dict on new map"""
try:
del self.savepos[player.steam_id]
except KeyError:
return
def cmd_savepos(self, player, msg, channel):
if player.team != "spectator":
# add player to savepos dict
self.savepos[player.steam_id] = player.state.position
player.tell("^6Saved. Your time won't count if you use !loadpos, unless you kill yourself.")
else:
player.tell("Can't save position as spectator.")
return minqlx.RET_STOP_ALL
def cmd_loadpos(self, player, msg, channel):
if player.team != "spectator":
if player.steam_id in self.savepos:
minqlx.player_spawn(player.id) #respawn player so he can't cheat
# add player to loadpos dict
self.loadpos[player.steam_id] = player.score
position=self.savepos[player.steam_id]
player.position(x=position[0], y=position[1], z=position[2])
if self.game.map.lower() in HASTE:
player.powerups(haste=999)
if self.game.map.lower() == "kraglejump":
player.powerups(haste=60) #some stages need haste and some don't, so 60 is a compromise...
else:
player.tell("^1You have to save your position first.")
else:
player.tell("Can't load position as spectator.")
return minqlx.RET_STOP_ALL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment