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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
import es,gamethread,playerlib,timeit, math
info = es.AddonInfo()
info.name = "TFlash"
info.version = "1.53P"
info.author = "*XYZ*SaYnt"
info.url = "http://addons.eventscripts.com/addons/view/tflash"
info.basename = "tflash"
info.description = "Detects team flashes and reports all flash stats for logging; also simple round-end flash stats."
#===============================================================================
# User configurable parameters
#duration of a flash under which a player is not considered blind.
#in seconds.
tf_cfg_durationlimit = 0.75
# flag to show end of round overall team flash stats. Set to zero to disable.
tf_cfg_end_of_round_stats = 1
# flag to disable flash logging for hlstatsx/psychostats. Set to zero to disable.
tf_cfg_log = 1
#===============================================================================
# global variables
flashed_for = {}
log_events = []
flash_stats = {}
flash_stats['2'] = {}
flash_stats['3'] = {}
def load():
#es.msg("TFlash %s by *XYZ*SaYnt loaded." % info.version)
es.set("tflash_version",info.version)
es.makepublic("tflash_version")
def round_start(ev):
reset_flash_stats()
#This is our custom version of statlog until the python version comes out.
def statlog(userid,event):
es.server.queuecmd("statlog " + str(userid) + " " + event)
##############################################################################
#ASSUMPTION.....FLASHBANG DETONATE HAPPENS VERY QUICKLY AFTER PLAYER BLIND.
##############################################################################
def player_blind(ev):
global log_events
global flashed_for
global tf_cfg_durationlimit
global flash_stats
userid = ev['userid']
p = playerlib.getPlayer(userid)
#add blinded players to a dictionary; userid is the key; store the
#flash duration.
#and only store if flash magnitude is high (255)
isdead = int(p.attributes['isdead'])
if not isdead:
alpha = int(p.get('flashalpha'))
if alpha == 255:
duration = float(p.get('flashduration'))
if duration > tf_cfg_durationlimit:
teamid = str(p.attributes['teamid'])
log_events.append([userid,"Player_Blind"])
flash_stats[teamid]["blind"] += 1
flashed_for[userid] = duration
def flashbang_detonate(ev):
global log_events
global flashed_for
global flash_stats
userid = ev['userid']
userteam = ev['es_userteam']
log_events.append([userid,"Flash_Detonate"])
flash_stats[userteam]["flashbang"] += 1
#we already have a list of players that were just blinded, so we loop through
#that list and see if any were on our team.
for k, v in flashed_for.iteritems():
tfcheck(userid,userteam,k,v)
# now clear out the dictionaries that we have created
flashed_for.clear()
def tfcheck(userid_of_flasher,team_of_flasher,userid_of_flashed,duration):
global log_events
global flash_stats
flash_stats[team_of_flasher]["blind_caused_by"] += 1
pobj = playerlib.getPlayer(userid_of_flasher)
team_of_flashed = es.getplayerteam(userid_of_flashed)
if int(team_of_flasher) == int(team_of_flashed):
if int(userid_of_flasher) == int(userid_of_flashed):
# player flashed himself.
es.tell(userid_of_flashed,"[FT] You just flashed yourself for %.2f seconds" % duration)
log_events.append([userid_of_flashed,"Self_Flasher"])
flash_stats[team_of_flasher]["self_flashed"] += 1
else:
schaden = math.ceil(math.ceil(duration * schadensmultiplizierer))
# player flashed a teammate. tattle.
#es.msg("tattle")
leben = pobj.get("health") - schaden
if leben > 0:
pobj.set("health", leben)
else:
es.sexec(userid_of_flasher, "kill")
blinded_name = es.getplayername(userid_of_flashed)
flasher_name = es.getplayername(userid_of_flasher)
es.tell(userid_of_flashed,"[FT] You were just teamflashed for %.2f seconds by %s (He got %i damage for that)" % (duration,flasher_name, schaden))
es.tell(userid_of_flasher,"[FT] You just teamflashed %s for %.2f seconds (Damage for that: %i)" % (blinded_name,duration, schaden))
log_events.append([userid_of_flasher,"Team_Flasher"])
log_events.append([userid_of_flashed,"Team_Flashee"])
flash_stats[team_of_flasher]["team_flashed"] += 1
else:
# player flashed the opposite team, which is good.
log_events.append([userid_of_flasher,"OppositeTeam_Flasher"])
flash_stats[team_of_flasher]["opposing_flashed"] += 1
def round_end(ev):
# at round end, we dump the stats. This is for efficiency so that we are not
# calling statslog quite so much during the middle of gameplay. I've never
# seen a problem with doing this, but still, it pays to be efficient. We also
# delay it slightly so that it gets taken care of in a different tick than
# all of the other round end events.
if tf_cfg_end_of_round_stats:
gamethread.delayed(0.3, write_flashstats)
if tf_cfg_log:
gamethread.delayed(0.5, write_logs)
def write_logs_timed():
thetime = timeit.Timer("tflash.write_logs()","from tflash import tflash").timeit(1)
es.log("Wrote tflash logs in %f seconds" % thetime);
def write_logs():
global log_events
for x in log_events:
statlog(x[0],x[1])
del log_events[:]
def write_flashstats():
write_flashstat('CT','3')
write_flashstat(' T','2')
def write_flashstat(moniker,teamid):
global flash_stats
otherteam = other_team(teamid)
flashbangs = flash_stats[teamid]["flashbang"]
blind = flash_stats[teamid]["blind_caused_by"]
if blind > 0:
teamflashing = float(flash_stats[teamid]["team_flashed"])/float(blind)*100.0
selfflashing = float(flash_stats[teamid]["self_flashed"])/float(blind)*100.0
goodflashing = float(flash_stats[teamid]["opposing_flashed"])/float(blind)*100.0
else:
teamflashing = 0.0
selfflashing = 0.0
goodflashing = 0.0
tellall("#green","[TF] %s: %d flashbangs thrown. %.1f%% teamflash, %.1f%% opposingflash, %.1f%% selfflash." % (moniker,flashbangs,teamflashing,goodflashing,selfflashing))
def other_team(teamid):
if teamid == '3':
return '2'
elif teamid == '2':
return '3'
else:
return '0'
def reset_flash_stats():
global flash_stats
for k in flash_stats:
flash_stats[k]["blind"] = 0
flash_stats[k]["blind_caused_by"] = 0
flash_stats[k]["flashbang"] = 0
flash_stats[k]["self_flashed"] = 0
flash_stats[k]["team_flashed"] = 0
flash_stats[k]["opposing_flashed"] = 0
def tellall(color,msg):
userids = es.getUseridList()
for k in userids:
es.tell(k,color,msg)
|