Detecting which is the closest
#2

Here's an example:
PHP код:
// ** INCLUDES
#include <a_samp>
#include <zcmd>
// ** ARRAYS AND ENUMERATORS
static const Float:aHospitalLocations[][] =
{
    {
1606.79001821.856710.8203}, // Las Venturas
    
{1184.4950, -1323.946813.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:xFloat:yFloat:z;
    
GetClosestHospitalToPlayer(playeridxyz);
    
format(stringsizeof(string), "%f, %f, %f"xyz);
    
SendClientMessage(playerid, -1string);
    return 
1;
}
// ** FUNCTIONS
stock GetClosestHospitalToPlayer(playerid, &Float:x, &Float:y, &Float:z)
{
    new 
Float:distance[2], index;
    
distance[0] = GetPlayerDistanceFromPoint(playeridaHospitalLocations[0][0], aHospitalLocations[0][1], aHospitalLocations[0][2]);
    for(new 
1sizeof(aHospitalLocations); ++)
    {
        
distance[1] = GetPlayerDistanceFromPoint(playeridaHospitalLocations[i][0], aHospitalLocations[i][1], aHospitalLocations[i][2]);
        if(
distance[1] < distance[0])
        {
            
distance[0] = distance[1];
            
index i;
        }
    }
    
aHospitalLocations[index][0];
    
aHospitalLocations[index][1];
    
aHospitalLocations[index][2];
    return 
1;

Reply


Messages In This Thread
Detecting which is the closest - by JaKe Elite - 28.09.2016, 21:33
Re: Detecting which is the closest - by SickAttack - 28.09.2016, 22:00
Re: Detecting which is the closest - by JaKe Elite - 28.09.2016, 22:15
Re: Detecting which is the closest - by SickAttack - 28.09.2016, 22:54

Forum Jump:


Users browsing this thread: 1 Guest(s)