I'm struggling to find a way to create a spawnpoint list, and then randomly choose a spawnpoint that no player has spawned in yet. See the screenshot below...
The code for the spawnpoints: here
And for the admin menu: here
Following things work:
- loading the <mapname>.txt file (parsing it from JSON list to Vector instances)
- saving the <mapname>.txt file (parsing it from Vector instances to JSON lists)
- Adding, removing and teleporting to vectors through the Admin menu
Contents of the dynamically saved spawnpoints file:
Code: Select all
[[-1663.1475830078125, 779.1383056640625, 32.03125], [-1922.8316650390625, 1980.5145263671875, 9.888980865478516], [-957.9427490234375, 2230.0693359375, -57.30064010620117], [-479.4043273925781, 1868.709716796875, -127.12945556640625], [-414.70361328125, 666.8245849609375, 3.628751039505005], [378.34857177734375, 25.55403709411621, 8.529182434082031], [1775.96875, 987.219482421875, 128.03125], [1670.6195068359375, 369.1476745605469, 64.03125], [1713.1978759765625, 1822.50537109375, 48.798667907714844]]
Actually and randomly choosing an empty spawnpoint however does not work, code:
Syntax: Select all
from random.choice import random_choice
from flashfunsp.spawnpoints import spawnpoints
from flashfunsp.spawnpoints import VECTOR_DISTANCE
class Player(PlayerEntity):
""" Adds features needed by this script to PlayerEntity """
def __init__(self, index):
"""
Instance initlaization
"""
# call PlayerEntity's __init__()
super(Player, self).__init__()
# ....
def teleport(self):
"""
Teleports the player to a random spawnpoint.
"""
possible = list()
for player in playeriter_alive:
for vector in filter(lambda x: x not in possible and x.get_distance(player.origin) > VECTOR_DISTANCE, spawnpoints):
possible.append(vector)
if possible:
self.origin = random_choice(possible)
def player_spawn(game_event):
player = Player(index_from_userid(game_event.get_int("userid")))
if not player.get_property_int("pl.deadflag") and player.team > 1:
player.teleport() # players just get "glued together"....