Skip to content

Commit 05dfc93

Browse files
zyphiemarkus-wa
authored andcommitted
NadeEvent: Use entity id instead of entity (#23)
The entity is sometimes already destoryed (e.g. molotov)
1 parent 4ad2df3 commit 05dfc93

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

events/events.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ 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"
109
)
1110

1211
// HeaderParsedEvent signals that the header has been parsed.
@@ -113,10 +112,10 @@ type NadeEventIf interface {
113112
// NadeEvent contains the common attributes of nade events. Dont register
114113
// handlers on this tho, you want NadeEventIf for that
115114
type NadeEvent struct {
116-
NadeType common.EquipmentElement
117-
Position r3.Vector
118-
Thrower *common.Player
119-
NadeEntity *st.Entity
115+
NadeType common.EquipmentElement
116+
Position r3.Vector
117+
Thrower *common.Player
118+
NadeEntityID int
120119
}
121120

122121
// Make NadeEvents implement NadeEventIf

game_events.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ 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"
1312
)
1413

1514
func (p *Parser) handleGameEventList(gel *msg.CSVCMsg_GameEventList) {
@@ -182,32 +181,32 @@ func (p *Parser) handleGameEvent(ge *msg.CSVCMsg_GameEvent) {
182181
Y: float64(data["y"].ValFloat),
183182
Z: float64(data["z"].ValFloat),
184183
}
185-
nadeEntity := p.entities[int(data["entityid"].GetValShort())]
184+
nadeEntityID := int(data["entityid"].GetValShort())
186185

187186
switch d.Name {
188187
case "flashbang_detonate": // Flash exploded
189-
p.eventDispatcher.Dispatch(events.FlashExplodedEvent{NadeEvent: buildNadeEvent(common.EqFlash, thrower, position, nadeEntity)})
188+
p.eventDispatcher.Dispatch(events.FlashExplodedEvent{NadeEvent: buildNadeEvent(common.EqFlash, thrower, position, nadeEntityID)})
190189

191190
case "hegrenade_detonate": // HE exploded
192-
p.eventDispatcher.Dispatch(events.HeExplodedEvent{NadeEvent: buildNadeEvent(common.EqHE, thrower, position, nadeEntity)})
191+
p.eventDispatcher.Dispatch(events.HeExplodedEvent{NadeEvent: buildNadeEvent(common.EqHE, thrower, position, nadeEntityID)})
193192

194193
case "decoy_started": // Decoy started
195-
p.eventDispatcher.Dispatch(events.DecoyStartEvent{NadeEvent: buildNadeEvent(common.EqDecoy, thrower, position, nadeEntity)})
194+
p.eventDispatcher.Dispatch(events.DecoyStartEvent{NadeEvent: buildNadeEvent(common.EqDecoy, thrower, position, nadeEntityID)})
196195

197196
case "decoy_detonate": // Decoy exploded/expired
198-
p.eventDispatcher.Dispatch(events.DecoyEndEvent{NadeEvent: buildNadeEvent(common.EqDecoy, thrower, position, nadeEntity)})
197+
p.eventDispatcher.Dispatch(events.DecoyEndEvent{NadeEvent: buildNadeEvent(common.EqDecoy, thrower, position, nadeEntityID)})
199198

200199
case "smokegrenade_detonate": // Smoke popped
201-
p.eventDispatcher.Dispatch(events.SmokeStartEvent{NadeEvent: buildNadeEvent(common.EqSmoke, thrower, position, nadeEntity)})
200+
p.eventDispatcher.Dispatch(events.SmokeStartEvent{NadeEvent: buildNadeEvent(common.EqSmoke, thrower, position, nadeEntityID)})
202201

203202
case "smokegrenade_expired": // Smoke expired
204-
p.eventDispatcher.Dispatch(events.SmokeEndEvent{NadeEvent: buildNadeEvent(common.EqSmoke, thrower, position, nadeEntity)})
203+
p.eventDispatcher.Dispatch(events.SmokeEndEvent{NadeEvent: buildNadeEvent(common.EqSmoke, thrower, position, nadeEntityID)})
205204

206205
case "inferno_startburn": // Incendiary exploded/started
207-
p.eventDispatcher.Dispatch(events.FireNadeStartEvent{NadeEvent: buildNadeEvent(common.EqIncendiary, thrower, position, nadeEntity)})
206+
p.eventDispatcher.Dispatch(events.FireNadeStartEvent{NadeEvent: buildNadeEvent(common.EqIncendiary, thrower, position, nadeEntityID)})
208207

209208
case "inferno_expire": // Incendiary expired
210-
p.eventDispatcher.Dispatch(events.FireNadeEndEvent{NadeEvent: buildNadeEvent(common.EqIncendiary, thrower, position, nadeEntity)})
209+
p.eventDispatcher.Dispatch(events.FireNadeEndEvent{NadeEvent: buildNadeEvent(common.EqIncendiary, thrower, position, nadeEntityID)})
211210
}
212211

213212
case "player_connect": // Bot connected or player reconnected, players normally come in via string tables & data tables
@@ -448,12 +447,12 @@ func mapGameEventData(d *msg.CSVCMsg_GameEventListDescriptorT, e *msg.CSVCMsg_Ga
448447
}
449448

450449
// Just so we can nicely create NadeEvents in one line
451-
func buildNadeEvent(nadeType common.EquipmentElement, thrower *common.Player, position r3.Vector, nadeEntity *st.Entity) events.NadeEvent {
450+
func buildNadeEvent(nadeType common.EquipmentElement, thrower *common.Player, position r3.Vector, nadeEntityID int) events.NadeEvent {
452451
return events.NadeEvent{
453-
NadeType: nadeType,
454-
Thrower: thrower,
455-
Position: position,
456-
NadeEntity: nadeEntity,
452+
NadeType: nadeType,
453+
Thrower: thrower,
454+
Position: position,
455+
NadeEntityID: nadeEntityID,
457456
}
458457
}
459458

0 commit comments

Comments
 (0)