Scripts:ClanmemberBalance

From BF2 Technical Information Wiki
Revision as of 15:38, 22 June 2018 by Pireax (talk | contribs) (Created page with "__TOC__ == Short Description == '''Autobalance unleashed by Nexus2k:''' This Modification prevent Clanmembers/Commanders/Squadleaders and Squad Members from Autobalance and...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Short Description

Autobalance unleashed by Nexus2k:

This Modification prevent Clanmembers/Commanders/Squadleaders and Squad Members from Autobalance and additionally switchs Clanmembers to one Team on connect

Protect Clanmembers/Commander/Squadleader from Autobalance:

Open bf2/admin/standard_admin/autobalance.py with a texteditor Add at Line 7:

#Change this to your Clantag
clantag="Net.BS|" 

And add at Line 46, after:

if not bf2.serverSettings.getAutoBalanceTeam(): return 

this:

        # Prevent Clanmembers from Autobalancing
        name=p.getName()
        if name.find(clantag)>-1: return None
       
        # Squadleader/Commander prevent from Change
        if p.isCommander(): return None
        if p.isSquadLeader(): return None

--Nexus2k 05:46, 18 Jul 2005 (MDT)

Additions

For more than one Clan Tag:

Modifiy the clantag variable: from:

#Change this to your Clantag
clantag="Net.BS|"

to

#Insert here your Clantags
clantags=["Net.BS|","|CSAR|"]

and from:

# Prevent Clanmembers from Autobalancing
name=p.getName()
if name.find(clantag)>-1: return None

to

# Prevent Clanmembers from Autobalancing
name=p.getName()
for clantag in clantags:
 if name.find(clantag)>-1: return None

Squadmemberautobalanceprotection:

(From ~RIP~Brian on http://bf1942.lightcubed.com/forum/viewtopic.php?p=14370#14370) add after this section :

# Prevent Clanmembers from Autobalancing
        name=p.getName()

        if name.find(clantag)>-1: return None
        # Squadleader/Commander prevent from Change
        if p.isCommander(): return None if p.isSquadLeader(): return None

the following code

# Prevent squad members from change
if p.getSquadId()>0: return None

More Additions

Auto TeamSet on Connect:

Open autobalance.py add after:

if team2 > team1:
                p.setTeam(1)
        else:
                p.setTeam(2)

this code part for only One Clan:

#change Team to 1 on Connect if Clanmember
name=p.getName()
if name.find(clantag)>-1: p.setTeam(1)

or this code part for multiple Clans:

#change Team to 1 on Connect if Clanmember
name=p.getName()
for clantag in clantags:
 if name.find(clantag)>-1: p.setTeam(1)

Example

The whole autobalance.py can look like this:

Example

The whole autobalance.py can look like this:

# team autobalance system

import bf2
import host
from bf2 import g_debug

#Insert here your Clantags
clantags=["Net.BS|","|CSAR|"]

def init():
        if g_debug: print 'initializing autobalance script'

        host.registerHandler('PlayerConnect', onPlayerConnect)
        host.registerHandler('PlayerDeath', onPlayerDeath)
        host.registerHandler('PlayerChangeTeams', onPlayerChangeTeams)

def onPlayerConnect(p):

        # dont teamswitch alive players, or they will have the wrong teams kit
        if p.isAlive(): return

        # 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)
        #change Team to 1 on Connect if Clanmember
        name=p.getName()
        for clantag in clantags:
         if name.find(clantag)>-1: p.setTeam(1)

def onPlayerDeath(p, vehicle):

        if not bf2.serverSettings.getAutoBalanceTeam(): return

        # Prevent Clanmembers from Autobalancing
        name=p.getName()
        for clantag in clantags:
         if name.find(clantag)>-1: return None

        # Squadleader/Commander prevent from Change
        if p.isCommander(): return None
        if p.isSquadLeader(): return None

        # Prevent squad members from change
        if p.getSquadId()>0: return None

        # dont use autobalance when its suicide/changes team
        if p.getSuicide():
                p.setSuicide(0)
                return

        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

        team2 = team2 * bf2.serverSettings.getTeamRatioPercent() / 100.0

        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

        # dont teamswitch alive players, or they will have the wrong teams kit
        if p.isAlive(): return

        if host.sgl_getIsAIGame():
                if humanHasSpawned: return
                if p.isAIPlayer(): return

                # 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:
                # 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)

Feautures

With all modifications you got a Autobalancescript with following Features:

- Auto set Team 1 for Clanmembers on connect - Protect Clanmembers from Autobalance - Protect Commanders and Squadleaders from Autobalance - Protect Squadmembers from Autobalance

Feedback

You can give me a Feedback at nexus2kswiss(at)bs-dc.com

--Nexus2k 06:02, 21 Jul 2005 (MDT)