giants-stupid-server/plugins/instagib.py

60 lines
1.8 KiB
Python

from dpnet.packet import Packet
from dpnet.gamepackets import *
from random import randint
class Instagib:
def __init__(self, server):
self.server = server
async def on_player_spawn(self, player):
await self.server.broadcast_message("%s has spawned" % player.name)
# random teleport
await self.random_teleport(player)
# give stuff
await self.give_stuff(player)
async def on_player_respawn(self, player):
await self.server.broadcast_message("%s has respawned" % player.name)
# random teleport
await self.random_teleport(player)
# give stuff
await self.give_stuff(player)
async def on_player_shoot(self, player):
await self.spawn_sniper(player)
async def on_player_hit(self, player, shooter, damage, weapon):
# make player die
await self.server.broadcast_gamedata(MSG_PLAYER_DIE(player, 1))
async def give_stuff(self, player):
# remove current weapon
await self.remove_current_weapon(player)
# add sniper
await self.spawn_sniper(player)
async def spawn_sniper(self, player):
await self.server.broadcast_gamedata(MSG_DROP_WEAPON(player, self.server._nextid, 6, 255).to_packet())
self.server._nextid += 1
async def remove_current_weapon(self, player):
await self.server.broadcast_gamedata(MSG_SWITCH_WEAPON(player, 0xff).to_packet())
async def random_teleport(self, player):
# random teleport
maxdist = 300
x = randint(-(maxdist/2), maxdist/2)
y = randint(-(maxdist/2), maxdist/2)
z = randint(-(maxdist/2), maxdist/2)
await self.server.broadcast_gamedata(MSG_PLAYER_TELEPORT(player, x, y, z).to_packet())
def setup(server):
plugin = Instagib(server)
server.add_plugin(plugin)