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