View Single Post
MeRcyLeZZ
Veteran Member
Join Date: Dec 2007
Old 08-29-2008 , 20:34   Re: How To: Respawn a player
Reply With Quote #19

I've been testing this in both CS and CZ, and I think the best method to respawn dead players (besides using Hamsandwich, of course) is definitely the "DEAD_RESPAWNABLE + THINK" one. I agree there is no need to call it more than once. Also, it doesn't matter what your pev_iuser# values are set to, as long as you're dead.

Using DLLFunc_Spawn on players (or Fun's spawn() native, which is basically the same thing) isn't reliable since you can get different results depending on when it's called, listed below:

Alive
Details: Your dead flag is DEAD_NO (0).
First call: You get teleported to one of your team spawns (info_player_start for CTs, info_player_deathmatch for Terrorists). You don't get stripped from your guns.
Successive calls: Same as first.

Dying
Details: Your dead flag is DEAD_DYING (1) and the death sequence of your model is being played. Your camera points in direction to your attacker.
First call: You do respawn correctly here.
Successive calls: Same as alive.

Died
Details: The camera is still following your attacker, but your dead flag is now DEAD_DEAD (2). Your pev_iuser values are: 2, [victim id], [attacker id], and 0, respectively.
First call: You respawn with the so called "HUD bug". You can't see your crosshair, use the flashlight, nor switch your weapons by using slot1, slot2, etc. Also, you don't get a knife.
Second call: The HUD bug gets fixed, but you still don't have a knife.
Successive calls: Same as alive.

Dead
Details: You have control of your camera to spectate other players. Your dead flag is DEAD_DEAD.
First call: You seem to become alive to the engine, but your camera is still in spectator mode as if you were dead and you can't control yourself. If you switch to Free Look and navigate to where you were supposed to spawn, you'll see a static model in your place. If you wait until the next round, you'll spawn with no weapons at all.
Second call: The aforementioned bug gets fixed and you respawn, but you aren't given any weapons.
Successive calls: Same as alive.

Joining a team for the first time
Details: When you don't spawn right away. Instead, you have to wait for the next round, even though your dead flag is DEAD_RESPAWNABLE (3).
First call: You do respawn correctly, which makes some sense.
Successive calls: Same as alive.

I made several attempts to get the bugs fixed by setting a different dead flag and/or editing the pev_iuser fields of players before calling DLLFunc_Spawn. All to no avail.


To conclude, here's the code I use to respawn players without hamsandwich. Works for human players as well as bots.
Code:
#include <amxmodx> #include <fakemeta> #include <cstrike> new cvar_respawndelay public plugin_init() {     register_plugin("Player", "Respawn", "Test")     register_event("DeathMsg", "event_deathmsg", "a")     cvar_respawndelay = register_cvar("amx_respawndelay", "5.0") // Delay before respawning } public event_deathmsg() {     // read_data(2) = victim     set_task(get_pcvar_float(cvar_respawndelay), "respawn_player", read_data(2)) } public respawn_player(id) {     // Disconnected, already spawned, or switched to Spectator     if (!is_user_connected(id) || is_user_alive(id) || cs_get_user_team(id) == CS_TEAM_SPECTATOR)         return;         // (Debug only)     client_print(0, print_chat, "Player %d is being respawned", id)         // Try to spawn the player setting the appropiate dead flag and forcing a think     set_pev(id, pev_deadflag, DEAD_RESPAWNABLE)     dllfunc(DLLFunc_Think, id)         // Fix for CZ Bots: DLLFunc_Think won't work on them,     // but DLLFunc_Spawn does the job without any bugs.     // (for some reason I'm not suprised...)     if (is_user_bot(id) && pev(id, pev_deadflag) == DEAD_RESPAWNABLE)     {         dllfunc(DLLFunc_Spawn, id)     } }
__________________
MeRcyLeZZ is offline