Nearest Hospital Spawn Upon Death
#1

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!

Код:
new Dead[MAX_PLAYERS];
Код:
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]);
}
Код:
public OnPlayerConnect(playerid)
{
	Dead[playerid]=0;
        return 1;
}
Код:
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);
	}
    
}
Reply


Messages In This Thread
Nearest Hospital Spawn Upon Death - by marley - 17.07.2016, 00:18
Re: Nearest Hospital Spawn Upon Death - by DTV - 17.07.2016, 01:11
Re: Nearest Hospital Spawn Upon Death - by marley - 17.07.2016, 02:29
Re: Nearest Hospital Spawn Upon Death - by DTV - 17.07.2016, 03:08
Re: Nearest Hospital Spawn Upon Death - by [cS]Owain - 17.07.2016, 05:17
Re: Nearest Hospital Spawn Upon Death - by oMa37 - 17.07.2016, 05:34
Re: Nearest Hospital Spawn Upon Death - by marley - 17.07.2016, 17:43

Forum Jump:


Users browsing this thread: 5 Guest(s)