@@ -191,6 +191,9 @@ func (p *parser) bindBombSites() {
191191
192192func (p * parser ) bindPlayers () {
193193 if p .isSource2 () {
194+ p .stParser .ServerClasses ().FindByName ("CCSPlayerController" ).OnEntityCreated (func (player st.Entity ) {
195+ p .bindNewPlayerControllerS2 (player )
196+ })
194197 p .stParser .ServerClasses ().FindByName ("CCSPlayerPawn" ).OnEntityCreated (func (player st.Entity ) {
195198 p .bindNewPlayerPawnS2 (player )
196199 })
@@ -323,11 +326,7 @@ func (p *parser) bindNewPlayerS1(playerEntity st.Entity) {
323326 }
324327}
325328
326- func (p * parser ) bindNewPlayerPawnS2 (pawnEntity st.Entity ) {
327- controllerHandle := pawnEntity .Property ("m_hController" ).Value ().Handle ()
328-
329- controllerEntity := p .gameState .EntityByHandle (controllerHandle )
330-
329+ func (p * parser ) bindNewPlayerControllerS2 (controllerEntity st.Entity ) {
331330 controllerEntityID := controllerEntity .ID ()
332331
333332 rp := p .rawPlayers [controllerEntityID - 1 ]
@@ -350,73 +349,78 @@ func (p *parser) bindNewPlayerPawnS2(pawnEntity st.Entity) {
350349 }
351350 })
352351
353- // General info
354- pawnEntity .Property ("m_iTeamNum" ).OnUpdate (func (val st.PropertyValue ) {
355- pl .Team = common .Team (val .IntVal )
356- pl .TeamState = p .gameState .Team (pl .Team )
357- })
352+ if isNew {
353+ if pl .SteamID64 != 0 {
354+ p .eventDispatcher .Dispatch (events.PlayerConnect {Player : pl })
355+ } else {
356+ p .eventDispatcher .Dispatch (events.BotConnect {Player : pl })
357+ }
358+ }
359+ }
360+
361+ func (p * parser ) bindNewPlayerPawnS2 (pawnEntity st.Entity ) {
362+ player := func () * common.Player {
363+ return p .gameState .Participants ().FindByHandle64 (pawnEntity .PropertyValueMust ("m_hController" ).Handle ())
364+ }
358365
359366 pawnEntity .Property ("m_flFlashDuration" ).OnUpdate (func (val st.PropertyValue ) {
360- if val .FloatVal == 0 {
367+ pl := player ()
368+ if pl == nil {
369+ return
370+ }
371+
372+ if val .Float () == 0 {
361373 pl .FlashTick = 0
362374 } else {
363375 pl .FlashTick = p .gameState .ingameTick
364376 }
365377
366- pl .FlashDuration = val .FloatVal
378+ pl .FlashDuration = val .Float ()
367379 })
368380
369- if ! p .isSource2 () {
370- p .bindPlayerWeapons (controllerEntity , pl ) // FIXME: make weapons work for S2
371-
372- for i := 0 ; i < 32 ; i ++ {
373- i2 := i // Copy so it stays the same
374- controllerEntity .BindProperty ("m_iAmmo." + fmt .Sprintf ("%03d" , i2 ), & pl .AmmoLeft [i2 ], st .ValTypeInt )
381+ //p.bindPlayerWeapons(controllerEntity, pl) // FIXME: make weapons work for S2
382+ //
383+ //for i := 0; i < 32; i++ {
384+ // i2 := i // Copy so it stays the same
385+ // controllerEntity.BindProperty("m_iAmmo."+fmt.Sprintf("%03d", i2), &pl.AmmoLeft[i2], st.ValTypeInt)
386+ //}
387+
388+ pawnEntity .Property ("m_pWeaponServices.m_hActiveWeapon" ).OnUpdate (func (val st.PropertyValue ) {
389+ pl := player ()
390+ if pl == nil {
391+ return
375392 }
376- }
377-
378- var (
379- activeWep st.Property
380- spottedByPrefix string
381- )
382393
383- if p .isSource2 () {
384- activeWep = pawnEntity .Property ("m_pWeaponServices.m_hActiveWeapon" )
385- spottedByPrefix = "m_bSpottedByMask.000"
386- } else {
387- activeWep = pawnEntity .Property ("m_hActiveWeapon" )
388- spottedByPrefix = "m_bSpottedByMask.00"
389- }
390-
391- activeWep .OnUpdate (func (val st.PropertyValue ) {
392394 pl .IsReloading = false
393395 })
394396
395397 pawnEntity .Property ("m_bIsDefusing" ).OnUpdate (func (val st.PropertyValue ) {
396- if p .gameState .currentDefuser == pl && pl .IsDefusing && val .IntVal == 0 {
398+ pl := player ()
399+ if pl == nil {
400+ return
401+ }
402+
403+ if p .gameState .currentDefuser == pl && pl .IsDefusing && ! val .BoolVal () {
397404 p .eventDispatcher .Dispatch (events.BombDefuseAborted {Player : pl })
398405 p .gameState .currentDefuser = nil
399406 }
400407
401- pl .IsDefusing = val .IntVal != 0
408+ pl .IsDefusing = val .BoolVal ()
402409 })
403410
404- spottedByMaskProp := pawnEntity .Property (spottedByPrefix + "0 " )
411+ spottedByMaskProp := pawnEntity .Property ("m_bSpottedByMask.0000 " )
405412 if spottedByMaskProp != nil {
413+ pl := player ()
414+ if pl == nil {
415+ return
416+ }
417+
406418 spottersChanged := func (val st.PropertyValue ) {
407419 p .eventDispatcher .Dispatch (events.PlayerSpottersChanged {Spotted : pl })
408420 }
409421
410422 spottedByMaskProp .OnUpdate (spottersChanged )
411- pawnEntity .Property (spottedByPrefix + "1" ).OnUpdate (spottersChanged )
412- }
413-
414- if isNew {
415- if pl .SteamID64 != 0 {
416- p .eventDispatcher .Dispatch (events.PlayerConnect {Player : pl })
417- } else {
418- p .eventDispatcher .Dispatch (events.BotConnect {Player : pl })
419- }
423+ pawnEntity .Property ("m_bSpottedByMask.0001" ).OnUpdate (spottersChanged )
420424 }
421425}
422426
0 commit comments