@@ -456,12 +456,34 @@ func (p *parser) bindNewPlayerS1(playerEntity st.Entity) {
456
456
}
457
457
}
458
458
459
- func (p * parser ) bindNewPlayerControllerS2 (controllerEntity st.Entity ) {
459
+ func (p * parser ) getOrCreatePlayerFromControllerEntity (controllerEntity st.Entity ) * common. Player {
460
460
controllerEntityID := controllerEntity .ID ()
461
461
p .gameState .playerControllerEntities [controllerEntityID ] = controllerEntity
462
462
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
+
463
485
controllerEntity .OnDestroy (func () {
464
- delete (p .gameState .playersByEntityID , controllerEntityID )
486
+ delete (p .gameState .playersByEntityID , controllerEntity . ID () )
465
487
})
466
488
}
467
489
@@ -474,17 +496,8 @@ func (p *parser) bindNewPlayerPawnS2(pawnEntity st.Entity) {
474
496
controllerEntityID := int (controllerHandle & constants .EntityHandleIndexMaskSource2 )
475
497
controllerEntity := p .gameState .playerControllerEntities [controllerEntityID ]
476
498
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 )
481
500
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
- }
488
501
489
502
if pl .SteamID64 != 0 {
490
503
p .eventDispatcher .Dispatch (events.PlayerConnect {Player : pl })
@@ -499,11 +512,6 @@ func (p *parser) bindNewPlayerPawnS2(pawnEntity st.Entity) {
499
512
}
500
513
})
501
514
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
-
507
515
pawnEntity .Property ("m_flFlashDuration" ).OnUpdate (func (val st.PropertyValue ) {
508
516
509
517
if val .Float () == 0 {
0 commit comments