Bug 3752 - cs_user_spawn() native does not properly respawn players
cs_user_spawn() native does not properly respawn players
Status: RESOLVED FIXED
Product: AMX Mod X
Classification: Unclassified
Component: Addon: Counter-Strike
trunk
PC All
: P3 minor
Assigned To: amxmodx-bugs@alliedmods.net
: needscheckin
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-03-22 19:35 PDT by WiLS (MeRcyLeZZ)
Modified: 2014-02-08 23:51 PST (History)
3 users (show)

See Also:


Attachments
Fix for cs_user_spawn (596 bytes, patch)
2010-12-20 11:49 PST, Reuben Morais
no flags Details | Diff | Splinter Review
Corrected proposed path (655 bytes, patch)
2011-03-25 18:38 PDT, Vincent Herbet [:Arkshine]
dvander: review+
joropito: review+
Details | Diff | Splinter Review

Description WiLS (MeRcyLeZZ) 2009-03-22 19:35:31 PDT
Note: The same bug applies to the fm_cs_user_spawn() stock from fakemeta_util.inc, which is based on the same code.

Description:
If you try to use this native to respawn a player some time after he dies, he may spawn with the so-called HUD bug (basically the player can't see the crosshair, use the flashlight, or change weapons) or he may not spawn at all and a player "ghost" (static player model floating in the air) may appear on the map.

These bugs are caused because the code is incorrectly using the "DEAD_RESPAWNABLE + DLLFunc_Spawn" method.

Here's a post explaining the details and a simple solution:
http://forums.alliedmods.net/showpost.php?p=678294&postcount=19

Here's an alternate solution posted on the same thread:
http://forums.alliedmods.net/showpost.php?p=681963&postcount=21
Comment 1 Reuben Morais 2010-12-20 11:49:34 PST
Created attachment 2479 [details] [review]
Fix for cs_user_spawn

Builds fine, not tested.
Comment 2 Vincent Herbet [:Arkshine] 2010-12-21 09:19:09 PST
Compiled and tested successfully on : CS 1.6 + Podbots and CZ + CS bots.

Here the small plugin used to test : http://pastebin.com/UkpxHJzd
Comment 3 WiLS (MeRcyLeZZ) 2010-12-21 14:37:20 PST
Thanks, let me just point out a small thing you missed. When checking whether it's a CZ Bot you also need to check that their deadflag is still set to DEAD_RESPAWNABLE: (this makes sure it's a bot that definitely hasn't respawned yet)

if (is_user_bot(id) && pev(id, pev_deadflag) == DEAD_RESPAWNABLE)
	dllfunc(DLLFunc_Spawn, id)


So the code for the fix should be:

+	if (((pPlayer->v.flags & FL_FAKECLIENT) == FL_FAKECLIENT) || (auth && (strcmp(auth, "BOT") == 0))) && (pPlayer->v.deadflag == DEAD_RESPAWNABLE) {
+		MDLL_Spawn(pPlayer);
Comment 4 Vincent Herbet [:Arkshine] 2010-12-21 15:43:04 PST
The flag DEAD_RESPAWNABLE is set before, so this check is not needed.
Comment 5 WiLS (MeRcyLeZZ) 2010-12-21 17:50:07 PST
Yes, the flag is set before. However after calling MDLL_Think(pPlayer), if the bot is successfully respawned, the flag is set to a different value (DEAD_NO). In that case, it means it wasn't a CZ Bot and we don't really need to call MDLL_Spawn(pPlayer).

It's really not such a big deal. Calling MDLL_Spawn on a bot that is already alive is pretty much harmless (he would just appear to spawn twice). I'd figure if we are fixing this, better get it right though.
Comment 6 Vincent Herbet [:Arkshine] 2010-12-21 18:31:27 PST
Ok, thanks for the information. I will try myself though, I would like to understand better and if I get the same behavior. 

Btw, I was wondering why Think() doesn't work on CZ bots, so I've tried to look into the CS code without real success. CBot:Killed() calls directly CBasePlayer::Killed() so SetThink( &CBasePlayer::PlayerDeathThink ) should be called well on CZ bots. Weird. Will try look further.
Comment 7 David Anderson [:dvander] 2011-03-25 16:16:31 PDT
Comment on attachment 2479 [details] [review]
Fix for cs_user_spawn

Not tested?
Comment 8 Vincent Herbet [:Arkshine] 2011-03-25 18:38:39 PDT
Created attachment 2559 [details] [review]
Corrected proposed path

This patch adds the missing check as stated by wils.

Compiled and tested successfully on CS1.6 (+podbots) and CS:CZ (+CS bots).
Comment 9 David Anderson [:dvander] 2013-02-13 01:26:28 PST
Going to pass on this for 1.8.2 - the patch honestly looks fine, but I'm pretty nervous about compatibility issues. We should take this as soon as we branch for 1.8.3.
Comment 10 Vincent Herbet [:Arkshine] 2013-02-13 10:06:00 PST
What compatibility issues do you have in mind ? I think there is no problems about this one. No matter how people have used this native until now, the result will the same without the glitches. About the method itself, it's what uses CS when a player dies. It sounds like safe for me.
Comment 11 Vincent Herbet [:Arkshine] 2013-06-15 14:02:16 PDT
Comment on attachment 2559 [details] [review]
Corrected proposed path

Reviewed and checked again. The way it's used currently will not be an an issue after this patch. Also, honestly there is no more plugin using this old native because was buggy. Asking joropito's thoughts.
Comment 12 joropito 2013-06-15 14:06:49 PDT
Comment on attachment 2559 [details] [review]
Corrected proposed path

Review of attachment 2559 [details] [review]:
-----------------------------------------------------------------

I don't see any compatibility problem with this patch
Comment 13 Vincent Herbet [:Arkshine] 2013-06-15 14:39:20 PDT
Pushed changeset: http://hg.alliedmods.net/amxmodx-central/rev/97c16eba7134
Changelog:
	Fix cs_user_spawn to properly respawn players (bug 3752, r=dvander)
Comment 14 AM Bugzilla Bot 2014-02-08 23:51:54 PST
Commit pushed to master at https://github.com/alliedmodders/amxmodx

https://github.com/alliedmodders/amxmodx/commit/f606adfa698ca724e5fd0dff37799b58f0663f82
Fix cs_user_spawn to properly respawn players (bug 3752, r=dvander)


Former-commit-id: 3bae515741f59ca9679cbacc1f81dce6734fa67b

Note You need to log in before you can comment on or make changes to this bug.