Skip to content

Commit cce2692

Browse files
committed
Add entity to NadeEvent
1 parent 4080117 commit cce2692

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

events/events.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
common "github.com/markus-wa/demoinfocs-golang/common"
88
msg "github.com/markus-wa/demoinfocs-golang/msg"
9+
st "github.com/markus-wa/demoinfocs-golang/sendtables"
910
)
1011

1112
// HeaderParsedEvent signals that the header has been parsed.
@@ -115,6 +116,7 @@ type NadeEvent struct {
115116
NadeType common.EquipmentElement
116117
Position r3.Vector
117118
Thrower *common.Player
119+
Entity *st.Entity
118120
}
119121

120122
// Make NadeEvents implement NadeEventIf

game_events.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
common "github.com/markus-wa/demoinfocs-golang/common"
1010
events "github.com/markus-wa/demoinfocs-golang/events"
1111
msg "github.com/markus-wa/demoinfocs-golang/msg"
12+
st "github.com/markus-wa/demoinfocs-golang/sendtables"
1213
)
1314

1415
func (p *Parser) handleGameEventList(gel *msg.CSVCMsg_GameEventList) {
@@ -197,31 +198,32 @@ func (p *Parser) handleGameEvent(ge *msg.CSVCMsg_GameEvent) {
197198
Y: float64(data["y"].ValFloat),
198199
Z: float64(data["z"].ValFloat),
199200
}
201+
entity := p.entities[int(data["entityid"].GetValShort())]
200202

201203
switch d.Name {
202204
case "flashbang_detonate": // Flash exploded
203-
p.eventDispatcher.Dispatch(events.FlashExplodedEvent{NadeEvent: buildNadeEvent(common.EqFlash, thrower, position)})
205+
p.eventDispatcher.Dispatch(events.FlashExplodedEvent{NadeEvent: buildNadeEvent(common.EqFlash, thrower, position, entity)})
204206

205207
case "hegrenade_detonate": // HE exploded
206-
p.eventDispatcher.Dispatch(events.HeExplodedEvent{NadeEvent: buildNadeEvent(common.EqHE, thrower, position)})
208+
p.eventDispatcher.Dispatch(events.HeExplodedEvent{NadeEvent: buildNadeEvent(common.EqHE, thrower, position, entity)})
207209

208210
case "decoy_started": // Decoy started
209-
p.eventDispatcher.Dispatch(events.DecoyStartEvent{NadeEvent: buildNadeEvent(common.EqDecoy, thrower, position)})
211+
p.eventDispatcher.Dispatch(events.DecoyStartEvent{NadeEvent: buildNadeEvent(common.EqDecoy, thrower, position, entity)})
210212

211213
case "decoy_detonate": // Decoy exploded/expired
212-
p.eventDispatcher.Dispatch(events.DecoyEndEvent{NadeEvent: buildNadeEvent(common.EqDecoy, thrower, position)})
214+
p.eventDispatcher.Dispatch(events.DecoyEndEvent{NadeEvent: buildNadeEvent(common.EqDecoy, thrower, position, entity)})
213215

214216
case "smokegrenade_detonate": // Smoke popped
215-
p.eventDispatcher.Dispatch(events.SmokeStartEvent{NadeEvent: buildNadeEvent(common.EqSmoke, thrower, position)})
217+
p.eventDispatcher.Dispatch(events.SmokeStartEvent{NadeEvent: buildNadeEvent(common.EqSmoke, thrower, position, entity)})
216218

217219
case "smokegrenade_expired": // Smoke expired
218-
p.eventDispatcher.Dispatch(events.SmokeEndEvent{NadeEvent: buildNadeEvent(common.EqSmoke, thrower, position)})
220+
p.eventDispatcher.Dispatch(events.SmokeEndEvent{NadeEvent: buildNadeEvent(common.EqSmoke, thrower, position, entity)})
219221

220222
case "inferno_startburn": // Incendiary exploded/started
221-
p.eventDispatcher.Dispatch(events.FireNadeStartEvent{NadeEvent: buildNadeEvent(common.EqIncendiary, thrower, position)})
223+
p.eventDispatcher.Dispatch(events.FireNadeStartEvent{NadeEvent: buildNadeEvent(common.EqIncendiary, thrower, position, entity)})
222224

223225
case "inferno_expire": // Incendiary expired
224-
p.eventDispatcher.Dispatch(events.FireNadeEndEvent{NadeEvent: buildNadeEvent(common.EqIncendiary, thrower, position)})
226+
p.eventDispatcher.Dispatch(events.FireNadeEndEvent{NadeEvent: buildNadeEvent(common.EqIncendiary, thrower, position, entity)})
225227
}
226228

227229
case "player_connect": // Bot connected, players come in via string tables & data tables
@@ -449,11 +451,12 @@ func mapGameEventData(d *msg.CSVCMsg_GameEventListDescriptorT, e *msg.CSVCMsg_Ga
449451
}
450452

451453
// Just so we can nicely create NadeEvents in one line
452-
func buildNadeEvent(nadeType common.EquipmentElement, thrower *common.Player, position r3.Vector) events.NadeEvent {
454+
func buildNadeEvent(nadeType common.EquipmentElement, thrower *common.Player, position r3.Vector, entity *st.Entity) events.NadeEvent {
453455
return events.NadeEvent{
454456
NadeType: nadeType,
455457
Thrower: thrower,
456458
Position: position,
459+
Entity: entity,
457460
}
458461
}
459462

0 commit comments

Comments
 (0)