[bf1942] autobalance system
[LG] pAnpAn
panpan at legion-etrangere.net
Mon Jul 4 14:08:23 EDT 2005
Hey, very nice one :)
Is there a similar way to dont autobalance people from a same team.... seems to be hard to be hard to do... but at least to check for one particular team ? with other words, is there a check on the player name ? like " if p.Name = "=SAS=*" return none ".
Cheers
pAnpAn
----- Original Message -----
From: Giel van Schijndel
To: bf1942 icculus
Sent: Monday, July 04, 2005 11:00 AM
Subject: [bf1942] autobalance system
I've modified the autobalance.py script because it kinda pissed me off after being switched for the third time while being a commander.
I have simply added these lines in the onPlayerDeath() routine:
These lines should ensure that the Commander and Squad Leader will NOT be switched anymore.
# [Modification] This tiny piece of code added makes sure that the Commander and Squad Leader are immune for being teamswitched.
if p.isCommander():
return None
if p.isSquadLeader():
return None
# [/Modification]
cheers,
--
Mortis - Webadmin and Game Server admin
European Tactical Battlefield Forces
------------------------------------------------------------------------------
# team autobalance system
import bf2
import host
from bf2 import g_debug
def init():
if g_debug: print 'initializing autobalance script'
host.registerHandler('PlayerConnect', onPlayerConnect)
host.registerHandler('PlayerDeath', onPlayerDeath)
host.registerHandler('PlayerChangeTeams', onPlayerChangeTeams)
def onPlayerConnect(p):
# if not bf2.serverSettings.getAutoBalanceTeam(): return None
if g_debug: print 'place player on the team with least players'
team1 = 0
team2 = 0
for tp in bf2.playerManager.getPlayers():
if tp != p:
if tp.getTeam() == 1: team1 += 1
else: team2 += 1
team2 = team2 * bf2.serverSettings.getTeamRatioPercent() / 100.0
if team2 > team1:
p.setTeam(1)
else:
p.setTeam(2)
def onPlayerDeath(p, vehicle):
if not bf2.serverSettings.getAutoBalanceTeam(): return None
if g_debug: print 'handling player death autobalance'
# dont use autobalance when its suicide/changes team
if p.getSuicide():
p.setSuicide(0)
return None
# [Modification] This tiny piece of code added makes sure that the Commander and Squad Leader are immune for being teamswitched.
if p.isCommander():
return None
if p.isSquadLeader():
return None
# [/Modification]
aiPlayerBalance = 0
team1 = 0
team2 = 0
for tp in bf2.playerManager.getPlayers():
if tp.getTeam() == 1:
team1 += 1
else:
team2 += 1
if tp.isAIPlayer():
aiPlayerBalance += 1
else:
aiPlayerBalance -= 1
if host.sgl_getIsAIGame():
if not (aiPlayerBalance < 0):
if not p.isAIPlayer():
return None
team2 = team2 * bf2.serverSettings.getTeamRatioPercent() / 100.0
if g_debug: print 'team1 %f team2 %f' % (team1,team2)
if (p.getTeam() == 1):
if (team2+1) < team1:
p.setTeam(2)
elif (p.getTeam() == 2):
if (team1+1) < team2:
p.setTeam(1)
def onPlayerChangeTeams(p, humanHasSpawned):
if not bf2.serverSettings.getAutoBalanceTeam(): return None
if host.sgl_getIsAIGame():
if humanHasSpawned: return None
if p.isAIPlayer(): return None
if g_debug: print 'handling aiplayer team change autobalance when round not started'
team = p.getTeam()
aiplayer = 0
for tp in bf2.playerManager.getPlayers():
if aiplayer == 0 and tp.getTeam() == team and tp.isAIPlayer():
aiplayer = tp
break
if aiplayer:
if p.getTeam() == 1: aiplayer.setTeam(2)
else: aiplayer.setTeam(1)
else:
if g_debug: print 'checking to see if player is allowed to change teams'
team1 = 0
team2 = 0
for tp in bf2.playerManager.getPlayers():
if tp.getTeam() == 1: team1 += 1
else: team2 += 1
if abs(team1 - team2) > 1:
if p.getTeam() == 1: p.setTeam(2)
else: p.setTeam(1)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://icculus.org/pipermail/bf1942/attachments/20050704/793acf3e/attachment.htm>
More information about the Bf1942
mailing list