PiratePlunder 0 Report post Posted August 14, 2008 I couldn't find a simple way of doing it, compared to just picking a random player irrespective of team, this seems much harder. Thought that this would do it, basically create an empty array, go through all players and add the index number of any players that are alive and in the correct team to the array. Then just pull a random index out of that array and grab the corresponding player. The random bits work as i've copied them from another part of our gamemode, i also know through debugging that its working through to the if index >0 and its entering there, so the player indexes are being added to the array (although i've not tested with more than 1 player). So im thinking its falling over when pulling the playerbyindex, maybe because of the array? peglegPlayerList = {} index = 0 #go through all alive players and grab pegleg players for p in bf2.playerManager.getPlayers(): if p.getTeam() == 1: #we only want players from team1 if p.isAlive() and not p.isManDown(): peglegPlayerList[index] = p.index index += 1 #pick a random player from the array if index > 0: peglegPlayerIndex = random.randint(-1, index-1) peglegPlayer = bf2.playerManager.getPlayerByIndex(peglegPlayerList[peglegPlayerIndex]) prnt("Player Picked" + str(peglegPlayer.getName()) ) Quote Share this post Link to post Share on other sites
[FH]ctz 0 Report post Posted August 14, 2008 (edited) one line solution (expand to make more readable at your leisure ) randomplayer = random.choice([p for p in bf2.playerManager.getPlayers() if p.getTeam() == 1 and p.isAlive() and not p.isManDown()]) whoops, fixed Edited August 14, 2008 by [FH]ctz Quote Share this post Link to post Share on other sites
PiratePlunder 0 Report post Posted August 14, 2008 You are joking right - it cant be that simple. Wow, many thanks. Quote Share this post Link to post Share on other sites
1/2Hawk 0 Report post Posted August 14, 2008 Are you sure we cant slide into FH2's harbor one night, steal their booty, put hickeys on their fair damsels, and pressgang ctz into service for our mod? That would be more pirately than all this typing. LOL Quote Share this post Link to post Share on other sites
PiratePlunder 0 Report post Posted August 15, 2008 LOL 1/2 if only we could. Im guessing that, like other mods, their list of fair damsels will be quite a short one. Besides, we've got in trouble for doing that sort of thing before - of course before either of us was on board though. Quote Share this post Link to post Share on other sites