Source-Python-Dev-Team / Source.Python

This plugin aims to use boost::python and create an easily accessible wrapper around the Source Engine API for scripter use.
http://forums.sourcepython.com
GNU General Public License v3.0
163 stars 31 forks source link

Different behavior for checks that the player is dead in "dod" #476

Closed dronelektron closed 1 year ago

dronelektron commented 1 year ago

Given the following code:

from commands import CommandReturn
from commands.client import ClientCommand
from players import PlayerInfo
from players.entity import Player

@ClientCommand('sp_is_dead')
def is_player_dead(command, index):
    player = Player(index)
    is_dead_1 = player.dead
    is_dead_2 = PlayerInfo.is_dead(player.playerinfo)

    print(f'[DEBUG] Is dead 1 - {is_dead_1}')
    print(f'[DEBUG] Is dead 2 - {is_dead_2}')

    return CommandReturn.BLOCK

Case 1 (Bug?):

  1. I'm alive
  2. Called "sp_is_dead"
  3. Result: is_dead_1 = False, is_dead_2 = False
  4. Killed myself with grenade
  5. Called "sp_is_dead"
  6. Result: is_dead_1 = True, is_dead_2 = False (expected to be True)

Case 2 (OK):

  1. Joined Spectator team
  2. Called "sp_is_dead"
  3. Result: is_dead_1 = True, is_dead_2 = True
CookStar commented 1 year ago

Player.dead returns True when Player.life_state(m_lifeState) is not 0(LIFE_ALIVE), but CBasePlayer::IsDead() and CPlayerInfo::IsDead() return True only when m_lifeState is 2(LIFE_DEAD).

In the above code, PlayerInfo.is_dead returns False because Player.life_state is 1(LIFE_DYING), meaning that the player is not yet completely dead. It should return True when the death animation is finished.

dronelektron commented 1 year ago

Oh, thanks for the explanation, I tested it and it works just like you said