SA-MP Forums Archive
Player died. i want them to spawn at hospital! [NEED HELP] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Player died. i want them to spawn at hospital! [NEED HELP] (/showthread.php?tid=568539)



Player died. i want them to spawn at hospital! [NEED HELP] - Chausar - 23.03.2015

hi, can you help me with this? If player died . i want to spawn it at two random LS Hospital.


public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}


public OnPlayerSpawn(playerid)
{
SetPlayerPos(playerid, 2026.0083,-1422.5580,16.9922); //LS Hospital at Grove Street
SetPlayerPos(playerid, 1184.7742,-1323.9717,13.5737); //LS Hospital near Ammunation
return 1;
}


Re: Player died. i want them to spawn at hospital! [NEED HELP] - SickAttack - 23.03.2015

Example of random spawns:
pawn Код:
stock static const Float:aSpawns[][] =
{
    {2026.0083, -1422.5580, 16.9922},
    {1184.7742, -1323.9717, 13.5737}
};

public OnPlayerSpawn(playerid)
{
    new rand = random(sizeof(aSpawns));
    SetPlayerPos(playerid, aSpawns[rand][0], aSpawns[rand][1], aSpawns[rand][2]);
    return 1;
}



Re: Player died. i want them to spawn at hospital! [NEED HELP] - mirou123 - 23.03.2015

I edited the code above because OnPlayerSpawn isn't just called when a player dies and respawns.
Код:
// On top of the script
new bool:IsDead[MAX_PLAYERS];
stock static const Float:aSpawns[][] =
{
    {2026.0083, -1422.5580, 16.9922},
    {1184.7742, -1323.9717, 13.5737}
};

public OnPlayerDeath(playerid, killerid, reason)
{
    IsDead[playerid] = true;
}

public OnPlayerSpawn(playerid)
{
    if(IsDead[playerid])
    {
        new rand = random(sizeof(aSpawns));
        SetPlayerPos(playerid, aSpawns[rand][0], aSpawns[rand][1], aSpawns[rand][2]);
        IsDead[playerid] = false;
        return 1;
    }
}