samedi 16 juillet 2016

Nearest Hospital Spawn Upon Death

Hey,

Looked all over using the search function, found a few suggested solutions, however can't seem to find any that work.

Basically what I'm looking for is a piece of script that respawns the player to the nearest Hospital upon death. So far I have the following code, however this doesn't work as I constantly respawn at my initial spawn point in the server.

Any help would be greatly appreciated!

Code:

new Dead[MAX_PLAYERS];

Code:

stock SpawnToHospital(playerid)
{
    Dead[playerid] = 0;
    static const Float:hspawns[8][4] = 
    {
                {2027.77, -1420.52, 15.99, 137.0},
                {1180.85, -1325.57, 12.58, 271.4},
                {1244.437, 331.2261, 18.5547, 7.5465},
                {-2199.719, -2308.075, 29.6181, 322.8928},
                {-2670.285, 616.4364, 13.4531, 183.1042},
                {-316.3832, 1056.045, 18.7344, 1.6017},
                {-1514.823, 2527.119, 54.7443, 2.3546},
                {1578.446, 1770.682, 9.8358, 99.7567}
       
    };
    new Float:spawndist[8];  // Change to the number of hospital spawnpoints you use.
    new Float:distance = 10000.0, closestspawn;
        spawndist[0] = GetPlayerDistanceFromPoint(playerid,2027.77, -1420.52, 15.99); // 1st hospital spawn.
        spawndist[1] = GetPlayerDistanceFromPoint(playerid,1180.85, -1325.57, 12.58); // 2nd hospital spawn.
        spawndist[2] = GetPlayerDistanceFromPoint(playerid,1244.437, 331.2261, 18.5547); // 3rd hospital spawn.
        spawndist[4] = GetPlayerDistanceFromPoint(playerid,-2199.719, -2308.075, 29.6181); // 5th hospital spawn.
        spawndist[3] = GetPlayerDistanceFromPoint(playerid,-2670.285, 616.4364, 13.4531); // 4th hospital spawn.
        spawndist[5] = GetPlayerDistanceFromPoint(playerid,-316.3832, 1056.045, 18.7344); // 6th hospital spawn.
        spawndist[6] = GetPlayerDistanceFromPoint(playerid,-1514.823, 2527.119, 54.7443); // 7th hospital spawn.
        spawndist[7] = GetPlayerDistanceFromPoint(playerid,1578.446, 1770.682, 9.8358); // 8th hospital spawn.

    
    for(new i = 0; i < sizeof(spawndist); i++)
    {
        if(spawndist[i] < distance) distance = spawndist[i], closestspawn = i;
    }
    SetPlayerPos(playerid, hspawns[closestspawn][0], hspawns[closestspawn][1], hspawns[closestspawn][2]);
    SetPlayerFacingAngle(playerid, hspawns[closestspawn][3]);
}

Code:

public OnPlayerConnect(playerid)
{
        Dead[playerid]=0;
        return 1;
}

Code:

public OnPlayerSpawn(playerid)
{
        if(Dead[playerid] == 1) 
        {
                SpawnToHospital(playerid);
        }
        
        SetPlayerInterior(playerid,0);
        TogglePlayerClock(playerid,0);
        if(PlayerInfo[playerid][pInJail] == 1)
        {
            new string[64];
                SetPlayerPos(playerid, 1492.2151,-1768.2281,3285.2859);
                format(string, sizeof(string), "* Your character is currently is jail for another %d seconds.", PlayerInfo[playerid][pInJailTime]);
                SendClientMessage(playerid, COLOR_ADMIN, string);
        }
    
}

This entry passed through the Full-Text RSS service - if this is your content and you're reading it on someone else's site, please read the FAQ at http://ift.tt/jcXqJW.
Recommended article from FiveFilters.org: Most Labour MPs in the UK Are Revolting.



Nearest Hospital Spawn Upon Death

Aucun commentaire:

Enregistrer un commentaire