new bool:dead; new Float:DistanceCounty_GH; new Float:DistanceAll_Saints_GH; new Float:DistanceCrippenMemorial_H; new Float:DistanceAngelP_MC; new Float:DistanceSanFierro_MC; new Float:DistanceElQuebrados_MC; new Float:DistanceLasVenturas_H; new Float:HospitalSpawns[][] = { {2031.8365, -1416.9377, 16.9922, 131.0062}, //County General Hospital {1182.0847, -1323.5752, 13.5812, 271.3102}, //All Saints General Hospital {1245.5205, 335.3977, 19.5547, 336.5431}, //CrippenMemorialHospital {-2196.8381, -2305.4912, 30.6250, 319.7987}, //AngelPineMedicalCenter {-2653.3613, 627.6060, 14.4531, 179.0622}, //SanFierroMedicalCenter {-1514.8903, 2528.7163, 55.7143, 359.3568}, //ElQuebradosMedicalCenter {1579.2933, 1769.0499, 10.8203, 90.3324} //LasVenturasHospital }; public OnPlayerRequestClass(playerid, classid) { dead = false; SetPlayerPos(playerid, -160.2186, -324.0767, 3.7590); SetPlayerFacingAngle(playerid, 87.7342); SetPlayerCameraPos(playerid, -170.899993, -323.940704, 3.929687); SetPlayerCameraLookAt(playerid, -170.899993, -323.940704, 3.929687); return 1; } stock GetSmallestIndex(v[], len = sizeof(v)) { new min_index, min_value = -1; for(new i = 0; i < len; i ++) { if(v[i] < min_value || min_value == -1) { min_index = i; min_value = v[i]; } } return min_index; } public OnPlayerSpawn(playerid) { if(dead==true) { new float:values[7]; values[0]=DistanceCounty_GH; values[1]=DistanceAll_Saints_GH; values[2]=DistanceCrippenMemorial_H; values[3]=DistanceAngelP_MC; values[4]=DistanceSanFierro_MC; values[5]=DistanceElQuebrados_MC; values[6]=DistanceLasVenturas_H; switch(GetSmallestIndex(values)) { case 0: {SetPlayerPos(playerid, HospitalSpawns[0][0], HospitalSpawns[0][1], HospitalSpawns[0][2]); SetPlayerFacingAngle(playerid, HospitalSpawns[0][3]); SetCameraBehindPlayer(playerid);} case 1: {SetPlayerPos(playerid, HospitalSpawns[1][0], HospitalSpawns[1][1], HospitalSpawns[1][2]); SetPlayerFacingAngle(playerid, HospitalSpawns[1][3]); SetCameraBehindPlayer(playerid); } case 2: {SetPlayerPos(playerid, HospitalSpawns[2][0], HospitalSpawns[2][1], HospitalSpawns[2][2]); SetPlayerFacingAngle(playerid, HospitalSpawns[2][3]); SetCameraBehindPlayer(playerid); } case 3: {SetPlayerPos(playerid, HospitalSpawns[3][0], HospitalSpawns[3][1], HospitalSpawns[3][2]); SetPlayerFacingAngle(playerid, HospitalSpawns[3][3]); SetCameraBehindPlayer(playerid); } case 4: {SetPlayerPos(playerid, HospitalSpawns[4][0], HospitalSpawns[4][1], HospitalSpawns[4][2]); SetPlayerFacingAngle(playerid, HospitalSpawns[4][3]); SetCameraBehindPlayer(playerid); } case 5: {SetPlayerPos(playerid, HospitalSpawns[5][0], HospitalSpawns[5][1], HospitalSpawns[5][2]); SetPlayerFacingAngle(playerid, HospitalSpawns[5][3]); SetCameraBehindPlayer(playerid); } case 6: {SetPlayerPos(playerid, HospitalSpawns[6][0], HospitalSpawns[6][1], HospitalSpawns[6][2]); SetPlayerFacingAngle(playerid, HospitalSpawns[6][3]); SetCameraBehindPlayer(playerid); } } } if(dead==false) { SetPlayerPos(playerid, 1714.9219,-1948.8318,14.1172); SetPlayerFacingAngle(playerid, 357.5184); SetCameraBehindPlayer(playerid); return 1; } return 0; } public OnPlayerDeath(playerid, killerid, reason) { SendDeathMessage(killerid, playerid, reason); // Shows the kill in the killfeed SetPlayerScore(killerid,GetPlayerScore(killerid)+1); dead = true; DistanceCounty_GH = GetPlayerDistanceFromPoint(playerid, HospitalSpawns[0][0], HospitalSpawns[0][1], HospitalSpawns[0][2]); DistanceAll_Saints_GH = GetPlayerDistanceFromPoint(playerid, HospitalSpawns[1][0], HospitalSpawns[1][1], HospitalSpawns[1][2]); DistanceCrippenMemorial_H = GetPlayerDistanceFromPoint(playerid, HospitalSpawns[2][0], HospitalSpawns[2][1], HospitalSpawns[2][2]); DistanceAngelP_MC = GetPlayerDistanceFromPoint(playerid, HospitalSpawns[3][0], HospitalSpawns[3][1], HospitalSpawns[3][2]); DistanceSanFierro_MC = GetPlayerDistanceFromPoint(playerid, HospitalSpawns[4][0], HospitalSpawns[4][1], HospitalSpawns[4][2]); DistanceElQuebrados_MC = GetPlayerDistanceFromPoint(playerid, HospitalSpawns[5][0], HospitalSpawns[5][1], HospitalSpawns[5][2]); DistanceLasVenturas_H = GetPlayerDistanceFromPoint(playerid, HospitalSpawns[6][0], HospitalSpawns[6][1], HospitalSpawns[6][2]); return 1; }
{ if(DistanceCounty_GH < DistanceAll_Saints_GH && DistanceCrippenMemorial_H && DistanceAngelP_MC && DistanceSanFierro_MC && DistanceElQuebrados_MC && DistanceLasVenturas_H) { SetPlayerPos(playerid, HospitalSpawns[0][0], HospitalSpawns[0][1], HospitalSpawns[0][2]); SetPlayerFacingAngle(playerid, HospitalSpawns[0][3]); SetCameraBehindPlayer(playerid); return 1; } else if(DistanceAll_Saints_GH < DistanceCounty_GH && DistanceCrippenMemorial_H && DistanceAngelP_MC && DistanceSanFierro_MC && DistanceElQuebrados_MC && DistanceLasVenturas_H) { SetPlayerPos(playerid, HospitalSpawns[1][0], HospitalSpawns[1][1], HospitalSpawns[1][2]); SetPlayerFacingAngle(playerid, HospitalSpawns[1][3]); SetCameraBehindPlayer(playerid); } else if(DistanceCrippenMemorial_H < DistanceAll_Saints_GH && DistanceCounty_GH && DistanceAngelP_MC && DistanceSanFierro_MC && DistanceElQuebrados_MC && DistanceLasVenturas_H) { SetPlayerPos(playerid, HospitalSpawns[2][0], HospitalSpawns[2][1], HospitalSpawns[2][2]); SetPlayerFacingAngle(playerid, HospitalSpawns[2][3]); SetCameraBehindPlayer(playerid); } else if(DistanceAngelP_MC < DistanceCrippenMemorial_H && DistanceAll_Saints_GH && DistanceCounty_GH && DistanceSanFierro_MC && DistanceElQuebrados_MC && DistanceLasVenturas_H) { SetPlayerPos(playerid, HospitalSpawns[3][0], HospitalSpawns[3][1], HospitalSpawns[3][2]); SetPlayerFacingAngle(playerid, HospitalSpawns[3][3]); SetCameraBehindPlayer(playerid); } else if(DistanceSanFierro_MC < DistanceAngelP_MC && DistanceCrippenMemorial_H && DistanceAll_Saints_GH && DistanceCounty_GH && DistanceElQuebrados_MC && DistanceLasVenturas_H) { SetPlayerPos(playerid, HospitalSpawns[4][0], HospitalSpawns[4][1], HospitalSpawns[4][2]); SetPlayerFacingAngle(playerid, HospitalSpawns[4][3]); SetCameraBehindPlayer(playerid); } else if(DistanceElQuebrados_MC < DistanceSanFierro_MC && DistanceAngelP_MC && DistanceCrippenMemorial_H && DistanceAll_Saints_GH && DistanceCounty_GH && DistanceLasVenturas_H) { SetPlayerPos(playerid, HospitalSpawns[5][0], HospitalSpawns[5][1], HospitalSpawns[5][2]); SetPlayerFacingAngle(playerid, HospitalSpawns[5][3]); SetCameraBehindPlayer(playerid); } else if(DistanceLasVenturas_H < DistanceElQuebrados_MC && DistanceSanFierro_MC && DistanceAngelP_MC && DistanceCrippenMemorial_H && DistanceAll_Saints_GH && DistanceCounty_GH) { SetPlayerPos(playerid, HospitalSpawns[6][0], HospitalSpawns[6][1], HospitalSpawns[6][2]); SetPlayerFacingAngle(playerid, HospitalSpawns[6][3]); SetCameraBehindPlayer(playerid); } }
HospitalSpawns[][]
HospitalSpawns[0][0] //The first set of coordinates and the X-coordinate.
HospitalSpawns[0][1] //The first set of coordinates and the Y-coordinate.
HospitalSpawns[0][2] //The first set of coordinates and the Z-coordinate.
HospitalSpawns[0][3] //The first set of coordinates and the Angle-coordinate.
SetPlayerPos(playerid, HospitalSpawns[0][0], HospitalSpawns[0][1], HospitalSpawns[0][2]); //The first set of coordinates and the X [0], Y [1] and Z-coordinate [2].
SetPlayerFacingAngle(playerid, HospitalSpawns[0][3]); //The first set of coordinates and the Angle [3] coordinate.
#define FLOAT_INFINITY (Float:0x7F800000)
new Float:gClosestHospitalDist[MAX_PLAYERS]; // if for some reason you have to save the distance
new gClosestHospital[MAX_PLAYERS]; // holds the index to the closest hospital
public OnPlayerDeath(playerid, killerid, reason)
{
// rest of code..
new Float:dist = FLOAT_INFINITY;
for (new i = 0; i < sizeof(HospitalSpawns); i++)
{
gClosestHospitalDist[playerid] = GetPlayerDistanceFromPoint(playerid, HospitalSpawns[i][0], HospitalSpawns[i][1], HospitalSpawns[i][2]);
if (gClosestHospitalDist[playerid] < dist)
{
dist = gClosestHospitalDist[playerid];
gClosestHospital[playerid] = i;
}
}
return 1;
}
Код:
HospitalSpawns[][] For example: HospitalSpawns[0][] means: the first line of coordinates. With this comes a second pair of brackets which stand for the amount of parameters in each line of coordinates. For example: HospitalSpawns[][0] means: the first parameter in the coordinate line (The X coordinate). And you can now combine these two. pawn Код:
pawn Код:
pawn Код:
pawn Код:
pawn Код:
pawn Код:
|
Why waste space allocating an array? I recommend that you calculate the distance from the hospitals immediately when a player dies, then do whatever you want with that.
Also another issue I found in your code is the "dead" variable, it will only work for one player alone - make it a per-player var. pawn Код:
![]() |
public OnPlayerSpawn(playerid)
{
if(dead==true)
{
SetPlayerPos(playerid, HospitalSpawns[gClosestHospital][0], HospitalSpawns[gClosestHospital][1], HospitalSpawns[gClosestHospital][2]);
SetPlayerFacingAngle(playerid, HospitalSpawns[gClosestHospital][3]);
setCaneraBehindPlayer(playerid);
return 1;
}
if(dead==false)
{
SetPlayerPos(playerid, 1714.9219,-1948.8318,14.1172);
SetPlayerFacingAngle(playerid, 357.5184);
SetCameraBehindPlayer(playerid);
return 1;
}
return 0;
}
public OnPlayerSpawn(playerid)
{
if(dead==true)
{
new i = gClosestHospital[playerid];
SetPlayerPos(playerid, HospitalSpawns[i][0], HospitalSpawns[i][1], HospitalSpawns[i][2]);
SetPlayerFacingAngle(playerid, HospitalSpawns[i][3]);
SetCameraBehindPlayer(playerid);
}
if(dead==false)
{
SetPlayerPos(playerid, 1714.9219,-1948.8318,14.1172);
SetPlayerFacingAngle(playerid, 357.5184);
SetCameraBehindPlayer(playerid);
return 1;
}
return 0;
}
new bool:dead[MAX_PLAYERS];
// And you use it like e.g. dead[playerid] under OnPlayerDeath
// The way you have it now will only ever work for one player alone
Just make a simple variable(called an array, actually) that holds MAX_PLAYERS items. You can still keep the "bool:" tag if you wish.
Also, be sure to declare it outside any function or callback (global variable). Example: pawn Код:
|