Skip to content

Commit f95684e

Browse files
committed
Combine kills & scores example
1 parent de04794 commit f95684e

File tree

7 files changed

+60
-122
lines changed

7 files changed

+60
-122
lines changed

examples/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ Here you can find a overview of examples on how to use demoinfocs-golang.
66
|-|-|
77
|[heatmap](heatmap)|Creating a heatmap from positions where players fired shots from|
88
|[net-messages](net-messages)|Parsing and handling custom net-messages|
9-
|[scores](scores)|Printig scores on the end of a round|
10-
|[kills](kills)|Printing kills (attacker, weapon, headshot, wallbang & victim)|
9+
|[print-events](print-events)|Printig kills & scores|

examples/kills/kills.go

Lines changed: 0 additions & 58 deletions
This file was deleted.

examples/kills/kills_test.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

examples/kills/README.md renamed to examples/print-events/README.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
# Printing kills
1+
# Printing event infos
22

3-
This example shows how to use the library to print out all kills including attackers, weapons, headshots, wallbangs & victims.
3+
This example shows how to use the library to print out information of some key game events - kills and team scores.
44

55
## Running the example
66

7-
`go run kills.go -demo /path/to/demo`
7+
`go run print_events.go -demo /path/to/demo`
88

99
### Sample output
1010

