12.05.2013, 15:56
Hi guys,
I have a question about my code. This is supposed to spawn you at the nearest hospital. But when you die, you get the "Out of world bounds" in your screen. Can anybody please say what is wrong?
Thanks in advance!
I have a question about my code. This is supposed to spawn you at the nearest hospital. But when you die, you get the "Out of world bounds" in your screen. Can anybody please say what is wrong?
pawn Код:
new dead[MAX_PLAYERS];
new hospital;
new Float:Hospitals[2][3] = {
{2029.665771, -1418.884765, 16.992187},
{1178.691772, -1324.275268, 14.132597}
};
pawn Код:
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)));
}
pawn Код:
stock ClosestHospital(playerid)
{
new hospitalid, Float:closest = PlayerDistanceToPoint(playerid, Hospitals[0][0], Hospitals[0][1], Hospitals[0][2]);
for(new i = 1; i < sizeof(Hospitals); i++)
{
if(PlayerDistanceToPoint(playerid, Hospitals[i][0], Hospitals[i][1], Hospitals[i][2]) < closest)
{
closest = PlayerDistanceToPoint(playerid, Hospitals[i][0], Hospitals[i][1], Hospitals[i][2]);
hospitalid = i;
}
}
return hospitalid;
}
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
dead[playerid] = 1;
hospital = ClosestHospital(playerid);
return 1;
}
pawn Код:
public OnPlayerSpawn(playerid)
{
if(dead[playerid] == 1)
{
new hid = hospital;
SetPlayerPos(playerid, Hospitals[hid][0], Hospitals[hid][1], Hospitals[hid][2]);
dead[playerid] = 0;
}
}