Raised This Month: $32 Target: $400
 8% 

How To: Respawn a player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GHW_Chronic
SourceMod Donor
Join Date: Sep 2004
Location: Texas
Old 08-19-2008 , 18:51   How To: Respawn a player
Reply With Quote #1

  • 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)     } }

Last edited by GHW_Chronic; 08-20-2008 at 19:03.
GHW_Chronic is offline
Send a message via AIM to GHW_Chronic
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 08-19-2008 , 18:54   Re: How To: Respawn a player
Reply With Quote #2

Better way, for CS at least:

ExecuteHamB(Ham_CS_RoundRespawn,player)
danielkza is offline
GHW_Chronic
SourceMod Donor
Join Date: Sep 2004
Location: Texas
Old 08-19-2008 , 19:06   Re: How To: Respawn a player
Reply With Quote #3

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.
GHW_Chronic is offline
Send a message via AIM to GHW_Chronic
Orangutanz
Veteran Member
Join Date: Apr 2006
Old 08-19-2008 , 21:12   Re: How To: Respawn a player
Reply With Quote #4

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.
Orangutanz is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 08-20-2008 , 03:34   Re: How To: Respawn a player
Reply With Quote #5

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.
Alka is offline
Orangutanz
Veteran Member
Join Date: Apr 2006
Old 08-20-2008 , 11:53   Re: How To: Respawn a player
Reply With Quote #6

Quote:
Originally Posted by Alka View Post
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.
Orangutanz is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-20-2008 , 12:11   Re: How To: Respawn a player
Reply With Quote #7

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 View Post
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 ;)
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Orangutanz
Veteran Member
Join Date: Apr 2006
Old 08-20-2008 , 12:22   Re: How To: Respawn a player
Reply With Quote #8

Quote:
Originally Posted by connorr View Post
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.
Orangutanz is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-20-2008 , 12:27   Re: How To: Respawn a player
Reply With Quote #9

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; }
__________________
Arkshine is offline
Orangutanz
Veteran Member
Join Date: Apr 2006
Old 08-20-2008 , 12:34   Re: How To: Respawn a player
Reply With Quote #10

Quote:
Originally Posted by arkshine View Post
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

Also it seems it should be: dllfunc( DLLFunc_Think, index ) not DLLFunc_Spawn
Orangutanz is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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