This repository has been archived by the owner on Nov 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoreboardsaver.py
83 lines (63 loc) · 2.22 KB
/
scoreboardsaver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#
# Server Scoreboard Saver
# - It saves the information of each player in the end of each round
#
# By: UTurista
#
# =======================================================
# =============== CONFIGURATION =====================
# =======================================================
record_folder = '/logs/'
record_extension = '.log'
# =======================================================
# =================== CODE ==========================
# =======================================================
import host
import bf2
from datetime import datetime
def init():
host.registerGameStatusHandler(onGameStatusChanged)
def deinit():
host.unregisterGameStatusHandler(onGameStatusChanged)
json_separator = ','
def onGameStatusChanged(status):
if status == bf2.GameStatus.EndGame:
now = datetime.now()
path = host.sgl_getModDirectory() + record_folder + str(bf2.gameLogic.getMapName()) + '_' + str(now.day) + str(now.hour) + str(now.minute) + record_extension
try:
f = open(path,'w+')
json = '['
# Available values:
#('deaths','kills','TKs','score','skillScore','rplScore','cmdScore','fracScore','rank','firstPlace','secondPlace','thirdPlace',
# 'bulletsFired','bulletsGivingDamage','bulletsFiredAndClear','bulletsGivingDamageAndClear')
first = 1
for p in bf2.playerManager.getPlayers():
try:
name = p.getName()
deaths = str(p.score.__getattr__('deaths'))
kills = str(p.score.__getattr__('kills'))
wounded = str(p.isManDown());
except Exception, e:
name = str(e)
kills = 'Invalid'
deaths = 'Invalid'
wounded = 'Invalid'
if first:
first = 0
json += '{'
else:
json += ',{'
json += '"name":"' + name + '"' + json_separator
json += '"deaths":"' + deaths + '"' + json_separator
json += '"wounded":"' + wounded + '"' + json_separator
json += '"kills":"' + kills + '"'
json += '}'
json += ']'
f.write(json)
f.close()
except Exception, e:
try:
f = open(path,'w+')
f.write(str(e))
f.close()
except : pass