28.09.2016, 22:00
Here's an example:
PHP код:
// ** INCLUDES
#include <a_samp>
#include <zcmd>
// ** ARRAYS AND ENUMERATORS
static const Float:aHospitalLocations[][] =
{
{1606.7900, 1821.8567, 10.8203}, // Las Venturas
{1184.4950, -1323.9468, 13.5744} // Los Santos
};
// ** MAIN
main()
{
print("Loaded \"get_closest_location_to_player.amx\".");
}
// ** CALLBACKS
public OnGameModeInit()
{
return 1;
}
public OnGameModeExit()
{
return 1;
}
// ** COMMANDS
CMD:closesthospital(playerid)
{
new string[144], Float:x, Float:y, Float:z;
GetClosestHospitalToPlayer(playerid, x, y, z);
format(string, sizeof(string), "%f, %f, %f", x, y, z);
SendClientMessage(playerid, -1, string);
return 1;
}
// ** FUNCTIONS
stock GetClosestHospitalToPlayer(playerid, &Float:x, &Float:y, &Float:z)
{
new Float:distance[2], index;
distance[0] = GetPlayerDistanceFromPoint(playerid, aHospitalLocations[0][0], aHospitalLocations[0][1], aHospitalLocations[0][2]);
for(new i = 1; i < sizeof(aHospitalLocations); i ++)
{
distance[1] = GetPlayerDistanceFromPoint(playerid, aHospitalLocations[i][0], aHospitalLocations[i][1], aHospitalLocations[i][2]);
if(distance[1] < distance[0])
{
distance[0] = distance[1];
index = i;
}
}
x = aHospitalLocations[index][0];
y = aHospitalLocations[index][1];
z = aHospitalLocations[index][2];
return 1;
}