@@ -456,12 +456,34 @@ func (p *parser) bindNewPlayerS1(playerEntity st.Entity) {
456456 }
457457}
458458
459- func (p * parser ) bindNewPlayerControllerS2 (controllerEntity st.Entity ) {
459+ func (p * parser ) getOrCreatePlayerFromControllerEntity (controllerEntity st.Entity ) * common. Player {
460460 controllerEntityID := controllerEntity .ID ()
461461 p .gameState .playerControllerEntities [controllerEntityID ] = controllerEntity
462462
463+ rp := p .rawPlayers [controllerEntityID - 1 ]
464+ _ , player := p .getOrCreatePlayer (controllerEntityID , rp )
465+ player .Entity = controllerEntity
466+ player .EntityID = controllerEntityID
467+ player .IsBot = controllerEntity .PropertyValueMust ("m_steamID" ).String () == "0"
468+
469+ if player .IsBot {
470+ player .Name = controllerEntity .PropertyValueMust ("m_iszPlayerName" ).String ()
471+ player .IsUnknown = false
472+ }
473+
474+ return player
475+ }
476+
477+ func (p * parser ) bindNewPlayerControllerS2 (controllerEntity st.Entity ) {
478+ pl := p .getOrCreatePlayerFromControllerEntity (controllerEntity )
479+
480+ controllerEntity .Property ("m_iTeamNum" ).OnUpdate (func (val st.PropertyValue ) {
481+ pl .Team = common .Team (val .S2UInt64 ())
482+ pl .TeamState = p .gameState .Team (pl .Team )
483+ })
484+
463485 controllerEntity .OnDestroy (func () {
464- delete (p .gameState .playersByEntityID , controllerEntityID )
486+ delete (p .gameState .playersByEntityID , controllerEntity . ID () )
465487 })
466488}
467489
@@ -474,17 +496,8 @@ func (p *parser) bindNewPlayerPawnS2(pawnEntity st.Entity) {
474496 controllerEntityID := int (controllerHandle & constants .EntityHandleIndexMaskSource2 )
475497 controllerEntity := p .gameState .playerControllerEntities [controllerEntityID ]
476498
477- rp := p .rawPlayers [controllerEntityID - 1 ]
478- _ , pl := p .getOrCreatePlayer (controllerEntityID , rp )
479- pl .Entity = controllerEntity
480- pl .EntityID = controllerEntity .ID ()
499+ pl := p .getOrCreatePlayerFromControllerEntity (controllerEntity )
481500 pl .IsConnected = true
482- pl .IsBot = controllerEntity .PropertyValueMust ("m_steamID" ).String () == "0"
483-
484- if pl .IsBot {
485- pl .Name = controllerEntity .PropertyValueMust ("m_iszPlayerName" ).String ()
486- pl .IsUnknown = false
487- }
488501
489502 if pl .SteamID64 != 0 {
490503 p .eventDispatcher .Dispatch (events.PlayerConnect {Player : pl })
@@ -499,11 +512,6 @@ func (p *parser) bindNewPlayerPawnS2(pawnEntity st.Entity) {
499512 }
500513 })
501514
502- pawnEntity .Property ("m_iTeamNum" ).OnUpdate (func (val st.PropertyValue ) {
503- pl .Team = common .Team (val .S2UInt64 ())
504- pl .TeamState = p .gameState .Team (pl .Team )
505- })
506-
507515 pawnEntity .Property ("m_flFlashDuration" ).OnUpdate (func (val st.PropertyValue ) {
508516
509517 if val .Float () == 0 {
0 commit comments