26.08.2012, 20:04
I'd use sth like this:
Not sure if it works..
PHP код:
enum hospital_
{
Float:h_X,
Float:h_Y,
Float:h_Z
};
new Hospitals[][hospital_] =
{
{0.0, 0.0, 0.0}, // list of hospital coords
{123.0, 456.0, 789.0},
{500.0, 500.0, 500.0}
};
stock Float:PlayerDistanceToPoint(playerid, Float:_x, Float:_y, Float:_z)
{
new Float:Coo[3];
GetPlayerPos(playerid,Coo[0],Coo[1],Coo[2]);
return floatsqroot(((Coo[0] - _x) * (Coo[0] - _x)) + ((Coo[1] - _y) * (Coo[1] - _y)) + ((Coo[2] - _z) * (Coo[2] - _z)));
}
stock ClosestHospital(playerid)
{
new hospitalid, Float:closest = PlayerDistanceToPoint(playerid, Hospitals[0][h_X], Hospitals[0][h_Y], Hospitals[0][h_Z];
for(new i=1; i<sizeof(Hospitals); i++)
{
if(PlayerDistanceToPoint(playerid, Hospitals[i][h_X], Hospitals[i][h_Y], Hospitals[i][h_Z]) < closest)
{
closest = PlayerDistanceToPoint(playerid, Hospitals[i][h_X], Hospitals[i][h_Y], Hospitals[i][h_Z]);
hospitalid = i;
}
}
return hospitalid;
}
public OnPlayerDeath(playerid, killerid, reason)
{
SetPVarInt(playerid, "Dead", 1);
SetPVarInt(playerid, "Hospital", ClosestHospital(playerid));
}
public OnPlayerSpawn(playerid)
{
if(GetPVarInt(playerid, "Dead"))
{
new hid = GetPVarInt(playerid, "Hospital");
SetPlayerInterior(playerid, 0);
SetPlayerVirtualWorld(playerid, 0);
SetPlayerPos(playerid, Hospitals[hid][h_X], Hospitals[hid][h_Y], Hospitals[hid][h_Z]);
SetPVarInt(playerid, "Dead", 0);
}
}