Player died. i want them to spawn at hospital! [NEED HELP]
#1

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;
}
Reply
#2

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;
}
Reply
#3

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;
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)