Detecting which is the closest -
JaKe Elite - 28.09.2016
So I am scripting the Trucker job and erm, I wanted to detect if the coordinates for the delivery is close to San Fierro or Los Santos.
For instance, The coordinates are set to Commerence, It will automatically detect that it's in Los Santos and if it is set to Downtown San Fierro, It will automatically detect that it's in San Fierro. If the coordinates are located in a county-side, It will get the closest city in distance.
I have an idea though, I will get the coordinates for LS/SF and then use this function to do it.
PHP код:
// From SCRP
stock GetClosestHospital(playerid)
{
new
Float:fDistance[2] = {99999.0, 0.0},
iIndex = -1
;
for (new i = 0; i < sizeof(arrHospitalSpawns); i ++)
{
fDistance[1] = GetPlayerDistanceFromPoint(playerid, arrHospitalSpawns[i][0], arrHospitalSpawns[i][1], arrHospitalSpawns[i][2]);
if (fDistance[1] < fDistance[0])
{
fDistance[0] = fDistance[1];
iIndex = i;
}
}
return iIndex;
}
Though I am clueless on how am I gonna do it.
Re: Detecting which is the closest -
SickAttack - 28.09.2016
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;
}
Re: Detecting which is the closest -
JaKe Elite - 28.09.2016
Will try this out, cheers m8.
EDIT: How can I determine if the player is in LS or LV (in this case SF) though?
Re: Detecting which is the closest -
SickAttack - 28.09.2016
There are various ways, depends on which one you choose.
- Create 3 areas with the streamer plugin, one for each city
- Specify which city each location/zone is in (array -> {"Commerce", x, y, z, "Los Santos"},)
- Etc., etc.