Skip to content

Commit 9a92f18

Browse files
committed
Clean up alt weapon detection
1 parent c8598f3 commit 9a92f18

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

datatables.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,26 +329,27 @@ func (p *Parser) bindWeapon(event st.EntityCreatedEvent) {
329329

330330
event.Entity.BindProperty("LocalWeaponData.m_iPrimaryAmmoType", &eq.AmmoType, st.ValTypeInt)
331331

332-
wepFix := func(ok string, change string, changer func()) {
332+
// Detect alternative weapons (P2k -> USP, M4A4 -> M4A1-S etc.)
333+
wepFix := func(defaultName, altName string, alt common.EquipmentElement) {
333334
event.Entity.FindProperty("m_nModelIndex").OnUpdate(func(val st.PropValue) {
334335
eq.OriginalString = p.modelPreCache[val.IntVal]
335-
// Check 'change' first because otherwise the m4a1_s is recognized as m4a4
336-
if strings.Contains(eq.OriginalString, change) {
337-
changer()
338-
} else if !strings.Contains(eq.OriginalString, ok) {
336+
// Check 'altName' first because otherwise the m4a1_s is recognized as m4a4
337+
if strings.Contains(eq.OriginalString, altName) {
338+
eq.Weapon = alt
339+
} else if !strings.Contains(eq.OriginalString, defaultName) {
339340
panic(fmt.Sprintf("Unknown weapon model %q", eq.OriginalString))
340341
}
341342
})
342343
}
343344

344345
switch eq.Weapon {
345346
case common.EqP2000:
346-
wepFix("_pist_hkp2000", "_pist_223", func() { eq.Weapon = common.EqUSP })
347+
wepFix("_pist_hkp2000", "_pist_223", common.EqUSP)
347348
case common.EqM4A4:
348-
wepFix("_rif_m4a1", "_rif_m4a1_s", func() { eq.Weapon = common.EqM4A1 })
349+
wepFix("_rif_m4a1", "_rif_m4a1_s", common.EqM4A1)
349350
case common.EqP250:
350-
wepFix("_pist_p250", "_pist_cz_75", func() { eq.Weapon = common.EqCZ })
351+
wepFix("_pist_p250", "_pist_cz_75", common.EqCZ)
351352
case common.EqDeagle:
352-
wepFix("_pist_deagle", "_pist_revolver", func() { eq.Weapon = common.EqRevolver })
353+
wepFix("_pist_deagle", "_pist_revolver", common.EqRevolver)
353354
}
354355
}

0 commit comments

Comments
 (0)