@@ -192,15 +192,15 @@ func (p *parser) bindBombSites() {
192192func (p * parser ) bindPlayers () {
193193 if p .isSource2 () {
194194 p .stParser .ServerClasses ().FindByName ("CCSPlayerPawn" ).OnEntityCreated (func (player st.Entity ) {
195- p .bindNewPlayer (player )
195+ p .bindNewPlayerPawnS2 (player )
196196 })
197197 } else {
198198 p .stParser .ServerClasses ().FindByName ("CCSPlayerResource" ).OnEntityCreated (func (entity st.Entity ) {
199199 p .gameState .playerResourceEntity = entity
200200 })
201201
202202 p .stParser .ServerClasses ().FindByName ("CCSPlayer" ).OnEntityCreated (func (player st.Entity ) {
203- p .bindNewPlayer (player )
203+ p .bindNewPlayerS1 (player )
204204 })
205205 }
206206}
@@ -244,7 +244,7 @@ func (p *parser) getOrCreatePlayer(entityID int, rp *common.PlayerInfo) (isNew b
244244}
245245
246246//nolint:funlen
247- func (p * parser ) bindNewPlayer (playerEntity st.Entity ) {
247+ func (p * parser ) bindNewPlayerS1 (playerEntity st.Entity ) {
248248 entityID := playerEntity .ID ()
249249 rp := p .rawPlayers [entityID - 1 ]
250250
@@ -282,12 +282,96 @@ func (p *parser) bindNewPlayer(playerEntity st.Entity) {
282282 pl .FlashDuration = val .FloatVal
283283 })
284284
285+ p .bindPlayerWeapons (playerEntity , pl ) // FIXME: make weapons work for S2
286+
287+ for i := 0 ; i < 32 ; i ++ {
288+ i2 := i // Copy so it stays the same
289+ playerEntity .BindProperty ("m_iAmmo." + fmt .Sprintf ("%03d" , i2 ), & pl .AmmoLeft [i2 ], st .ValTypeInt )
290+ }
291+
292+ activeWep := playerEntity .Property ("m_hActiveWeapon" )
293+
294+ activeWep .OnUpdate (func (val st.PropertyValue ) {
295+ pl .IsReloading = false
296+ })
297+
298+ playerEntity .Property ("m_bIsDefusing" ).OnUpdate (func (val st.PropertyValue ) {
299+ if p .gameState .currentDefuser == pl && pl .IsDefusing && val .IntVal == 0 {
300+ p .eventDispatcher .Dispatch (events.BombDefuseAborted {Player : pl })
301+ p .gameState .currentDefuser = nil
302+ }
303+
304+ pl .IsDefusing = val .IntVal != 0
305+ })
306+
307+ spottedByMaskProp := playerEntity .Property ("m_bSpottedByMask.000" )
308+ if spottedByMaskProp != nil {
309+ spottersChanged := func (val st.PropertyValue ) {
310+ p .eventDispatcher .Dispatch (events.PlayerSpottersChanged {Spotted : pl })
311+ }
312+
313+ spottedByMaskProp .OnUpdate (spottersChanged )
314+ playerEntity .Property ("m_bSpottedByMask.001" ).OnUpdate (spottersChanged )
315+ }
316+
317+ if isNew {
318+ if pl .SteamID64 != 0 {
319+ p .eventDispatcher .Dispatch (events.PlayerConnect {Player : pl })
320+ } else {
321+ p .eventDispatcher .Dispatch (events.BotConnect {Player : pl })
322+ }
323+ }
324+ }
325+
326+ func (p * parser ) bindNewPlayerPawnS2 (pawnEntity st.Entity ) {
327+ controllerHandle := pawnEntity .Property ("m_hController" ).Value ().Handle ()
328+
329+ controllerEntity := p .gameState .EntityByHandle (controllerHandle )
330+
331+ controllerEntityID := controllerEntity .ID ()
332+
333+ rp := p .rawPlayers [controllerEntityID - 1 ]
334+
335+ isNew , pl := p .getOrCreatePlayer (controllerEntityID , rp )
336+
337+ pl .EntityID = controllerEntityID
338+ pl .Entity = controllerEntity
339+ pl .IsConnected = true
340+
341+ controllerEntity .OnDestroy (func () {
342+ delete (p .gameState .playersByEntityID , controllerEntityID )
343+ pl .Entity = nil
344+ })
345+
346+ // Position
347+ controllerEntity .OnPositionUpdate (func (pos r3.Vector ) {
348+ if pl .IsAlive () {
349+ pl .LastAlivePosition = pos
350+ }
351+ })
352+
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+ })
358+
359+ pawnEntity .Property ("m_flFlashDuration" ).OnUpdate (func (val st.PropertyValue ) {
360+ if val .FloatVal == 0 {
361+ pl .FlashTick = 0
362+ } else {
363+ pl .FlashTick = p .gameState .ingameTick
364+ }
365+
366+ pl .FlashDuration = val .FloatVal
367+ })
368+
285369 if ! p .isSource2 () {
286- p .bindPlayerWeapons (playerEntity , pl ) // FIXME: make weapons work for S2
370+ p .bindPlayerWeapons (controllerEntity , pl ) // FIXME: make weapons work for S2
287371
288372 for i := 0 ; i < 32 ; i ++ {
289373 i2 := i // Copy so it stays the same
290- playerEntity .BindProperty ("m_iAmmo." + fmt .Sprintf ("%03d" , i2 ), & pl .AmmoLeft [i2 ], st .ValTypeInt )
374+ controllerEntity .BindProperty ("m_iAmmo." + fmt .Sprintf ("%03d" , i2 ), & pl .AmmoLeft [i2 ], st .ValTypeInt )
291375 }
292376 }
293377
@@ -297,18 +381,18 @@ func (p *parser) bindNewPlayer(playerEntity st.Entity) {
297381 )
298382
299383 if p .isSource2 () {
300- activeWep = playerEntity .Property ("m_pWeaponServices.m_hActiveWeapon" )
384+ activeWep = pawnEntity .Property ("m_pWeaponServices.m_hActiveWeapon" )
301385 spottedByPrefix = "m_bSpottedByMask.000"
302386 } else {
303- activeWep = playerEntity .Property ("m_hActiveWeapon" )
387+ activeWep = pawnEntity .Property ("m_hActiveWeapon" )
304388 spottedByPrefix = "m_bSpottedByMask.00"
305389 }
306390
307391 activeWep .OnUpdate (func (val st.PropertyValue ) {
308392 pl .IsReloading = false
309393 })
310394
311- playerEntity .Property ("m_bIsDefusing" ).OnUpdate (func (val st.PropertyValue ) {
395+ pawnEntity .Property ("m_bIsDefusing" ).OnUpdate (func (val st.PropertyValue ) {
312396 if p .gameState .currentDefuser == pl && pl .IsDefusing && val .IntVal == 0 {
313397 p .eventDispatcher .Dispatch (events.BombDefuseAborted {Player : pl })
314398 p .gameState .currentDefuser = nil
@@ -317,14 +401,14 @@ func (p *parser) bindNewPlayer(playerEntity st.Entity) {
317401 pl .IsDefusing = val .IntVal != 0
318402 })
319403
320- spottedByMaskProp := playerEntity .Property (spottedByPrefix + "0" )
404+ spottedByMaskProp := pawnEntity .Property (spottedByPrefix + "0" )
321405 if spottedByMaskProp != nil {
322406 spottersChanged := func (val st.PropertyValue ) {
323407 p .eventDispatcher .Dispatch (events.PlayerSpottersChanged {Spotted : pl })
324408 }
325409
326410 spottedByMaskProp .OnUpdate (spottersChanged )
327- playerEntity .Property (spottedByPrefix + "1" ).OnUpdate (spottersChanged )
411+ pawnEntity .Property (spottedByPrefix + "1" ).OnUpdate (spottersChanged )
328412 }
329413
330414 if isNew {
0 commit comments