20.07.2011, 03:15
thats an example of getting the closest hospital i use in my script, the variables are initialized outside of the loop, therefore they still exist outside of the for loop.
Код:
new Float:x, Float:y, Float:z, chospital, Float:sdistance; GetPlayerPos( playerid, x, y, z); for (new i = 0; i < MAX_HOSPITALS; i++) { if (i == 0) { sdistance = DISTANCE(x, y, z, Hospitals[i][0], Hospitals[i][1], Hospitals[i][2]); chospital = i; } else if (DISTANCE(x, y, z, Hospitals[i][0], Hospitals[i][1], Hospitals[i][2]) < sdistance) { sdistance = DISTANCE(x, y, z, Hospitals[i][0], Hospitals[i][1], Hospitals[i][2]); chospital = i; } }