-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteleport.py
190 lines (164 loc) · 8.48 KB
/
teleport.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
'''
This is an open source remake for the script hookshot.py by Mr.Morphman.
It was written completely from scratch.
Feel free to contribute!
LICENSE: BSD-3 (do what you want with it).
This version is made for Piqueserver.
'''
from pyspades.constants import FALL_KILL
import time
from pyspades import world
from math import sqrt
from twisted.internet import reactor
from piqueserver.commands import command
@command('teleportdistance', 'td', admin_only=True)
def tpd(self, value):
try:
self.protocol.length = int(value)
if value == 0:
self.send_chat('Teleport feature successfully deactivated. Congratulations, spoilsport.')
else:
self.send_chat('Teleport distance set to '+str(self.protocol.length))
except:
self.send_chat("Oops! That didn't work. Try again!")
@command('teleportspeed', 'ts', admin_only=True)
def tpts(self, value):
try:
value=float(value)
if value > 0:
self.protocol.speed=1/value
self.send_chat('Teleport speed set to '+str(value)+' blocks per second')
elif value == 0:
self.send_chat('To deactivate teleport, set the teleport distance to zero.')
else:
self.send_chat('Positive people use positive numbers.')
except:
self.send_chat("Oops! That didn't work. Try again!")
@command('teleportcooldown','tc', admin_only=True)
def tpc(self, value):
try:
value=float(value)
self.protocol.cooldown = value
self.send_chat('Teleport cooldown time set to '+str(value))
except:
self.send_chat("Oops! That didn't work. Try again!")
def ff(player):
if player.allhisplannedstuff=={}:
player.unfallable = False
def set_pos(player, goal, pos):
blockdistance=round(sqrt((goal[0]-pos[0])**2 + (goal[1]-pos[1])**2 + (goal[2]-pos[2])**2))
blockdistance += 1
teleporttime=time.monotonic()
player.unfallable = True
player.makeunfallable[teleporttime]=reactor.callLater(player.protocol.speed*blockdistance+4, ff, player)
vectorx=(goal[0]-pos[0])/blockdistance
vectory=(goal[1]-pos[1])/blockdistance
vectorz=(goal[2]-pos[2])/blockdistance #noclipping during flight is intended
for i in range(1,blockdistance):
zzz=reactor.callLater(player.protocol.speed*(i), player.give_pos, (pos[0]+vectorx*i, pos[1]+vectory*i,pos[2]+vectorz*i), teleporttime, i)
player.allhisplannedstuff[teleporttime*i]=zzz
def apply_script(protocol, connection, config):
class teleportprotocol(protocol):
cooldown = 8
length = 120
speed=0.004
previouscooldown = cooldown
previouslength = length
def on_advance(self, *arg, **kw):
self.previouscooldown = self.cooldown
self.cooldown = 0 #this feature lets everyone teleport around in the end
self.previouslength = self.length
self.length = 300
def on_map_change(self, map):
for playerz in self.players.values():
for allkeys in playerz.allhisplannedstuff.keys():
if playerz.allhisplannedstuff[allkeys].active():
playerz.allhisplannedstuff[allkeys].cancel()
playerz.allhisplannedstuff={}
for unfallablekeys in playerz.makeunfallable.keys():
if playerz.makeunfallable[unfallablekeys].active():
playerz.makeunfallable[unfallablekeys].cancel()
playerz.makeunfallable={}
self.cooldown = self.previouscooldown
self.length = self.previouslength
return protocol.on_map_change(self, map)
class teleportconnection(connection):
unfallable = False
lastteleport = 0.0
allhisplannedstuff = {}
makeunfallable = {}
def give_pos(player, position, teleporttime, iterator):
if player is not None:
try:
if (position[0]>=0) and (position[0]<=511) and (position[1] >=0) and (position[1]<=511) and (position[2]>-5) and (position[2]<=63):
player.set_location(position)
player.allhisplannedstuff.pop(teleporttime*iterator)
except:
pass
def on_spawn(self, pos):
self.lastteleport=0.0 #reset on start
return connection.on_spawn(self, pos)
def on_fall(self, damage):
if self.unfallable:
if self.allhisplannedstuff == {}:
self.unfallable = False
for unfallablekeys in self.makeunfallable.keys():
if self.makeunfallable[unfallablekeys].active():
self.makeunfallable[unfallablekeys].cancel()
self.makeunfallable={}
return False
return connection.on_fall(self, damage)
def on_kill(self, killer, type, grenade):
for keys2 in self.allhisplannedstuff.keys():
if self.allhisplannedstuff[keys2].active():
self.allhisplannedstuff[keys2].cancel()
self.allhisplannedstuff={}
return connection.on_kill(self, killer, type, grenade)
def on_animation_update(self, jump, crouch, sneak, sprint):
if (((time.monotonic()-self.lastteleport) >= self.protocol.cooldown) or self.invisible) and sneak == True and not self.team.other.flag.player is self and self.world_object.cast_ray(self.protocol.length) is not None:
for unfallablekeys in self.makeunfallable.keys():
if self.makeunfallable[unfallablekeys].active():
self.makeunfallable[unfallablekeys].cancel()
self.makeunfallable={}
if self.world_object.velocity.z >= 0.58 and not self.god:
self.kill(self, FALL_KILL)
headpoints = world.cube_line(*(self.world_object.cast_ray(self.protocol.length)) + (self.world_object.position.get()))
nice=False
for headblocks in headpoints:
x1,y1,z1=headblocks
if self.protocol.map.get_solid(x1,y1,z1) == 0 and self.protocol.map.get_solid(x1,y1,z1 + 1) == 0 and self.protocol.map.get_solid(x1, y1, z1 + 2) == 0:
nice=True
set_pos(self, (x1,y1,z1+1), (self.world_object.position.get()))
break
elif self.protocol.map.get_solid(x1,y1,z1-1) == 0 and self.protocol.map.get_solid(x1,y1,z1) == 0 and self.protocol.map.get_solid(x1, y1, z1 + 1) == 0:
nice=True
set_pos(self, (x1,y1,z1), (self.world_object.position.get()))
break
elif self.protocol.map.get_solid(x1,y1,z1-2) == 0 and self.protocol.map.get_solid(x1,y1,z1-1 ) == 0 and self.protocol.map.get_solid(x1, y1, z1) == 0:
nice=True
set_pos(self, (x1,y1,z1-1), (self.world_object.position.get()))
break
elif (z1<=1) * (self.world_object.position.z<4):
nice=True
set_pos(self, (x1,y1,z1-2), (self.world_object.position.get()))
break
if nice == False: #emergency case
x1, y1, z1 = self.world_object.cast_ray(self.protocol.length)
x1, y1, z1 = int(x1), int(y1), int(z1)
for pos in self.protocol.pos_table:
if self.is_location_free(x1 + pos[0], y1 + pos[1], z1 + pos[2]):
set_pos(self, (x1 + pos[0],y1 + pos[1],z1 + pos[2]), (self.world_object.position.get()))
break
self.lastteleport=time.monotonic()
return connection.on_animation_update(self, jump, crouch, sneak, sprint)
def on_disconnect(self):
for allkeys in self.allhisplannedstuff.keys():
if self.allhisplannedstuff[allkeys].active():
self.allhisplannedstuff[allkeys].cancel()
self.allhisplannedstuff={}
for unfallablekeys in self.makeunfallable.keys():
if self.makeunfallable[unfallablekeys].active():
self.makeunfallable[unfallablekeys].cancel()
self.makeunfallable={}
connection.on_disconnect(self)
return teleportprotocol, teleportconnection