15.12.2017, 18:04
Код:
stock GetProxHosp(playerid) { if(!IsPlayerConnected(playerid)) return 0; //caso o player nгo esteja conectado, retorna 0 new Float:Hospital[][4] = //variбvel com as coordenadas de todos os hospitais { //X, Y, Z, Angulo {-2651.6501, 634.451000, 14.4531, 180.0}, {1173.58420, -1324.5615, 15.1953, 270.0}, {2031.94150, -1404.3578, 17.2614, 165.0}, {1582.56150, 1768.79210, 10.8203, 90.00}, {-318.81500, 1050.88900, 20.3403, 360.0}, {-1514.7959, 2522.85060, 55.8246, 0.000}, {-2200.2214, -2306.5452, 30.6250, 320.0}, {1242.37130, 328.452000, 19.7555, 335.0} }; new hospitalproximo; //variбvel que serб o id do hospital mais prуximo for(new hospid = 0, Float:prevdist, Float:dist; hospid < sizeof(Hospital); hospid++) //loop por todas as coordenadas dos hospitais. hospid = id hosppital, prevdist й a menor distancia, dist й a distancia para o hospital checado { dist = GetPlayerDistanceToPoint(playerid, Hospital[hospid][0], Hospital[hospid][1], Hospital[hospid][2]); //faz com que dist receba essa distancia if(hospid == 0 || dist < prevdist) prevdist = dist, hospitalproximo = hospid; //se for o primeiro hospital ou se a distancia checada for menor que a menor distancia salva, troca } //no fim ele salva em PVAR as coordenadas do hospital mais prуximo SetPVarFloat(playerid, "HospPosX", Hospital[hospitalproximo][0]); SetPVarFloat(playerid, "HospPosY", Hospital[hospitalproximo][1]); SetPVarFloat(playerid, "HospPosZ", Hospital[hospitalproximo][2]); SetPVarFloat(playerid, "HospPosA", Hospital[hospitalproximo][3]); return 1; }