1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[Solved]Summaries problem

Discussion in 'BF2Statistics discussion' started by funhk, May 10, 2009.

  1. funhk

    funhk New Member

    I've recently installed BF2 statistics v1.2 on a 1.0 dedicated server.
    But i found the unlock.py sound to be a bf2 1.2 one cos it has more unlock items.
    Therefore, I searched for BF2statistics 1.0
    1.0 seems matched rhe original unlock.py
    However, no matter bf2stats 1.2/1.0 I used gets me an error message when changing to next level. The score was blackened as shown below.

    [​IMG]

    unknown_map; unknown_gamemode

    I've searched those syntax and found it related to constants.py
    p.s. I've not edited the constant file
    and after investigate I also discovered the snapshot.py seem to have problem.(I've already download the updated snapshot.py in download session)
    line 187 #("gm", getGameModeId(bf2.serverSettings.getGameMode())),
    when comparing with 1.4.2, the one in 1.0 is command out with a #

    Moreover, I believed that even BF2stats v1.0 is not designed for BF2 1.0.2442. Am I right?
    cos I can find xpack's python folder in it

    I've also search for solution in this forum, Google other forums
    but I can't find an answer.. Mr thinner's solution in
    http://express.websitewelcome.com/~nbfclan/bf2statistics/e107_plugins/forum/forum_viewtopic.php?4552.post
    is for the bf2stats v1.4 and that required the use of BF2 v1.41

    The fact is there're private ranked servers in the original BF2 1.0 and demo servers
    so, is there any old version that I can use with v1.0? anyone can provide me?
    or how can I map my python files so that I works?
    I really need to host a 1.0 server
    thx in advance!
     
  2. funhk

    funhk New Member

    I think there's no connecting problem with my db
    and here're my configs

    since there maybe too much words in this passage
    you can better view it in a texteditor

    sv.serverName "blah"
    sv.password ""
    sv.internet 1
    sv.bandwidthChoke 0
    sv.serverIP ""
    sv.serverPort 16567
    sv.welcomeMessage "blah"
    sv.punkBuster 1
    sv.allowFreeCam 0
    sv.allowExternalViews 1
    sv.allowNoseCam 1
    sv.hitIndicator 1
    sv.maxPlayers 64
    sv.numPlayersNeededToStart 2
    sv.notEnoughPlayersRestartDelay 15
    sv.startDelay 15
    sv.endDelay 5
    sv.spawnTime 15
    sv.manDownTime 15
    sv.endOfRoundDelay 0
    sv.ticketRatio 100
    sv.roundsPerMap 1
    sv.timeLimit 2700
    sv.scoreLimit 0
    sv.soldierFriendlyFire 100
    sv.vehicleFriendlyFire 100
    sv.soldierSplashFriendlyFire 100
    sv.vehicleSplashFriendlyFire 100
    sv.tkPunishEnabled 1
    sv.tkNumPunishToKick 3
    sv.tkPunishByDefault 0
    sv.votingEnabled 1
    sv.voteTime 90
    sv.minPlayersForVoting 2
    sv.gameSpyPort 29900
    sv.allowNATNegotiation 0
    sv.interfaceIP
    sv.autoRecord 0
    sv.demoIndexURL ""
    sv.demoDownloadURL "http://"
    sv.autoDemoHook "adminutils/demo/rotate_demo.exe"
    sv.demoQuality 1
    sv.adminScript "default"
    sv.timeBeforeRestartMap 30
    sv.autoBalanceTeam 1
    sv.teamRatioPercent 100
    sv.voipEnabled 1
    sv.voipQuality 3
    sv.voipServerRemote 0
    sv.voipServerRemoteIP
    sv.voipServerPort 55125
    sv.voipBFClientPort 55123
    sv.voipBFServerPort 55124
    sv.voipSharedPassword
    sv.useGlobalRank 1
    sv.useGlobalUnlocks 1
    sv.sponsorText ""
    sv.sponsorLogoURL ""
    sv.communityLogoURL ""
    sv.radioSpamInterval 6
    sv.radioMaxSpamFlagCount 6
    sv.radioBlockedDurationTime 30

    the starting parametries are
    bf2_w32ded.exe +config "xxx.con" +mapList "yyy.con" +dedicated 1 +ranked 1

    config.php



    the original snapshot.py in download session
    #################################################
    #
    # History:
    # 11/24/05 v0.0.1 - ALPHA build
    # 11/28/05 v0.0.2 - Removed killedByPlayer
    # - Added kills
    # 12/08/05 v0.0.3 - Added deaths
    # 12/09/05 v0.0.4 - Removed tnv/tgm
    # 12/10/05 v0.0.5 - Added prefix
    # 12/14/05 v0.0.6 - Removed useless GS call
    # - Removed tactical/zip/grappling kills
    # - Added grappling deaths
    # 12/25/05 v0.0.7 - Added v
    # 01/03/06 v0.1 - BETA release
    # 01/05/06 v0.1.1 - Added master db
    # - Added socket timeout/error handling
    # 01/25/06 v0.1.2 - Updated CDB IP
    # 02/15/06 v0.1.3 - Updated CDB URL
    #
    #################################################

    HOST = '127.0.0.1' # server ip
    PORT = 80 # server http port
    PATH = '/ASP/bf2statistics.php' # server path to script
    PREFIX = 'logs' # log file prefix


    unlock.py
    import host
    import bf2.PlayerManager
    from bf2.stats.constants import *
    from bf2 import g_debug


    # map gamespy item ids to kits
    unlockItemMap = {
    11 : 0,
    22 : 1,
    33 : 2,
    44 : 3,
    55 : 4,
    66 : 5,
    77 : 6,
    }

    sessionPlayerUnlockMap = {}



    def init():
    # Events
    host.registerHandler('PlayerConnect', onPlayerConnect, 1)

    # Added by Chump - for bf2statistics stats (plus de-indenting)
    #if bf2.serverSettings.getUseGlobalUnlocks():
    host.registerHandler('PlayerUnlocksResponse', onUnlocksResponse, 1)

    # Connect already connected players if reinitializing
    for p in bf2.playerManager.getPlayers():
    onPlayerConnect(p)

    if g_debug: print "Unlock module initialized"



    class UnlockSet: pass



    def onPlayerConnect(player):

    defaultUnlocks = [0, 0, 0, 0, 0, 0, 0]
    host.pers_plrSetUnlocks(player.index, defaultUnlocks, defaultUnlocks)

    if not player.isAIPlayer():
    id = player.index
    reconnect = id in sessionPlayerUnlockMap

    # always get new unlocks on reconnect/map restart/map change etc
    if reconnect:
    del sessionPlayerUnlockMap[id]

    newUnlockSet = UnlockSet()

    newUnlockSet.unlockLevel = {}
    for i in range(0, NUM_KIT_TYPES):
    newUnlockSet.unlockLevel = 0

    sessionPlayerUnlockMap[id] = newUnlockSet

    player.unlocks = sessionPlayerUnlockMap[id]

    # Added by Chump - for bf2statistics stats (plus de-indenting)
    #if bf2.serverSettings.getUseGlobalUnlocks():
    if player.getProfileId() > 2000:
    success = host.pers_plrRequestUnlocks(player.index, 1)
    if not success:
    if g_debug: print "Failed requesting unlocks"
    else:
    if g_debug: print "Player %d had no profile id, can't request unlocks" % player.index

    if g_debug: print "Added player %d to unlock checking" % (player.index)



    def onUnlocksResponse(succeeded, player, unlocks):
    if not succeeded:
    print "Unlocks request failed for player %d %d: %s" % (player.index, player.getName(), unlocks)
    return

    # print "Unlocks received for player ", player.getName(), "(",player.index, ") : ", unlocks

    # translate gamespy item vector into a kit-based unlock vector handled by game
    kitUnlocks = [0, 0, 0, 0, 0, 0, 0]
    for item in unlocks:
    if item in unlockItemMap:
    kitUnlocks[unlockItemMap[item]] = 1

    if g_debug: print "Kit unlocks: ", kitUnlocks
    #We do not yet support giving different unlocks to different teams
    host.pers_plrSetUnlocks(player.index, kitUnlocks, kitUnlocks)

    stats.py

    import host
    import bf2.PlayerManager
    import fpformat
    from constants import *
    from bf2 import g_debug



    roundArmies = [None, None, None]

    playerConnectionOrderIterator = 0
    def getPlayerConnectionOrderIterator():
    global playerConnectionOrderIterator
    return playerConnectionOrderIterator

    def setPlayerConnectionOrderIterator(value):
    global playerConnectionOrderIterator
    playerConnectionOrderIterator = value



    sessionPlayerStatsMap = {}
    def getStatsMap():
    global sessionPlayerStatsMap
    return sessionPlayerStatsMap

    def setStatsMap(map):
    global sessionPlayerStatsMap
    sessionPlayerStatsMap = map



    def init():
    host.registerHandler('PlayerConnect', onPlayerConnect, 1)
    host.registerHandler('PlayerDisconnect', onPlayerDisconnect, 1)
    host.registerHandler('Reset', onReset, 1)

    host.registerGameStatusHandler(onGameStatusChanged)

    if g_debug: print "Persistant stats module initialized."



    def onGameStatusChanged(status):
    if status == bf2.GameStatus.Playing:

    # find highest player still connected
    highestPid = -1
    for pid in sessionPlayerStatsMap:
    if pid > highestPid:
    highestPid = pid

    global playerConnectionOrderIterator
    playerConnectionOrderIterator = highestPid + 1
    print "Reset orderiterator to %d based on highest pid kept" % playerConnectionOrderIterator

    # Reconnect players
    if len(sessionPlayerStatsMap) == 0:
    print "Reloading players"
    for p in bf2.playerManager.getPlayers():
    onPlayerConnect(p)

    global army
    roundArmies[1] = getArmy(bf2.gameLogic.getTeamName(1))
    roundArmies[2] = getArmy(bf2.gameLogic.getTeamName(2))

    # All other hooks
    host.registerHandler('PlayerKilled', onPlayerKilled)
    host.registerHandler('PlayerDeath', onPlayerDeath)
    host.registerHandler('EnterVehicle', onEnterVehicle)
    host.registerHandler('ExitVehicle', onExitVehicle)
    host.registerHandler('PickupKit', onPickupKit)
    host.registerHandler('DropKit', onDropKit)
    host.registerHandler('PlayerChangedSquad', onPlayerChangedSquad)
    host.registerHandler('ChangedCommander', onChangedCommander)
    host.registerHandler('ChangedSquadLeader', onChangedSquadLeader)
    host.registerHandler('PlayerChangeWeapon', onPlayerChangeWeapon)
    host.registerHandler('PlayerBanned', onPlayerBanned)
    host.registerHandler('PlayerKicked', onPlayerKicked)
    host.registerHandler('PlayerSpawn', onPlayerSpawn)

    for s in sessionPlayerStatsMap.itervalues():
    s.reset()

    for p in bf2.playerManager.getPlayers():
    p.stats.reinit(p)
    p.stats.wasHereAtStart = 1

    bf2.playerManager.enableScoreEvents()

    # Added by Chump - for fragalyzer
    #bf2.stats.fragalyzer_log.enable()


    elif status == bf2.GameStatus.EndGame:

    # finalize stats and send snapshot
    for p in bf2.playerManager.getPlayers():
    p.stats.wasHereAtEnd = 1
    finalizePlayer(p)

    # show end-of-round information
    bf2.stats.endofround.invoke()

    # Added by Chump - for bf2statistics stats
    # if not ranked, clean out stats vectors
    #if not host.ss_getParam('ranked'):
    # playerConnectionOrderIterator = 0
    # sessionPlayerStatsMap.clear()



    def onReset(data):
    for s in sessionPlayerStatsMap.itervalues():
    s.reset()

    for p in bf2.playerManager.getPlayers():
    p.stats.reinit(p)
    p.stats.wasHereAtStart = 1



    class PlayerStat:
    def __init__(self, player):
    self.profileId = player.getProfileId()
    self.playerId = player.index
    self.id = self.playerId
    self.connectionOrderNr = 0
    self.rank = 0

    self.reinit(player)
    self.reset()

    def reinit(self, player):
    self.name = player.getName()
    self.ipaddr = player.getAddress()
    self.localScore = player.score

    def reset(self):
    self.connectAt = date()
    self.timeOnLine = 0

    self.score = 0
    self.cmdScore = 0
    self.teamScore = 0
    self.skillScore = 0
    self.kills = 0
    self.teamkills = 0
    self.deaths = 0

    self.vehicles = {}
    for v in range(0, NUM_VEHICLE_TYPES + 1):
    if not v in self.vehicles:
    self.vehicles[v] = VehicleStat(v)
    else:
    self.vehicles[v].reset()

    self.weapons = {}
    for w in range(0, NUM_WEAPON_TYPES + 1):
    if not w in self.weapons:
    self.weapons[w] = WeaponStat(w)
    else:
    self.weapons[w].reset()

    self.kits = {}
    for k in range(0, NUM_KIT_TYPES + 1):
    if not k in self.kits:
    self.kits[k] = KitStat(k)
    else:
    self.kits[k].reset()

    self.killedByPlayer = {}
    self.killedPlayer = {}

    self.team = 0

    self.localScore.reset()

    self.bulletsFired = 0
    self.bulletsHit = 0

    self.currentKillStreak = 0
    self.longestKillStreak = 0
    self.currentDeathStreak = 0
    self.longestDeathStreak = 0
    self.wasHereAtStart = 0
    self.wasHereAtEnd = 0
    self.complete = 0
    self.medals = None

    self.spawnedTeam = 3
    self.spawnedAt = 0
    self.becameCmdAt = 0
    self.becameSqlAt = 0
    self.joinedSquadAt = 0
    self.rawTimePlayed = 0
    self.rawTimeAsCmd = 0
    self.rawTimeAsSql = 0
    self.rawTimeInSquad = 0

    self.timesBanned = 0
    self.timesKicked = 0

    self.timeAsArmy = {}
    for a in range(0, NUM_ARMIES + 1):
    self.timeAsArmy[a] = 0

    self.currentWeaponType = NUM_WEAPON_TYPES

    def __getattr__(self, name):
    if name in self.__dict__: return self.__dict__[name]
    elif name == 'timePlayed':
    if self.spawnedAt:
    timeDiff = date() - self.spawnedAt
    self.rawTimePlayed += timeDiff
    self.timeAsArmy[roundArmies[self.spawnedTeam]] += timeDiff
    self.spawnedAt = date()
    return self.rawTimePlayed
    elif name == 'timeAsCmd':
    if self.becameCmdAt:
    self.rawTimeAsCmd += date() - self.becameCmdAt
    self.becameCmdAt = date()
    return self.rawTimeAsCmd
    elif name == 'timeAsSql':
    if self.becameSqlAt:
    self.rawTimeAsSql += date() - self.becameSqlAt
    self.becameSqlAt = date()
    return self.rawTimeAsSql
    elif name == 'timeInSquad':
    if self.joinedSquadAt:
    self.rawTimeInSquad += date() - self.joinedSquadAt
    self.joinedSquadAt = date()
    return self.rawTimeInSquad
    elif name == 'accuracy':
    if self.bulletsFired == 0:
    return 0
    else:
    return 1.0 * self.bulletsHit / self.bulletsFired
    else:
    raise AttributeError, name

    # when same player rejoins server
    def reconnect(self, player):
    self.connectAt = date()
    self.ipaddr = player.getAddress()

    bf2.playerManager.disableScoreEvents()

    print "Reattaching score object from old dead player %d to new player %d" % (self.localScore.index, player.index)

    player.score = self.localScore
    player.score.index = player.index

    player.score.score = self.score
    player.score.cmdScore = self.cmdScore
    player.score.rplScore = self.teamScore
    player.score.skillScore = self.skillScore
    player.score.kills = self.kills
    player.score.TKs = self.teamkills
    player.score.deaths = self.deaths

    player.score.rank = self.rank

    bf2.playerManager.enableScoreEvents()

    # calculate final stats values for this player (disconnected or end of round)
    def finalize(self, player):
    self.copyPlayerData(player)

    if self.currentWeaponType != NUM_WEAPON_TYPES:
    self.weapons[self.currentWeaponType].exit(player)
    self.currentWeaponType = NUM_WEAPON_TYPES

    stopSpawned(player)
    stopInSquad(player)
    stopAsSql(player)
    stopAsCmd(player)

    # Added by Chump - for bf2statistics stats
    #if self.wasHereAtStart == 1 and self.wasHereAtEnd == 1:
    if self.wasHereAtEnd == 1:
    self.complete = 1

    # sum up vehicles & kits
    collectBulletsFired(player)
    finalizeBulletsFired(player)

    for v in player.stats.vehicles.itervalues():
    if v.enterAt != 0: v.exit(player)
    for v in player.stats.kits.itervalues():
    if v.enterAt != 0: v.exit(player)
    for v in player.stats.weapons.itervalues():
    if v.enterAt != 0: v.exit(player)

    # copy data to player-stats, as player might not be awailable after this
    def copyPlayerData(self, player):
    self.timeOnLine += date() - self.connectAt

    self.localScore = player.score

    self.score = player.score.score
    self.cmdScore = player.score.cmdScore
    self.teamScore = player.score.rplScore
    self.skillScore = player.score.skillScore

    if self.score < 0: self.score = 0
    if self.cmdScore < 0: self.cmdScore = 0
    if self.teamScore < 0: self.teamScore = 0
    if self.skillScore < 0: self.skillScore = 0

    self.kills = player.score.kills
    self.teamkills = player.score.TKs
    self.deaths = player.score.deaths

    self.rank = player.score.rank
    self.army = roundArmies[player.getTeam()]
    self.team = player.getTeam()

    # Added by Chump - for bf2statistics stats (plus de-indenting)
    #if host.ss_getParam('ranked'):
    if hasattr(player, 'medals'):
    self.medals = player.medals
    else:
    if g_debug: print "Player had no medal stats. pid=", player.index



    class ObjectStat:
    def __init__(self, type):
    self.reset()
    self.type = type

    def reset(self):

    # reset all non-global
    self.kills = 0
    self.killedBy = 0
    self.rawTimeInObject = 0
    self.deaths = 0
    self.score = 0
    self.bulletsFired = 0
    self.bulletsFiredTemp = 0
    self.bulletsHit = 0
    self.bulletsHitTemp = 0
    self.enterAt = 0
    self.enterScore = 0

    def enter(self, player):
    self.enterAt = date()
    self.enterScore = player.score.score

    # Added by Chump - for bf2statistics stats
    if g_debug: print "PYTHONSCRIPT: ENTER --- enterAt:%s score:%d" % (self.enterAt, self.enterScore)

    def exit(self, player):
    if self.enterAt == 0: return
    time = self.timeInObject
    self.enterAt = 0

    self.score += player.score.score - self.enterScore
    self.enterScore = 0

    # Added by Chump - for bf2statistics stats
    if g_debug: print "PYTHONSCRIPT: EXIT --- timeInObject:%s score:%d" % (time, self.score)

    def __getattr__(self, name):
    if name in self.__dict__: return self.__dict__[name]
    elif name == 'timeInObject' or name == 'rtime':
    if self.enterAt:
    self.rawTimeInObject += date() - self.enterAt
    self.enterAt = date()
    return self.rawTimeInObject
    elif name == 'accuracy':
    if self.bulletsFired == 0:
    return 0
    else:
    return 1.0 * self.bulletsHit / self.bulletsFired
    else:
    raise AttributeError, name



    class VehicleStat(ObjectStat):
    def __init__(self, type):
    ObjectStat.__init__(self, type)
    self.reset()

    def reset(self):
    ObjectStat.reset(self)
    self.roadKills = 0



    class KitStat(ObjectStat):
    def __init__(self, type):
    ObjectStat.__init__(self, type)
    self.reset()

    def reset(self):
    ObjectStat.reset(self)



    class WeaponStat(ObjectStat):
    def __init__(self, type):
    ObjectStat.__init__(self, type)
    self.reset()

    def reset(self):
    ObjectStat.reset(self)

    def enter(self, player):
    if player.stats.currentWeaponType != NUM_WEAPON_TYPES:
    player.stats.weapons[player.stats.currentWeaponType].exit(player)
    player.stats.currentWeaponType = self.type

    ObjectStat.enter(self, player)

    def exit(self,player):
    time = date() - self.enterAt

    ObjectStat.exit(self, player)



    def date():
    return host.timer_getWallTime()



    def finalizePlayer(player):
    player.stats.finalize(player)



    def onPlayerConnect(player):

    # see if player already has a record
    player.stats = None
    connectingProfileId = player.getProfileId()
    for stats in sessionPlayerStatsMap.itervalues():
    if connectingProfileId > 0 and connectingProfileId == stats.profileId:
    print "Found old player record, profileId ", stats.profileId
    player.stats = stats
    player.stats.reconnect(player)

    if not player.stats:

    print "Creating new record for player profileId ", connectingProfileId

    # add stats record
    global playerConnectionOrderIterator
    id = playerConnectionOrderIterator

    newPlayerStats = PlayerStat(player)

    sessionPlayerStatsMap[id] = newPlayerStats
    player.stats = sessionPlayerStatsMap[id]

    player.stats.connectionOrderNr = playerConnectionOrderIterator
    playerConnectionOrderIterator += 1

    player.score.rank = player.stats.rank





    def onPlayerDisconnect(player):
    finalizePlayer(player)




    def onEnterVehicle(player, vehicle, freeSoldier = False):

    if player == None: return

    vehicleType = getVehicleType(vehicle.templateName)
    if vehicleType != VEHICLE_TYPE_SOLDIER:
    rootVehicle = bf2.objectManager.getRootParent(vehicle)
    vehicleType = getVehicleType(rootVehicle.templateName)
    else: rootVehicle = vehicle

    if vehicleType != VEHICLE_TYPE_SOLDIER:
    for w in player.stats.weapons.itervalues():
    w.exit(player)

    weapon = player.getPrimaryWeapon()
    if weapon:
    weaponType = getWeaponType(weapon.templateName)
    player.stats.weapons[weaponType].enter(player)

    if not vehicleType in player.stats.vehicles:
    player.stats.vehicles[vehicleType] = VehicleStat()

    player.stats.vehicles[vehicleType].enter(player)
    if vehicleType != VEHICLE_TYPE_UNKNOWN:
    player.stats.lastVehicleType = vehicleType

    weapon = player.getPrimaryWeapon()
    if weapon:
    player.stats.lastWeaponType = getWeaponType(weapon.templateName)

    collectBulletsFired(player)

    # Added by Chump - for bf2statistics stats
    if g_debug: print "PYTHONSCRIPT: Enter Vehicle --- vehicleType:%s rootVehicle:%s player.stats.vehicles[vehicleType]:%s" % (vehicleType, rootVehicle, player.stats.vehicles[vehicleType])



    def onExitVehicle(player, vehicle):

    vehicleType = getVehicleType(vehicle.templateName)
    if vehicleType != VEHICLE_TYPE_SOLDIER:
    rootVehicle = bf2.objectManager.getRootParent(vehicle)
    vehicleType = getVehicleType(rootVehicle.templateName)

    # keep track of last driver, for road kill scoring purposes
    if rootVehicle == vehicle:
    vehicle.lastDrivingPlayerIndex = player.index

    else: rootVehicle = vehicle

    weapon = player.getPrimaryWeapon()
    if weapon:
    weaponType = getWeaponType(weapon.templateName)
    player.stats.weapons[weaponType].enter(player)

    player.stats.vehicles[vehicleType].exit(player)

    weapon = player.getPrimaryWeapon()
    if weapon:
    player.stats.lastWeaponType = getWeaponType(weapon.templateName)

    collectBulletsFired(player)

    # Added by Chump - for bf2statistics stats
    if g_debug: print "PYTHONSCRIPT: Exit Vehicle --- vehicleType:%s rootVehicle:%s" % (vehicleType, rootVehicle)


    def onPlayerSpawn(player, soldier):

    startSpawned(player)
    if player.getSquadId() != 0: startInSquad(player)
    if player.isSquadLeader(): startAsSql(player)
    if player.isCommander(): startAsCmd(player)

    onEnterVehicle(player, soldier)
    player.soldier = soldier



    def onPickupKit(player, kit):
    kitType = getKitType(kit.templateName)

    if not kitType in player.stats.kits:
    player.stats.kits[kitType] = KitStat()

    player.stats.kits[kitType].enter(player)
    player.stats.lastKitType = kitType

    weapon = player.getPrimaryWeapon()
    if weapon:
    player.stats.lastWeaponType = getWeaponType(weapon.templateName)



    def onDropKit(player, kit):
    kitType = getKitType(kit.templateName)
    player.stats.kits[kitType].exit(player)

    for w in player.stats.weapons.itervalues():
    w.exit(player)

    collectBulletsFired(player)



    def onPlayerChangeWeapon(player, oldWeapon, newWeapon):
    if oldWeapon:
    oldWeaponType = getWeaponType(oldWeapon.templateName)
    player.stats.weapons[oldWeaponType].exit(player)

    if newWeapon:
    newWeaponType = getWeaponType(newWeapon.templateName)
    player.stats.weapons[newWeaponType].enter(player)
    player.stats.lastWeaponType = newWeaponType



    def onPlayerKilled(victim, attacker, weapon, assists, object):

    # check if killed by vehicle in motion
    killedByEmptyVehicle = False
    if attacker == None and weapon == None and object != None:
    if hasattr(object, 'lastDrivingPlayerIndex'):
    attacker = bf2.playerManager.getPlayerByIndex(object.lastDrivingPlayerIndex)
    killedByEmptyVehicle = True

    # killed by enemy
    if attacker != None:

    # no kill stats for teamkills / suicides!
    if attacker.getTeam() != victim.getTeam():

    # streaks
    attacker.stats.currentKillStreak += 1
    if attacker.stats.currentKillStreak > attacker.stats.longestKillStreak:
    attacker.stats.longestKillStreak = attacker.stats.currentKillStreak

    # end current death streak
    attacker.stats.currentDeathStreak = 0

    # killedBy
    if attacker != None:
    if not victim.stats.connectionOrderNr in attacker.stats.killedPlayer:
    attacker.stats.killedPlayer[victim.stats.connectionOrderNr] = 0
    attacker.stats.killedPlayer[victim.stats.connectionOrderNr] += 1

    if not attacker.stats.connectionOrderNr in victim.stats.killedByPlayer:
    victim.stats.killedByPlayer[attacker.stats.connectionOrderNr] = 0
    victim.stats.killedByPlayer[attacker.stats.connectionOrderNr] += 1


    # weapon stats
    if weapon != None:
    weaponType = getWeaponType(weapon.templateName)

    if attacker != None:
    attacker.stats.weapons[weaponType].kills += 1

    if victim != None:
    victim.stats.weapons[weaponType].killedBy += 1

    # vehicle stats
    vehicleType = None
    if killedByEmptyVehicle:
    vehicleType = getVehicleType(object.templateName)
    else:
    vehicle = attacker.getVehicle()
    vehicleType = getVehicleType(vehicle.templateName)

    if vehicleType != VEHICLE_TYPE_SOLDIER:
    rootVehicle = bf2.objectManager.getRootParent(vehicle)
    if rootVehicle != None:
    vehicleType = getVehicleType(rootVehicle.templateName)

    if vehicleType != None:
    if attacker != None:
    attacker.stats.vehicles[vehicleType].kills += 1
    if victim != None:
    victim.stats.vehicles[vehicleType].killedBy += 1

    # road kill
    if weapon == None and object != None:
    attacker.stats.vehicles[vehicleType].roadKills += 1


    # kit stats
    if attacker != None:
    kit = attacker.getKit()
    if kit != None:
    kitTemplateName = kit.templateName
    kitType = getKitType(kitTemplateName)
    elif hasattr(attacker, 'lastKitType'):
    kitType = attacker.lastKitType
    else:
    return

    attacker.stats.kits[kitType].kills += 1

    # death stats are handled in onPlayerDeath.

    collectBulletsFired(attacker)



    def onPlayerDeath(victim, vehicle):

    # vehicle is already exited, as this happens before actual death. That doesnt stop us from dying in it.
    rootVehicle = bf2.objectManager.getRootParent(vehicle)
    vehicleType = getVehicleType(rootVehicle.templateName)

    stopSpawned(victim)
    stopInSquad(victim)
    stopAsSql(victim)
    stopAsCmd(victim)

    onExitVehicle(victim, victim.soldier)
    finalizeBulletsFired(victim)
    clearBulletsFired(victim)

    # streaks
    victim.stats.currentDeathStreak += 1
    if victim.stats.currentDeathStreak > victim.stats.longestDeathStreak:
    victim.stats.longestDeathStreak = victim.stats.currentDeathStreak

    # end current kill streak
    victim.stats.currentKillStreak = 0

    victim.stats.vehicles[vehicleType].deaths += 1

    # kit is already dropped, so we have to get the last kit used
    victim.stats.kits[victim.stats.lastKitType].deaths += 1

    # weapon is already dropped, so we gave to get the last weapon used
    victim.stats.weapons[victim.stats.lastWeaponType].deaths += 1



    # update accuracy on weapon, kit and vehicle
    def collectBulletsFired(player):
    if player == None: return

    # count bullets fired
    bulletsFired = player.score.bulletsFired
    totBulletsFired = 0
    kitBulletsFired = 0
    for b in bulletsFired:
    templateName = b[0]
    nr = b[1]

    weaponType = getWeaponType(templateName)
    player.stats.weapons[weaponType].bulletsFiredTemp = nr
    totBulletsFired += nr

    # only count kit stats for soldier-type weapons
    if weaponType != WEAPON_TYPE_UNKNOWN:
    kitBulletsFired += nr


    # count bullets hit
    bulletsHit = player.score.bulletsGivingDamage
    totBulletsHit = 0
    kitBulletsHit = 0
    for b in bulletsHit:
    templateName = b[0]
    nr = b[1]

    weaponType = getWeaponType(templateName)
    player.stats.weapons[weaponType].bulletsHitTemp = nr
    totBulletsHit += nr

    # only count kit stats for soldier-type weapons
    if weaponType != WEAPON_TYPE_UNKNOWN:
    kitBulletsHit += nr


    # dont bother giving kit stats if we're in a vehicle
    kit = player.getKit()
    if kit != None:
    kitType = getKitType(kit.templateName)
    player.stats.kits[kitType].bulletsFiredTemp = kitBulletsFired
    player.stats.kits[kitType].bulletsHitTemp = kitBulletsHit

    vehicle = player.getVehicle()
    if vehicle != None:
    rootVehicle = bf2.objectManager.getRootParent(vehicle)
    vehicleType = getVehicleType(rootVehicle.templateName)

    player.stats.vehicles[vehicleType].bulletsFiredTemp = totBulletsFired
    player.stats.vehicles[vehicleType].bulletsHitTemp = totBulletsHit



    def clearBulletsFired(player):

    # Added by Chump - for fragalyzer
    #bf2.stats.fragalyzer_log.dumpAccuracy(player)

    bulletsFired = player.score.bulletsFiredAndClear
    bulletsHit = player.score.bulletsGivingDamageAndClear



    def finalizeBulletsFired(player):
    for v in player.stats.vehicles.itervalues():
    v.bulletsFired += v.bulletsFiredTemp
    v.bulletsHit += v.bulletsHitTemp
    v.bulletsFiredTemp = 0
    v.bulletsHitTemp = 0
    for w in player.stats.weapons.itervalues():
    w.bulletsFired += w.bulletsFiredTemp
    w.bulletsHit += w.bulletsHitTemp
    player.stats.bulletsFired += w.bulletsFiredTemp
    player.stats.bulletsHit += w.bulletsHitTemp
    w.bulletsFiredTemp = 0
    w.bulletsHitTemp = 0
    for k in player.stats.kits.itervalues():
    k.bulletsFired += k.bulletsFiredTemp
    k.bulletsHit += k.bulletsHitTemp
    k.bulletsFiredTemp = 0
    k.bulletsHitTemp = 0



    def startSpawned(player):
    player.stats.spawnedAt = date()
    player.stats.spawnedTeam = player.getTeam()
    def startInSquad(player): player.stats.joinedSquadAt = date()
    def startAsSql(player): player.stats.becameSqlAt = date()
    def startAsCmd(player): player.stats.becameCmdAt = date()



    def stopSpawned(player):
    time = player.stats.timePlayed
    player.stats.spawnedAt = 0
    player.stats.spawnedTeam = 3
    def stopInSquad(player):
    time = player.stats.timeInSquad
    player.stats.joinedSquadAt = 0
    def stopAsSql(player):
    time = player.stats.timeAsSql
    player.stats.becameSqlAt = 0
    def stopAsCmd(player):
    time = player.stats.timeAsCmd
    player.stats.becameCmdAt = 0



    def onChangedCommander(team, oldCmd, newCmd):
    if newCmd and newCmd.stats.spawnedAt != 0: startAsCmd(newCmd)
    if oldCmd: stopAsCmd(oldCmd)



    def onChangedSquadLeader(squad, oldSql, newSql):
    if newSql and newSql.stats.spawnedAt != 0: startAsSql(newSql)
    if oldSql: stopAsSql(oldSql)



    def onPlayerChangedSquad(player, oldSquad, newSquad):
    if oldSquad == newSquad:
    return

    if player.stats.spawnedAt == 0:
    return

    if oldSquad == 0: startInSquad(player)
    if newSquad == 0:
    stopAsSql(player)
    stopInSquad(player)



    def onPlayerBanned(player, time, type):

    # dont count round bans
    if type == 2: return

    player.stats.timesBanned += 1



    def onPlayerKicked(player):
    player.stats.timesKicked += 1
     
  3. funhk

    funhk New Member

    hello, I just checked my sql
    players' record are saved
    that means it should work
    but I just have no idea why the python returns as unknown gamemode and unknown maps

    Please, if you know where's the problem
    please tell me
    or if you have a bf2 v1.0 compatible bf2stats plz send to me by PM or attach here
    I would be appreciated.
    Thank you very much
     
  4. Thinner

    Thinner New Member

    Hi,

    try this one: http://www.bf2statistics.com/e107_plugins/forum/forum_viewtopic.php?5378.10#post_5406

    The events are not available in BF2 Demo server that's why the code will crash and end-of-round data isn't send.
     
  5. funhk

    funhk New Member

    hi, mate
    I tried, doesn't work
    My BF2Statistics is v1.2
    and the server is running retail 1.0