AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   How To: Respawn a player (https://forums.alliedmods.net/showthread.php?t=76179)

GHW_Chronic 08-19-2008 18:51

How To: Respawn a player
 
  • I have seen many people struggle with this and am myself one of them (this effort was actually for the respawn portion of my CTF). I decided to finally figure out the perfect way to spawn a player in pawn and here is what I have come up with.



Code:
#include <fun> #include <fakemeta> //Call This public respawn_player(id) {     if(is_user_connected(id))     {         //Make the engine think he is spawning         set_pev(id,pev_deadflag,DEAD_RESPAWNABLE);         set_pev(id, pev_iuser1, 0);         dllfunc(DLLFunc_Think,id)         //Move his body so if corpse is created it is not in map         engfunc(EngFunc_SetOrigin,id,Float:{-4800.0,-4800.0,-4800.0})         //Actual Spawn         set_task(0.5,"spawnagain",id)     } } public spawnagain(id) {     //Make sure he didn't disconnect in the 0.5 seconds that have passed.     if(is_user_connected(id))     {         //Spawn player         spawn(id)         dllfunc(DLLFunc_Spawn,id)         //After 1.0 the player will be spawned fully and you can mess with the ent (give weapons etc)         //set_task(1.0,"player_fully_spawned",id)     } }

danielkza 08-19-2008 18:54

Re: How To: Respawn a player
 
Better way, for CS at least:

ExecuteHamB(Ham_CS_RoundRespawn,player)

GHW_Chronic 08-19-2008 19:06

Re: How To: Respawn a player
 
offtopic: honestly HAM is a blessing but I really don't want to use it because 50% of the servers I play in use 1.76d.

Orangutanz 08-19-2008 21:12

Re: How To: Respawn a player
 
All you need to respawn a player is this:
Code:
set_pev( id, pev_deadflag, DEAD_RESPAWNABLE )
You get your default weapons back as well, the only draw back to this is if you call it instantly ie when a player dies straight away.
I think 3 seconds was the delay else you have to set the above flag and call:
Code:
dllfunc( DLLFunc_Spawn, id )
Regardless its not really logical to respawn a player instantly as soon as they die so just setting the pev_deadflag is sufficient with a task greater than 3 seconds from DeathMsg event.

Alka 08-20-2008 03:34

Re: How To: Respawn a player
 
Code:
stock fm_user_spawn(id) {  if(!(1 <= id <= global_get(glb_maxClients)))   return;    if(!is_user_alive(id))  {   set_pev(id, pev_deadflag, DEAD_RESPAWNABLE);   dllfunc(DLLFunc_Think, id);  }  else   dllfunc(DLLFunc_Spawn, id); }
I remember that setting the flag to DEAD_RESPAWNABLE and then use DLLFunc_Spawn didn't work properly, so DLLFunc_Think is just fine.

Orangutanz 08-20-2008 11:53

Re: How To: Respawn a player
 
Quote:

Originally Posted by Alka (Post 672514)
I remember that setting the flag to DEAD_RESPAWNABLE and then use DLLFunc_Spawn didn't work properly, so DLLFunc_Think is just fine.

Yeah your right, your think flag gets cleared upon death. I think it gets set to -1.0 if I remember rightly.

Does that mean you can respawn instantly using that technique Alka?
DEAD_RESPAWNABLE
THINK

I know when I discovered this many moons ago, I had it worked out you could just call: DEAD_RESPAWNABLE after 3 seconds of death else you had to use DEAD_RESPAWNABLE and SPAWN. I know that was the technique we used in Soccer/Football Mod.

ConnorMcLeod 08-20-2008 12:11

Re: How To: Respawn a player
 
Would be usefull to explain how to set properly the hud then, i remember that when i tried to make an amx version of gungame i had lot of problems with that, some times players have no knife and no crosshair.


Quote:

Originally Posted by GHW_Chronic (Post 672338)
offtopic: honestly HAM is a blessing but I really don't want to use it because 50% of the servers I play in use 1.76d.

But official version is now 1.8.1 ;)

Orangutanz 08-20-2008 12:22

Re: How To: Respawn a player
 
Quote:

Originally Posted by connorr (Post 672669)
Would be usefull to explain how to set properly the hud then, i remember that when i tried to make an amx version of gungame i had lot of problems with that, some times players have no knife and no crosshair.




But official version is now 1.8.1 ;)

Oh yeah I remember that now, you need to clear iuser settings, make sure they are all 0.

Arkshine 08-20-2008 12:27

Re: How To: Respawn a player
 
fakemeta_util :

Code:
stock fm_cs_user_spawn(index) {     set_pev(index, pev_deadflag, DEAD_RESPAWNABLE);     dllfunc(DLLFunc_Spawn, index);     set_pev(index, pev_iuser1, 0);     return 1; }

Orangutanz 08-20-2008 12:34

Re: How To: Respawn a player
 
Quote:

Originally Posted by arkshine (Post 672678)
fakemeta_util :

Code:
stock fm_cs_user_spawn(index) {     set_pev(index, pev_deadflag, DEAD_RESPAWNABLE);     dllfunc(DLLFunc_Spawn, index);     set_pev(index, pev_iuser1, 0);     return 1; }

Are you taking the piss or is that really in FM_Util? If it is why does it have CS prefix :grrr:

Also it seems it should be: dllfunc( DLLFunc_Think, index ) not DLLFunc_Spawn


All times are GMT -4. The time now is 01:22.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.