29.07.2012, 02:35
pawn Code:
forward GetNearestBus(playerid, name[], len);
public GetNearestBus(playerid, name[], len)
{
new Float:d = 0.000;
new Float:dis = 0.0000;
new number = -1;
for(new i = 0; i <= sizeof(BusStops); i++)
{
dis = GetPlayerDistanceFromPoint(playerid, BusStops[i][BusCords][0], BusStops[i][BusCords][1], BusStops[i][BusCords][2]);
if(dis > d)
{
d = dis;
number = i;
}
}
return format(name, len, BusStops[number][BusName], 0);
pawn Code:
forward GetNearestBus(playerid, &name[], len);
public GetNearestBus(playerid, &name[], len)
{
new Float:d = 9999.000;
new Float:dis = 0.0000;
new number = -1;
for(new i = 0; i <= sizeof(BusStops); i++)
{
dis = GetPlayerDistanceFromPoint(playerid, BusStops[i][BusCords][0], BusStops[i][BusCords][1], BusStops[i][BusCords][2]);
if(dis < d)
{
d = dis;
number = i;
}
}
format(name, len, BusStops[number][BusName], 0);
return name;
}
Things wrong:
- Your finding the furthest bus stop... you should be finding the nearest.
- - Change if(dis > d) to if(dis < d)
- - Change new Float:d = 0.000; to new Float:d = 9999.000;
- You're returning the result of format, not the name of the bustop.
- - Redo the return.

