40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
# cap health at the spawn health. Vampire healing in QL goes up to 2x max health
|
|
# (g_startingHealth 200 let players reach 400) and there is no cvar for a vampire cap,
|
|
# so every server frame any living player above the cap is set back to it.
|
|
# Cap = qlx_healthCap if > 0, else g_startingHealth (200 on lgvamp, 100 on lgvamp100).
|
|
import minqlx
|
|
|
|
REREAD_FRAMES = 40 # re-read the cvars about once a second (sv_fps 40)
|
|
|
|
|
|
def to_int(value):
|
|
try:
|
|
return int(float(value))
|
|
except (TypeError, ValueError):
|
|
return 0
|
|
|
|
|
|
class healthcap(minqlx.Plugin):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.set_cvar_once("qlx_healthCap", "0")
|
|
self.cap = 0
|
|
self.frames = 0
|
|
self.add_hook("frame", self.handle_frame)
|
|
self.read_cap()
|
|
self.logger.info("healthcap loaded: cap %d", self.cap)
|
|
|
|
def read_cap(self):
|
|
self.cap = to_int(self.get_cvar("qlx_healthCap")) or to_int(self.get_cvar("g_startingHealth"))
|
|
|
|
def handle_frame(self):
|
|
self.frames += 1
|
|
if self.frames >= REREAD_FRAMES:
|
|
self.frames = 0
|
|
self.read_cap()
|
|
if self.cap <= 0:
|
|
return
|
|
for p in self.players():
|
|
if p.is_alive and p.health > self.cap:
|
|
p.health = self.cap
|