@@ -329,26 +329,27 @@ func (p *Parser) bindWeapon(event st.EntityCreatedEvent) {
329
329
330
330
event .Entity .BindProperty ("LocalWeaponData.m_iPrimaryAmmoType" , & eq .AmmoType , st .ValTypeInt )
331
331
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 ) {
333
334
event .Entity .FindProperty ("m_nModelIndex" ).OnUpdate (func (val st.PropValue ) {
334
335
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 ) {
339
340
panic (fmt .Sprintf ("Unknown weapon model %q" , eq .OriginalString ))
340
341
}
341
342
})
342
343
}
343
344
344
345
switch eq .Weapon {
345
346
case common .EqP2000 :
346
- wepFix ("_pist_hkp2000" , "_pist_223" , func () { eq . Weapon = common .EqUSP } )
347
+ wepFix ("_pist_hkp2000" , "_pist_223" , common .EqUSP )
347
348
case common .EqM4A4 :
348
- wepFix ("_rif_m4a1" , "_rif_m4a1_s" , func () { eq . Weapon = common .EqM4A1 } )
349
+ wepFix ("_rif_m4a1" , "_rif_m4a1_s" , common .EqM4A1 )
349
350
case common .EqP250 :
350
- wepFix ("_pist_p250" , "_pist_cz_75" , func () { eq . Weapon = common .EqCZ } )
351
+ wepFix ("_pist_p250" , "_pist_cz_75" , common .EqCZ )
351
352
case common .EqDeagle :
352
- wepFix ("_pist_deagle" , "_pist_revolver" , func () { eq . Weapon = common .EqRevolver } )
353
+ wepFix ("_pist_deagle" , "_pist_revolver" , common .EqRevolver )
353
354
}
354
355
}
0 commit comments