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); } }
new closestspawn = -1;
for(new i = 0; i < sizeof(spawndist); i++)
{
if(closestspawn == -1 && spawndist[i] < distance)
{
closestspawn = i;
continue;
}
else if(closestspawn != -1 && closestspawn != i)
{
if(spawndist[i] < spawndist[closestspawn])
{
closestspawn = i;
continue;
}
else continue;
}
}
else if(closestspawn != -1 && closestspawn != i)
{
if(spawndist[i] > spawndist[closestspawn]) continue;
else if(spawndist[i] < spawndist[closestspawn])
{
closestspawn = i;
continue;
}
}
for some bizarre reason for a split second it tps me to the train station where the player starts before spawning properly at the wrong hosp
|
So we've made progress, so now when I die it tps me to a hospital, but it isn't the nearest,
|
#define MAX_HOSPITALS 8
static const Float:hspawns[MAX_HOSPITALS][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:distance = 99999.0,
Float:tmp_distance,
closest = -1;
for(new i = 0; i < MAX_HOSPITALS; i++)
{
tmp_distance = GetPlayerDistanceFromPoint(playerid, hspawnsr[i][0], hspawns[i][1], hspawns[i][2]);
if (tmp_distance < distance)
{
distance = tmp_distance;
closest = i;
}
}
SetSpawnInfo(playerid, NO_TEAM, GetPlayerSkin(playerid), hspawns[closest][0],hspawns[closest][1],hspawns[closest][2],hspawns[closest][3], 0, 0, 0, 0, 0, 0);