If anyone wants a gamemode, script or other python program creating, please post them below.
Of course all credit for ideas and initial design will stay yours
TO DO LIST
Spoiler:
| | | | | | | | | |
V V V V V V V V V V
Ninja_pig_pro wrote:I have some stuff I need fixed in my script thread;can you elaborate? What should the scripts do
I would like the fix "Survivor.py" and "game1.py"
Ninja_pig_pro wrote:Survivor script atm was only supposed to send you to a area when you die.OK... But I got it completely working how I think it should: It locks one team, allows teamkilling, and still increases the score if killed. Here is the fixed script BTW it IS now a gamemode, so you can put it in gamemode instead of scripts in config.txt
# Free for all script written by Yourself
# With scripts from: Jail.py and arena.py
# And btw I doubt this works; Ninja Pig
# fixed by thepolm3
from random import randint
from twisted.internet.reactor import callLater
from pyspades.common import to_coordinates, coordinates
from commands import add, admin, get_player, join_arguments, name, alias, get_team
from pyspades.constants import *
jail_location = 0, 0, 0 # x, y, z of the spectator room
jail_coords = [ ] # e.g. ["B4", "B5"]
# If ALWAYS_ENABLED is False, free for all can still be enabled in the map
# metadata by setting the key 'free_for_all' to True in the extensions dictionary
ALWAYS_ENABLED = True
# If WATER_SPANS is True, then players can spawn in water
WATER_SPAWNS = False
HIDE_POS = (0, 0, 63)
def apply_script(protocol, connection, config):
class SurvivorProtocol(protocol):
game_mode=CTF_MODE
free_for_all=None
def on_map_change(self, map):
extensions = self.map_info.extensions
if ALWAYS_ENABLED:
self.free_for_all = True
else:
if extensions.has_key('free_for_all'):
self.free_for_all = extensions['free_for_all']
else:
self.free_for_all = False
if self.free_for_all:
self.friendly_fire = True
return protocol.on_map_change(self, map)
def on_base_spawn(self, x, y, z, base, entity_id):
if self.free_for_all:
return HIDE_POS
return protocol.on_base_spawn(self, x, y, z, base, entity_id)
def on_flag_spawn(self, x, y, z, flag, entity_id):
if self.free_for_all:
return HIDE_POS
return protocol.on_flag_spawn(self, x, y, z, flag, entity_id)
class SurvivorConnection(connection):
score_hack = False
def on_spawn_location(self, pos):
if not self.score_hack and self.protocol.free_for_all:
while True:
x = randint(0, 511)
y = randint(0, 511)
z = self.protocol.map.get_z(x, y)
if z != 63 or WATER_SPAWNS:
break
# Magic numbers taken from server.py spawn function
z -= 2.4
x += 0.5
y += 0.5
return (x, y, z)
return connection.on_spawn_location(self, pos)
def on_connect(self):
if self.protocol.free_for_all and not get_team(self, "green").locked:
get_team(self, "green").locked = True
return connection.on_connect(self)
def on_refill(self):
if self.protocol.free_for_all:
return False
return connection.on_refill(self)
def on_flag_take(self):
if self.protocol.free_for_all:
return False
return connection.on_flag_take(self)
def on_kill(self, by, type, grenade):
# Switch teams to add score hack
if by is not None and by.team is self.team and self is not by:
self.switch_team()
a=callLater(0.01,self.switch_team)
return connection.on_kill(self, by, type, grenade)
def switch_team(self):
pos = self.world_object.position
self.set_team(self.team.other)
self.spawn((pos.x, pos.y, pos.z))
return SurvivorProtocol, SurvivorConnection
"""
Jail script by PXYC
Edited by Ninja Pig
Fixed by thepolm3
"""
from pyspades.common import to_coordinates, coordinates
from commands import add, admin, get_player, join_arguments, name, alias
from pyspades.constants import *
jail_location = 0, 0, 0 # Location of game1
jail_coords = [] # e.g. ["B4", "B5"]
jail_list = []
@name('game')
@alias('g')
@admin
def game1_player(connection, value = None, *args):
protocol = connection.protocol # Meh
if not value:
value=connection.name
try:
player = get_player(protocol, value) # Get player
except Exception:
return "Invalid player"
else:
if player.jailed:
return 'Player ' + player.name + ' Already ingame!' # Player is already jailed!
elif not player.jailed:
player.jailed = True # Set player to jailed
if not args:
reason = player.reason = "no reason"
else:
reason = player.reason = join_arguments(*args)
try:
player.squad = None
player.squad_pref = None
except Exception:
pass #if squads are not enabled
player.set_location(jail_location) # Move player to jail
connection.protocol.send_chat("%s has joined game 1!" % (player.name)) # Message
connection.protocol.irc_say("* %s joined game 1" % (player.name)) # Message
jail_list.append(player.name)
@name('game1')
def is_jailed(connection, value = None):
if value is None:
if not jail_list:
return 'No players.'
else:
return " players: " + ", ".join(jail_list)
elif value is not None:
protocol = connection.protocol
try:
player = get_player(protocol, value or connection) # Get player
except Exception:
return "Invalid player"
else:
if player.jailed:
return 'Player %s is playing game 1' % (player.name)
else:
return 'Player %s is not playing.' % (player.name)
@name('quit')
@admin
def quit_from_game(connection, value=None):
protocol = connection.protocol # Meh
if not value:
value=connection.name
try:
player = get_player(protocol, value) # Get player
except Exception:
return "Invalid player"
if player not in protocol.players:
raise ValueError() # Errors again
else:
if not player.jailed: # If player isn't jailed
return 'Player ' + player.name + ' is not ingame!' # Message
elif player.jailed: # If player is jailed
player.jailed = False # Player is not jailed anymore
player.reason=None
player.kill() # Kill the player
connection.protocol.send_chat("%s quit the game 1" % (player.name)) # Message
connection.protocol.irc_say('* %s has left game 1' % (player.name)) # Message
jail_list.remove(player.name)
add(game1_player)
add(quit_from_game)
add(is_jailed)
def apply_script(protocol,connection,config):
class GameOneConnection(connection):
jailed=False
reason=None
def on_disconnect(self):
if self.jailed:
jail_list.remove(self.name)
self.jailed = False
return connection.on_disconnect(self)
return protocol, GameOneConnection
TB_ wrote:Wait, so the survivor gamemode that I suggested earlier works now?! :DYeah, he used the script to finish up the whole gamemode! :D I await for a server to come up!
TB_ wrote:Tournament modeI'll get right on it :D
"""
Tournament mode by thepolm3
Idea by TB_
"""
from commands import add, admin, get_player, join_arguments, name, alias, get_team
from pyspades.constants import *
from random import randint
from twisted.internet.reactor import callLater
HIDE_COORD = (0, 0, 63)
HIDE_COORD2 = (511, 511, 63)
BUILDING_ENABLED = False
MAX_SPAWN_DISTANCE=5
def apply_script(protocol,connection,config):
class TournamentConnection(connection):
tournament_id=None
myroundended=False
opponant=None
def on_spawn_location(self, pos):
if self.protocol.tournament_enabled:
prot=self.protocol
if self.tournament_id%2==1:
callLater(1,self.match)
else:
self.send_chat("Please wait until an opponant arrives")
if self.myroundended and prot.round_active:
self.opponant=prot.tournament_players[self.tournament_id-1]
self.opponant.opponant=self
self.send_chat("You have been matched against %s Fight to the death!" %(self.opponant.name))
self.opponant.send_chat("You have been matched against %s Fight to the death!" %(self.name))
return HIDE_COORD2
else:
if not prot.round_active:
self.myroundended=False
x,y,z = prot.spawns[self.tournament_id]
return(x,y,z)
return connection.on_spawnlocation(self,pos)
def on_kill(self, killer, type, grenade):
if self.protocol.tournament_enabled:
if killer!=None and killer!=self:
if self.opponant==killer and self.protocol.round_active and not self.myroundended:
killer.send_chat("You won this round!")
self.myroundended=True
killer.myroundended=True
self.send_chat("Sorry, you died. wait until the end of the round to play again")
killer.kill()
self.protocol.check_end()
self.switch_team()
a=callLater(0.01,self.switch_team)
return connection.on_kill(self,killer,type,grenade)
else:
if killer.opponant==None:
killer.send_chat("Wait for your opponant to arrive!")
elif not self.protocol.round_active:
killer.send_chat("not yet!")
else:
killer.send_chat("Shoot %s, not %s!" %(killer.opponant.name,self.name))
return False
return connection.on_kill(self,killer,type,grenade)
def switch_team(self):
self.set_team(self.team.other)
self.spawn()
def on_position_update(self):
prot=self.protocol
if prot.tournament_enabled:
if self.opponant==None or not prot.round_active:
pos = self.world_object.position
x,y,z=prot.spawns[self.tournament_id]
xd = x - pos.x
yd = y - pos.y
zd = z - pos.z
if (xd ** 2 + yd ** 2 + zd ** 2)**0.5 > MAX_SPAWN_DISTANCE:
self.set_location(prot.spawns[self.tournament_id])
if self.opponant==None:
self.send_chat("Wait for your opponant to arrive!")
return connection.on_position_update(self)
def on_connect(self):
prot=self.protocol
if prot.tournament_enabled:
get_team(self, "green").locked = True
self.tournament_id = len(prot.tournament_players)
prot.tournament_players.append(self)
return connection.on_connect(self)
def on_disconnect(self):
prot=self.protocol
if prot.tournament_enabled:
self.myroundended=False
del(prot.tournament_players[self.tournament_id])
self.tournament_id=None
if self.opponant:
self.opponant.send_chat("%s has disconnected and forfeight. Prove yourself next game!"%(self.name))
self.opponant.opponant=None
self.opponant=None
return connection.on_disconnect(self)
class TournamentProtocol(protocol):
game_mode=CTF_MODE
tournament_enabled = False
spawns=[]
olds=[]
tournament_players=[]
round_active=False
gamesfinished=0
def on_map_change(self, map):
extensions = self.map_info.extensions
if config.get("game_mode","ctf")=="tournament" or extensions.has_key('tournament'):
self.tournament_enabled = True
self.olds = [self.respawn_time,self.building,self.friendly_fire,self.max_players]
self.respawn_time = 0
self.building = BUILDING_ENABLED
self.friendly_fire = True
if extensions.has_key('tournament'):
try:
for i in extensions["tournament"]: #setting spawns
self.spawns.append(i)
self.max_players=len(self.spawns)
except Exception:
raise "Tournament defined incorrectly in map meta data, use format tournament:[(spawn1),(spawn2),(spawn3)] etc"
else:
raise Exception("No extentions")
self.send_chat("The round will begin in 10 seconds")
a=callLater(10,self.begin_round)
else:
# Cleanup after a map change
self.tournament_enabled=False
if self.olds:
self.respawn_time,self.building,self.friendly_fire,self.max_players=self.olds
self.olds=[]
return protocol.on_map_change(self,map)
def check_end(self):
self.gamesfinished+=1
if self.gamesfinished>=int(len(self.tournament_players)/2):
self.end_round()
self.send_chat("Round finished")
def end_round(self):
self.gamesfinished=0
tournament_players=self.tournament_players
length = len(tournament_players) - 1
sorted = False
while not sorted:
sorted = True
for i in range(length):
if tournament_players[i].kills > tournament_players[i+1].kills:
sorted = False
tournament_players[i], tournament_players[i+1] = tournament_players[i+1], tournament_players[i]
for player in tournament_players:
player.tournament_id=tournament_players.index(player)
player.kill()
player.myroundended=False
player.opponant=None
self.send_chat("The round will begin in 5 seconds")
self.round_active=False
a=callLater(10,self.begin_round)
def begin_round(self):
if len(self.tournament_players)>1:
self.round_active=True
self.send_chat("Begin killing!")
else:
self.send_chat("Not enough players. The round will begin in 10 seconds")
a=callLater(10,self.begin_round)
def on_flag_spawn(self, x, y, z, flag, entity_id):
if not self.tournament_enabled:
return protocol.on_base_spawn(self, x, y, z, flag, entity_id)
return HIDE_COORD
def on_base_spawn(self, x, y, z, base, entity_id):
if not self.tournament_enabled:
return protocol.on_base_spawn(self, x, y, z, base, entity_id)
return HIDE_COORD
return TournamentProtocol, TournamentConnection
Users browsing this forum: No registered users and 15 guests