1111
```
12+
Map: de_cache
1213
[T]xms*ASUS ♥ /F/ <AK-47 (HS)> [CT]crisby
1314
[CT]tiziaN <USP-S (HS)> [T]Ex6TenZ-BALLISTIX
1415
[CT]tiziaN <USP-S> [T]mistou * Cooler Master
@@ -19,19 +20,22 @@ This example shows how to use the library to print out all kills including attac
1920
[T]to1nou * Seagate <USP-S (HS)> [CT]syrsoNR
2021
[CT]keev <USP-S (HS)> [T]to1nou * Seagate
2122
[CT]keev <USP-S (HS)> [T]xms*ASUS ♥ /F/
23+
Round finished: winnerSide=CT ; score=1:0
2224
[T]Ex6TenZ-BALLISTIX <Desert Eagle (HS)> [CT]syrsoNR
2325
[CT]kzy LJ∼ <FAMAS (HS)> [T]ALEX * Intel
2426
[CT]crisby <UMP-45 (HS)> [T]to1nou * Seagate
2527
[CT]kzy LJ∼ <FAMAS> [T]Ex6TenZ-BALLISTIX
2628
[CT]kzy LJ∼ <FAMAS (HS)> [T]xms*ASUS ♥ /F/
2729
[CT]keev <UMP-45> [T]mistou * Cooler Master
30+
Round finished: winnerSide=CT ; score=2:0
2831
[CT]crisby <UMP-45 (HS)> [T]to1nou * Seagate
2932
[CT]kzy LJ∼ <FAMAS (HS)> [T]Ex6TenZ-BALLISTIX
3033
[CT]crisby <USP-S> [CT]kzy LJ∼
3134
[CT]crisby <USP-S (HS)> [T]xms*ASUS ♥ /F/
3235
[T]mistou * Cooler Master <Glock-18 (HS)> [CT]crisby
3336
[CT]syrsoNR <M4A1> [T]ALEX * Intel
3437
[CT]syrsoNR <M4A1 (HS)> [T]mistou * Cooler Master
38+
Round finished: winnerSide=CT ; score=3:0
3539
[T]Ex6TenZ-BALLISTIX <AK-47> [CT]crisby
3640
[CT]syrsoNR <M4A1 (HS) (WB)> [T]Ex6TenZ-BALLISTIX
3741
[CT]kzy LJ∼ <FAMAS> [T]mistou * Cooler Master
@@ -40,6 +44,7 @@ This example shows how to use the library to print out all kills including attac
4044
[T]ALEX * Intel <AK-47> [T]xms*ASUS ♥ /F/
4145
[CT]tiziaN <M4A1> [T]ALEX * Intel
4246
[CT]keev <Desert Eagle> [T]to1nou * Seagate
47+
Round finished: winnerSide=CT ; score=4:0
4348
[T]to1nou * Seagate <AK-47 (HS)> [CT]syrsoNR
4449
[CT]crisby <M4A1> [T]to1nou * Seagate
4550
[T]xms*ASUS ♥ /F/ <AK-47 (HS)> [CT]crisby
@@ -48,22 +53,26 @@ This example shows how to use the library to print out all kills including attac
4853
[T]Ex6TenZ-BALLISTIX <AK-47> [CT]kzy LJ∼
4954
[CT]tiziaN <AK-47> [T]ALEX * Intel
5055
[CT]keev <AWP> [T]Ex6TenZ-BALLISTIX
56+
Round finished: winnerSide=CT ; score=5:0
5157
[CT]keev <AWP> [T]mistou * Cooler Master
5258
[T]Ex6TenZ-BALLISTIX <Tec-9 (HS)> [CT]keev
5359
[T]Ex6TenZ-BALLISTIX <Tec-9 (HS)> [CT]tiziaN
5460
[T]xms*ASUS ♥ /F/ <Desert Eagle (HS) (WB)> [CT]crisby
5561
[T]ALEX * Intel <AWP> [CT]syrsoNR
62+
Round finished: winnerSide=T ; score=1:5
5663
[T]mistou * Cooler Master <AK-47 (HS)> [CT]syrsoNR
5764
[CT]keev <AWP> [T]xms*ASUS ♥ /F/
5865
[T]Ex6TenZ-BALLISTIX <AK-47> [CT]crisby
5966
[CT]keev <AWP (HS)> [T]to1nou * Seagate
6067
[CT]kzy LJ∼ <M4A1 (HS)> [T]ALEX * Intel
6168
[CT]keev <AWP> [T]Ex6TenZ-BALLISTIX
6269
[CT]kzy LJ∼ <M4A1> [T]mistou * Cooler Master
70+
Round finished: winnerSide=CT ; score=6:1
6371
[T]xms*ASUS ♥ /F/ <Tec-9> [CT]keev
6472
[CT]tiziaN <M4A1 (HS)> [T]mistou * Cooler Master
6573
[T]Ex6TenZ-BALLISTIX <AK-47> [CT]syrsoNR
6674
[T]to1nou * Seagate <AK-47> [CT]tiziaN
75+
Round finished: winnerSide=T ; score=2:6
6776
[CT]kzy LJ∼ <AK-47 (HS)> [T]mistou * Cooler Master
6877
[T]ALEX * Intel <AK-47> [CT]syrsoNR
6978
[CT]tiziaN <p250> [T]Ex6TenZ-BALLISTIX
@@ -72,32 +81,37 @@ This example shows how to use the library to print out all kills including attac
7281
[CT]crisby <M4A1> [T]xms*ASUS ♥ /F/
7382
[CT]crisby <M4A1> [T]to1nou * Seagate
7483
[CT]crisby <M4A1 (HS)> [T]ALEX * Intel
84+
Round finished: winnerSide=CT ; score=7:2
7585
[CT]tiziaN <M4A1 (HS)> [T]xms*ASUS ♥ /F/
7686
[T]Ex6TenZ-BALLISTIX <Tec-9 (HS)> [CT]tiziaN
7787
[T]to1nou * Seagate <AK-47> [CT]crisby
7888
[T]ALEX * Intel <AK-47 (HS)> [CT]syrsoNR
7989
[T]mistou * Cooler Master <Tec-9 (HS)> [CT]keev
8090
[T]to1nou * Seagate <AK-47 (HS)> [CT]kzy LJ∼
91+
Round finished: winnerSide=T ; score=3:7
8192
[CT]crisby <p250 (HS)> [T]to1nou * Seagate
8293
[T]xms*ASUS ♥ /F/ <AK-47 (HS)> [CT]crisby
8394
[CT]kzy LJ∼ <M4A1> [T]xms*ASUS ♥ /F/
8495
[CT]kzy LJ∼ <M4A1 (HS)> [T]ALEX * Intel
8596
[CT]keev <AWP> [T]Ex6TenZ-BALLISTIX
8697
[CT]keev <AWP> [T]mistou * Cooler Master
98+
Round finished: winnerSide=CT ; score=8:3
8799
[CT]kzy LJ∼ <M4A1> [T]xms*ASUS ♥ /F/
88100
[CT]kzy LJ∼ <M4A1 (HS)> [T]Ex6TenZ-BALLISTIX
89101
[T]to1nou * Seagate <AWP> [CT]kzy LJ∼
90102
[CT]tiziaN <FAMAS (HS)> [T]ALEX * Intel
91103
[T]to1nou * Seagate <AWP> [CT]tiziaN
92104
[CT]keev <AWP (HS) (WB)> [T]to1nou * Seagate
93105
[CT]crisby <M4A1> [T]mistou * Cooler Master
106+
Round finished: winnerSide=CT ; score=9:3
94107
[CT]kzy LJ∼ <M4A1> [T]ALEX * Intel
95108
[T]to1nou * Seagate <Tec-9 (HS)> [CT]crisby
96109
[CT]tiziaN <M4A1> [T]mistou * Cooler Master
97110
[CT]tiziaN <M4A1 (HS)> [T]Ex6TenZ-BALLISTIX
98111
[T]to1nou * Seagate <Tec-9 (HS)> [CT]tiziaN
99112
[CT]syrsoNR <AK-47 (WB)> [T]to1nou * Seagate
100113
[CT]keev <USP-S (HS)> [T]xms*ASUS ♥ /F/
114+
Round finished: winnerSide=CT ; score=10:3
101115
[CT]tiziaN <M4A1 (HS)> [T]mistou * Cooler Master
102116
[T]xms*ASUS ♥ /F/ <Tec-9> [CT]tiziaN
103117
[CT]syrsoNR <AK-47> [T]ALEX * Intel
@@ -106,6 +120,7 @@ This example shows how to use the library to print out all kills including attac
106120
[CT]crisby <M4A1 (HS)> [T]xms*ASUS ♥ /F/
107121
[T]Ex6TenZ-BALLISTIX <Galil AR> [CT]kzy LJ∼
108122
[CT]crisby <M4A1 (HS)> [T]Ex6TenZ-BALLISTIX
123+
Round finished: winnerSide=CT ; score=11:3
109124
[T]Ex6TenZ-BALLISTIX <AK-47> [CT]tiziaN
110125
[CT]keev <Tec-9 (HS)> [T]mistou * Cooler Master
111126
[T]xms*ASUS ♥ /F/ <AK-47> [CT]syrsoNR
@@ -114,11 +129,13 @@ This example shows how to use the library to print out all kills including attac
114129
[CT]crisby <M4A1 (HS)> [T]ALEX * Intel
115130
[T]to1nou * Seagate <AK-47> [CT]kzy LJ∼
116131
[T]xms*ASUS ♥ /F/ <AK-47> [CT]crisby
132+
Round finished: winnerSide=T ; score=4:11
117133
[CT]mistou * Cooler Master <P2000 (HS)> [T]tiziaN
118134
[CT]mistou * Cooler Master <P2000 (HS)> [T]syrsoNR
119135
[CT]mistou * Cooler Master <P2000 (HS)> [T]keev
120136
[CT]xms*ASUS ♥ /F/ <USP-S (HS)> [T]crisby
121137
[CT]ALEX * Intel <USP-S (HS)> [T]kzy LJ∼
138+
Round finished: winnerSide=CT ; score=5:11
122139
[T]tiziaN <Desert Eagle (HS)> [CT]Ex6TenZ-BALLISTIX
123140
[CT]mistou * Cooler Master <M4A1 (HS)> [T]kzy LJ∼
124141
[CT]ALEX * Intel <FAMAS> [T]syrsoNR
@@ -128,6 +145,7 @@ This example shows how to use the library to print out all kills including attac
128145
[CT]mistou * Cooler Master <M4A1 (HS)> [T]tiziaN
129146
[T]keev <FAMAS (WB)> [CT]mistou * Cooler Master
130147
[T]keev <FAMAS> [CT]xms*ASUS ♥ /F/
148+
Round finished: winnerSide=T ; score=12:5
131149
[CT]mistou * Cooler Master <Five-SeveN> [T]tiziaN
132150
[T]syrsoNR <AK-47> [CT]mistou * Cooler Master
133151
[T]kzy LJ∼ <AK-47 (HS)> [CT]xms*ASUS ♥ /F/
@@ -136,19 +154,22 @@ This example shows how to use the library to print out all kills including attac
136154
[CT]to1nou * Seagate <Five-SeveN (HS)> [T]syrsoNR
137155
[CT]Ex6TenZ-BALLISTIX <Five-SeveN (HS)> [T]kzy LJ∼
138156
[CT]to1nou * Seagate <Five-SeveN> [T]keev
157+
Round finished: winnerSide=CT ; score=6:12
139158
[T]crisby <Tec-9 (HS)> [CT]xms*ASUS ♥ /F/
140159
[CT]mistou * Cooler Master <FAMAS (HS)> [T]kzy LJ∼
141160
[CT]mistou * Cooler Master <FAMAS> [T]crisby
142161
[T]syrsoNR <Tec-9 (HS)> [CT]Ex6TenZ-BALLISTIX
143162
[CT]to1nou * Seagate <AK-47 (HS)> [T]tiziaN
144163
[CT]ALEX * Intel <M4A1> [T]syrsoNR
145164
[CT]to1nou * Seagate <AK-47> [T]keev
165+
Round finished: winnerSide=CT ; score=7:12
146166
[T]kzy LJ∼ <Desert Eagle (HS)> [CT]mistou * Cooler Master
147167
[CT]Ex6TenZ-BALLISTIX <M4A1> [T]tiziaN
148168
[CT]to1nou * Seagate <AK-47> [T]syrsoNR
149169
[CT]Ex6TenZ-BALLISTIX <M4A1> [T]crisby
150170
[CT]to1nou * Seagate <AK-47> [T]keev
151171
[CT]ALEX * Intel <M4A1> [T]kzy LJ∼
172+
Round finished: winnerSide=CT ; score=8:12
152173
[T]keev <AWP> [CT]mistou * Cooler Master
153174
[T]tiziaN <AK-47 (HS)> [CT]xms*ASUS ♥ /F/
154175
[CT]Ex6TenZ-BALLISTIX <M4A1> [T]tiziaN
@@ -157,13 +178,15 @@ This example shows how to use the library to print out all kills including attac
157178
[CT]Ex6TenZ-BALLISTIX <M4A1 (HS)> [T]keev
158179
[T]crisby <AK-47> [CT]to1nou * Seagate
159180
[CT]Ex6TenZ-BALLISTIX <M4A1> [T]crisby
181+
Round finished: winnerSide=CT ; score=9:12
160182
[CT]to1nou * Seagate <AWP> [T]syrsoNR
161183
[T]keev <AK-47 (HS)> [CT]Ex6TenZ-BALLISTIX
162184
[T]kzy LJ∼ <AK-47> [CT]xms*ASUS ♥ /F/
163185
[CT]ALEX * Intel <AK-47> [T]keev
164186
[T]kzy LJ∼ <AK-47 (HS)> [CT]ALEX * Intel
165187
[T]crisby <AK-47 (HS)> [CT]to1nou * Seagate
166188
[CT]mistou * Cooler Master <AWP (WB)> [T]kzy LJ∼
189+
Round finished: winnerSide=T ; score=13:9
167190
[T]syrsoNR <AK-47> [CT]ALEX * Intel
168191
[T]syrsoNR <AK-47 (HS)> [CT]xms*ASUS ♥ /F/
169192
[CT]Ex6TenZ-BALLISTIX <M4A1> [T]syrsoNR
@@ -172,11 +195,14 @@ This example shows how to use the library to print out all kills including attac
172195
[T]crisby <AK-47> [CT]to1nou * Seagate
173196
[CT]Ex6TenZ-BALLISTIX <M4A1> [T]crisby
174197
[CT]Ex6TenZ-BALLISTIX <P2000> [T]keev
198+
Round finished: winnerSide=CT ; score=10:13
199+
Round finished: No winner (tie)
175200
[CT]syrsoNR <World> [CT]syrsoNR
176201
[CT]ALEX * Intel <World> [CT]ALEX * Intel
177202
[CT]xms*ASUS ♥ /F/ <World> [CT]xms*ASUS ♥ /F/
178203
[CT]Ex6TenZ-BALLISTIX <World> [CT]Ex6TenZ-BALLISTIX
179204
[CT]to1nou * Seagate <World> [CT]to1nou * Seagate
205+
Round finished: No winner (tie)
180206
[CT]ALEX * Intel <World> [CT]ALEX * Intel
181207
[CT]xms*ASUS ♥ /F/ <World> [CT]xms*ASUS ♥ /F/
182208
[CT]to1nou * Seagate <World> [CT]to1nou * Seagate
@@ -187,20 +213,23 @@ This example shows how to use the library to print out all kills including attac
187213
[CT]mistou * Cooler Master <World> [CT]mistou * Cooler Master
188214
[T]keev <World> [T]keev
189215
[T]crisby <World> [T]crisby
216+
Round finished: No winner (tie)
190217
[CT]mistou * Cooler Master <AWP> [T]tiziaN
191218
[T]kzy LJ∼ <p250> [CT]mistou * Cooler Master
192219
[T]keev <Tec-9> [CT]xms*ASUS ♥ /F/
193220
[T]keev <AWP> [CT]Ex6TenZ-BALLISTIX
194221
[T]keev <AWP> [CT]ALEX * Intel
195222
[CT]to1nou * Seagate <AWP> [T]syrsoNR
196223
[CT]to1nou * Seagate <AWP> [T]crisby
224+
Round finished: winnerSide=T ; score=14:10
197225
[CT]to1nou * Seagate <AWP> [T]crisby
198226
[T]tiziaN <AK-47> [CT]Ex6TenZ-BALLISTIX
199227
[CT]mistou * Cooler Master <Five-SeveN (HS)> [T]syrsoNR
200228
[CT]mistou * Cooler Master <Five-SeveN (HS)> [T]tiziaN
201229
[T]keev <Tec-9> [CT]mistou * Cooler Master
202230
[CT]xms*ASUS ♥ /F/ <Desert Eagle> [T]kzy LJ∼
203231
[CT]xms*ASUS ♥ /F/ <Desert Eagle (HS)> [T]keev
232+
Round finished: winnerSide=CT ; score=11:14
204233
[CT]ALEX * Intel <AK-47 (HS)> [T]tiziaN
205234
[CT]xms*ASUS ♥ /F/ <M4A1> [T]syrsoNR
206235
[T]crisby <Tec-9 (HS)> [CT]xms*ASUS ♥ /F/
@@ -210,6 +239,7 @@ This example shows how to use the library to print out all kills including attac
210239
[T]kzy LJ∼ <Galil AR> [CT]Ex6TenZ-BALLISTIX
211240
[CT]to1nou * Seagate <AWP> [T]keev
212241
[T]kzy LJ∼ <AK-47 (HS)> [CT]to1nou * Seagate
242+
Round finished: winnerSide=T ; score=15:11
213243
[T]syrsoNR <AK-47 (HS)> [CT]to1nou * Seagate
214244
[T]tiziaN <Galil AR (HS)> [CT]xms*ASUS ♥ /F/
215245
[CT]ALEX * Intel <FAMAS> [T]tiziaN
@@ -218,15 +248,18 @@ This example shows how to use the library to print out all kills including attac
218248
[CT]ALEX * Intel <FAMAS (HS)> [T]keev
219249
[T]crisby <AK-47> [CT]ALEX * Intel
220250
[CT]mistou * Cooler Master <AK-47 (HS)> [T]crisby
251+
Round finished: winnerSide=CT ; score=12:15
221252
[CT]Ex6TenZ-BALLISTIX <AK-47> [T]keev
222253
[CT]xms*ASUS ♥ /F/ <FAMAS> [T]syrsoNR
223254
[CT]xms*ASUS ♥ /F/ <FAMAS> [T]crisby
224255
[CT]xms*ASUS ♥ /F/ <FAMAS (HS)> [T]tiziaN
225256
[T]kzy LJ∼ <p250> [CT]xms*ASUS ♥ /F/
226257
[CT]mistou * Cooler Master <AWP> [T]kzy LJ∼
258+
Round finished: winnerSide=CT ; score=13:15
227259
[T]tiziaN <Galil AR (HS)> [CT]mistou * Cooler Master
228260
[T]crisby <AK-47 (HS) (WB)> [CT]xms*ASUS ♥ /F/
229261
[T]keev <Tec-9 (HS)> [CT]ALEX * Intel
230262
[T]crisby <AK-47 (HS)> [CT]Ex6TenZ-BALLISTIX
231263
[T]keev <Tec-9> [CT]to1nou * Seagate
264+
Round finished: winnerSide=T ; score=16:13
232265
```

