-
Notifications
You must be signed in to change notification settings - Fork 9
/
gauntonly.py
209 lines (174 loc) · 8.15 KB
/
gauntonly.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# This is a plugin written by iouonegirl(@gmail.com) and Gelenkbusfahrer
# Copyright (c) 2016 iouonegirl, Gelenkbusfahrer
# https://github.com/dsverdlo/minqlx-plugins
#
# You are free to modify this plugin to your custom,
# except for the version command related code.
#
# The idea for this plugin comes from Gelenkbusfahrer
# and has been discussed on station.boards.net.
# Home forum of the Bus Station server.
#
# This plugin detects when a last standing player is
# facing more than [MAX] opponents and will disable all
# weapons until there are only [MIN] players left standing.
#
# Round based modes only
# Uses
# - set qlx_gaunt_max "4"
# - set qlx_gaunt_min "2" Invulnerability
import minqlx
import datetime
import time
import os
import re
import requests
import random
VERSION = "v0.3"
# This code makes sure the required superclass is loaded automatically
try:
from .iouonegirl import iouonegirlPlugin
except:
try:
abs_file_path = os.path.join(os.path.dirname(__file__), "iouonegirl.py")
res = requests.get("https://raw.githubusercontent.com/dsverdlo/minqlx-plugins/master/iouonegirl.py")
if res.status_code != requests.codes.ok: raise
with open(abs_file_path,"a+") as f: f.write(res.text)
from .iouonegirl import iouonegirlPlugin
except Exception as e :
minqlx.CHAT_CHANNEL.reply("^1iouonegirl abstract plugin download failed^7: {}".format(e))
raise
class gauntonly(iouonegirlPlugin):
def __init__(self):
super().__init__(self.__class__.__name__, VERSION)
self.set_cvar_once("qlx_gaunt_min", "2")
self.set_cvar_once("qlx_gaunt_max", "4")
self.add_hook("death", self.handle_death)
self.add_hook("team_switch", self.handle_switch)
self.add_hook("round_end", self.handle_round_end)
self.min_opp = self.get_cvar("qlx_gaunt_min", int)
self.max_opp = self.get_cvar("qlx_gaunt_max", int)
self.gauntmode = False
self.weapons_taken = None
self.checkonce = True
self.blinking = False
def handle_switch(self, player, _old, _new):
# Somebody noob quits? Check if we need to switch modes
if self.checkonce: self.detect()
def handle_death(self, victim, killer, data):
# Some noob dies? Check if we need to switch modes
if self.checkonce: self.detect()
def handle_round_end(self, data):
# Round finally ended? Turn the mode off
self.gauntmode = False
self.checkonce = True
def detect(self):
# Not in a match? Do nothing
if not self.game: return
if self.game.roundlimit in [self.game.blue_score, self.game.red_score]: return
# Grab some info and put that stuff into variables for readability yo
teams = self.teams()
alive_r = list(filter(lambda p: p.is_alive, teams['red']))
alive_b = list(filter(lambda p: p.is_alive, teams['blue']))
#if self.gauntmode:
# if not (alive_r and alive_b):
# self.stop_sound()
# If we do not have a last standing, do nothing
if not 1 in [len(alive_r), len(alive_b)]: return
# If one team is completely dead, do nothing
if not (alive_r and alive_b):
return
# Ok things are getting more complicated, listen closely!
# If the gauntmode was active, and both teams have less than [MIN] players: TURN IT OFF
if len(alive_r) <= self.min_opp and len(alive_b) <= self.min_opp and self.gauntmode:
# Deactivate gaunt mode: take everyone's gauntlets, display warning and then restore weapons
self.gauntmode = False
for p in self.players(): # Take their gauntlet away and switch to empty
p.weapons(g=False, mg=False, sg=False, gl=False, rl=False, lg=False, rg=False, pg=False, bfg=False, gh=False, ng=False, pl=False, cg=False, hmg=False, hands=False)
p.weapon(15)
# Countdown will display messages and then restore the weapons
r = "^3Restoring weapons in "
self.countdown([r+"5", r+"4", r+"3", r+"2", r+"1", "^2FIGHT!"])
return
# If we were not in gaunt mode yet, check if we have enough opponents.
# Remember at least one team has 1 player; add the teams and subtract one
if (not self.gauntmode) and self.game.state == "in_progress" and len(alive_b + alive_r[1:]) > self.max_opp:
if self.checkonce:
# Compare healths+armors and decide if last standing had a chance winning. If there's a good chance, this doesn't gonna be a pummel round.
if len(alive_r) > len(alive_b):
calc_opp = alive_r
ha_last = alive_b[0].health + alive_b[0].armor
else:
calc_opp = alive_b
ha_last = alive_r[0].health + alive_r[0].armor
ha_opp_total = 0
for p in calc_opp:
ha_opp_total += p.health + p.armor
ha_required = 1000*(ha_last/300)/1.43+300
p_amount = len(alive_b + alive_r[1:])
if p_amount == 5: chance = 10
elif p_amount == 6: chance = 20
elif p_amount == 7: chance = 40
else: chance = 100
if random.randint(1,100) > chance or ha_opp_total < ha_required:
self.checkonce = False
return
self.gauntmode = True
self.weapons_taken = self.weapons_taken or alive_r[0].weapons()
for p in self.players():
p.weapons(g=False, mg=False, sg=False, gl=False, rl=False, lg=False, rg=False, pg=False, bfg=False, gh=False, ng=False, pl=False, cg=False, hmg=False, hands=False)
p.weapon(15)
self.blink(["Prepare your pummel!", ""] * 9 + ["^2{}vs{} - Go pummeling!".format(len(alive_r), len(alive_b))])
self.blinking = True
self.msg("^7Pummel showdown! Weapons will be restored when ^3{}^7 players are left standing.".format(self.min_opp+1))
return
# If we didn't have to turn the gauntmode ON, and not OFF,
# it will be the case someone died or changed teams
if self.gauntmode and not self.blinking:
self.msg("^7Pummel showdown! Gaunt ^3{}^7 more enemies to restore weapons".format(len(alive_b+alive_r)-1-self.min_opp))
# Let's make some noise
d = random.randint(1, 3)
self.play_sound("sound/vo/humiliation{}".format(d))
if len(alive_r) > len(alive_b):
self.blink2((["{} Reds left!".format(len(alive_r))] + [""]) * 6)
else:
self.blink2((["{} Blues left!".format(len(alive_b))] + [""]) * 6)
@minqlx.thread
def blink(self, messages, interval = .12):
@minqlx.next_frame
def logic(_m): self.center_print("^3{}".format(_m))
@minqlx.next_frame
def setgaunt(_p):
_p.weapons(g=True, mg=False, sg=False, gl=False, rl=False, lg=False, rg=False, pg=False, bfg=False, gh=False, ng=False, pl=False, cg=False, hmg=False, hands=True)
_p.weapon(1)
_p.powerups(haste=30)
# First centerprint all the messages
for m in messages:
logic(m)
time.sleep(interval)
# Then change the weapons to gauntlet
for p in self.players():
setgaunt(p)
self.play_sound("sound/vo_evil/go")
self.blinking = False
@minqlx.thread
def blink2(self, messages, interval = .12):
@minqlx.next_frame
def logic(_m): self.center_print("^3{}".format(_m))
for m in messages:
logic(m)
time.sleep(interval)
@minqlx.thread
def countdown(self, messages, interval = 1):
@minqlx.next_frame
def logic(_m): self.center_print("^3{}".format(_m))
@minqlx.next_frame
def setweap(_p): minqlx.set_weapons(_p.id, self.weapons_taken or _p.weapons())
# First centerprint to warn players
for m in messages:
time.sleep(interval)
logic(m)
# Then restore their weapons
for p in self.players():
setweap(p)
self.play_sound("sound/vo_evil/fight")