How To: Respawn a player

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1229
Gender:
United States of America

How To: Respawn a player

Post by Archive-Poster »

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: Select all

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

Who is online

Users browsing this forum: No registered users and 0 guests