examples/scores/scores.go renamed to examples/print-events/print_events.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
ex "github.com/markus-wa/demoinfocs-golang/examples"
1212
)
1313

14-
// Run like this: go run scores.go -demo /path/to/demo.dem
14+
// Run like this: go run print_events.go -demo /path/to/demo.dem
1515
func main() {
1616
f, err := os.Open(ex.DemoPathFromArgs())
1717
defer f.Close()
@@ -24,6 +24,19 @@ func main() {
2424
checkError(err)
2525
fmt.Println("Map:", h.MapName)
2626

27+
// Register handler on kill events
28+
p.RegisterEventHandler(func(e events.PlayerKilledEvent) {
29+
var hs string
30+
if e.IsHeadshot {
31+
hs = " (HS)"
32+
}
33+
var wallBang string
34+
if e.PenetratedObjects > 0 {
35+
wallBang = " (WB)"
36+
}
37+
fmt.Printf("%s <%v%s%s> %s\n", formatPlayer(e.Killer), e.Weapon.Weapon, hs, wallBang, formatPlayer(e.Victim))
38+
})
39+
2740
// Register handler on round end to figure out who won
2841
p.RegisterEventHandler(func(e events.RoundEndedEvent) {
2942
gs := p.GameState()
@@ -44,6 +57,15 @@ func main() {
4457
checkError(err)
4558
}
4659

60+
func formatPlayer(p *common.Player) string {
61+
switch p.Team {
62+
case common.TeamTerrorists:
63+
return "[T]" + p.Name
64+
case common.TeamCounterTerrorists:
65+
return "[CT]" + p.Name
66+
}
67+
return p.Name
68+
}
4769
func checkError(err error) {
4870
if err != nil {
4971
log.Fatal(err)
File renamed without changes.

0 commit comments

Comments
 (0)