Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate ply:Alive() #1450

Open
TimGoll opened this issue Mar 3, 2024 · 10 comments
Open

Investigate ply:Alive() #1450

TimGoll opened this issue Mar 3, 2024 · 10 comments
Labels
type/rework Big changes or overhaul of an existing feature

Comments

@TimGoll
Copy link
Member

TimGoll commented Mar 3, 2024

In our code base we sometimes check if a player is alive: https://github.com/search?q=repo%3ATTT-2%2FTTT2%20%3AAlive()&type=code

However I'm not sure there is any scenario where a player isn't alive. Spectators are counted as alive as well, therefore we differentiate with IsTerror and IsSpec.

This should be investigated, maybe we can get rid of all Alive checks. We also have quite a few places where we explicitly check the team for TEAM_TERROR or TEAM_SPEC. I think we should replace those with IsTerror and IsSpec

@TimGoll
Copy link
Member Author

TimGoll commented Mar 3, 2024

Looking at the wiki it looks like a player can indeed be dead: https://wiki.facepunch.com/gmod/Player:Alive

However this might be overwritten in TTT to keep spectators alive as well?

@Histalek
Copy link
Member

Histalek commented Mar 3, 2024

Would a disconnected player still be "alive"? maybe this check is needed in some places?

@TimGoll
Copy link
Member Author

TimGoll commented Mar 3, 2024

It seems like we do kill players in TTT2, but we respawn them in the same tick again

Example: player changes to being a forced spec:

if not ply:IsSpec() then
ply:Kill()
end
GAMEMODE:PlayerSpawnAsSpectator(ply)
ply:SetTeam(TEAM_SPEC)
ply:SetForceSpec(true)
ply:Spawn()

@TimGoll
Copy link
Member Author

TimGoll commented Mar 3, 2024

Would a disconnected player still be "alive"? maybe this check is needed in some places?

I don't think so, because a disconnected player is a "NULL ENT"

@TimGoll
Copy link
Member Author

TimGoll commented Mar 3, 2024

Stuff worth looking at:

@TimGoll
Copy link
Member Author

TimGoll commented Mar 3, 2024

So I get the hunch that there are scenarios where a player is not alive, because the wiki says Alive will return false in DoPlayerDeath. But it seems like we respawn the player as a spec immediately and only set the team? I'm a bit confused because I'm unable to locate this in the code base

@TimGoll
Copy link
Member Author

TimGoll commented Mar 3, 2024

This is all I'm able to find, here is the team updated from TERROR to SPEC. But a Spawn is never called, so a player should still be counted dead, so Alive should return false? I'm really confused and I have to test this in-game at some point:

victim:SetTeam(TEAM_SPEC)
victim:Freeze(false)
victim:SetRagdollSpec(true)
victim:Spectate(OBS_MODE_IN_EYE)

@TimGoll TimGoll added the type/rework Big changes or overhaul of an existing feature label Mar 3, 2024
@mexikoedi
Copy link
Contributor

mexikoedi commented Mar 3, 2024

It could be worth looking into the IsActive() check as well.
Alive players in an active round so it cannot be a spectator or a dead player.
Could be used in some places to simplify the code instead of using IsTerror() and IsSpec() checks.
See here: https://github.com/Facepunch/garrysmod/blob/61cb86af65daa454e0d879be78bc9b40fe956ce2/garrysmod/gamemodes/terrortown/gamemode/player_ext_shd.lua#L23

@TimGoll
Copy link
Member Author

TimGoll commented Mar 3, 2024

But IsActive only checks IsTerror and if it is an active round. So I don't think there are many places in our code base where this could be simplified

@EntranceJew
Copy link
Contributor

This is all I'm able to find, here is the team updated from TERROR to SPEC. But a Spawn is never called, so a player should still be counted dead, so Alive should return false? I'm really confused and I have to test this in-game at some point:

victim:SetTeam(TEAM_SPEC)
victim:Freeze(false)
victim:SetRagdollSpec(true)
victim:Spectate(OBS_MODE_IN_EYE)

This is accurate, all the shuffling happens immediately after death, and in a confusingly named "respawnforround" function, in the snippet you cited:
That :Freeze(false) should be skipped if the player is a bot, as it enables valve-bots to wander out of the map boundaries -- to be consistent with the other places the player is being frozen

@Histalek Histalek added this to the Feature Backlog milestone May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/rework Big changes or overhaul of an existing feature
Projects
None yet
Development

No branches or pull requests

4 participants