-
Notifications
You must be signed in to change notification settings - Fork 4
/
specs.py
74 lines (65 loc) · 3.04 KB
/
specs.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
#specs.py by x0rnn to list players spectating you and to check who someone is spectating
#!specs: show players spectating you
#!specwho <id>: show who <id> is spectating
#!specall: show who every spectator is spectating
import minqlx
class specs(minqlx.Plugin):
def __init__(self):
self.add_command("specs", self.cmd_specs)
self.add_command("specwho", self.cmd_specwho, usage="<id>")
self.add_command("specall", self.cmd_specall)
self.match = False
def cmd_specs(self, player, msg, channel):
if player.team == "spectator":
player.tell("You must join the game first to use this command.")
else:
player.tell(", ".join([p.name for p in self.teams()["spectator"] if p.state.position == player.state.position]))
return minqlx.RET_STOP_ALL
def cmd_specwho(self, player, msg, channel):
if len(msg) < 2:
return minqlx.RET_USAGE
try:
ident = int(msg[1])
target_player = None
if 0 <= ident < 64:
target_player = self.player(ident)
ident = target_player.steam_id
except ValueError:
channel.reply("No player with that ID.")
return
except minqlx.NonexistentPlayerError:
channel.reply("Invalid client ID.")
return
if target_player.team == "spectator":
for pl in self.players():
if pl.team != "spectator":
specx = int(target_player.state.position.x)
specy = int(target_player.state.position.y)
specz = int(target_player.state.position.z)
playerx = int(pl.state.position.x)
playery = int(pl.state.position.y)
playerz = int(pl.state.position.z)
if abs(specx - playerx) < 20 and abs(specy - playery) < 20 and abs(specz - playerz) < 20:
self.match = True
name = pl.name
if self.match:
player.tell("{} is spectating {}".format(target_player.name, name))
self.match = False
else:
player.tell("{} is not spectating anyone.".format(target_player.name))
else:
player.tell("{} is not a spectator.".format(target_player.name))
return minqlx.RET_STOP_ALL
def cmd_specall(self, player, msg, channel):
for p in self.teams()["spectator"]:
specx = int(p.state.position.x)
specy = int(p.state.position.y)
specz = int(p.state.position.z)
for pl in self.players():
if pl.team != "spectator":
playerx = int(pl.state.position.x)
playery = int(pl.state.position.y)
playerz = int(pl.state.position.z)
if abs(specx - playerx) < 20 and abs(specy - playery) < 20 and abs(specz - playerz) < 20:
player.tell("{} is spectating {}".format(p.name, pl.name))
return minqlx.RET_STOP_ALL