Get closests starting point -
SomebodyAndMe - 26.04.2013
Well I'm trying to make if a player is in a vehicle and calls /work it goes to the closest location set in the new ALocations.
But currently it sets the missionid to the last defined mission.
Can anyone see what's wrong in this code?
pawn Код:
if(TypeFlight[playerid] == 1) // Andromada
{
new MissionID;
new MAX_LOCATIONS = sizeof(ALocations);
for(new i; i <= MAX_LOCATIONS; i++)
{
new Float:pPos[3], Float:LowestDistance = 50000000.0000, Float:thisDistance;
GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
thisDistance = GetDistanceBetweenPoints(ALocations[i][LocX],ALocations[i][LocY],ALocations[i][LocZ], pPos[0], pPos[1], pPos[2]);
if(thisDistance < LowestDistance)
{
LowestDistance = thisDistance;
MissionID = i;
}
}
StartedMission[playerid] = 1;
//new rand = random(sizeof(ALocations));
new string2[65], message[128];
SetPlayerFlightCheckpoint(playerid, ALocations[MissionID][LocX],ALocations[MissionID][LocY],ALocations[MissionID][LocZ], 15.0);
format(string2, sizeof(string2), "%s", ALocations[MissionID][LocationName]); //PASSWORD
strmid(FirstAPName[playerid], string2, 0, strlen(string2), 128); //PASSWORD
//FirstAPName[playerid] = ALocations[rand][LocationName];
//FirstAPName[playerid] = AndroDName;
format(message,sizeof(message), "Head to {FF9900}%s {FFFFFF}and pick up the cargo goods.", ALocations[MissionID][LocationName]);
SendClientMessage(playerid, COLOR_WHITE, message);
TypeFlight[playerid] = 1;
MissionStage[playerid] = 1;
WantsRecording[playerid] = 1;
Pos1[playerid] = ALocations[MissionID][LocX];
Pos2[playerid] = ALocations[MissionID][LocY];
Pos3[playerid] = ALocations[MissionID][LocZ];
}
The locations:
pawn Код:
new ALocations[][TLocation] =
{
// LocationName, LocationX, LocationY, LocationZ
{"LSA Gate A", 1738.3202,-2425.8325,14.4741}, // Location 1
{"LSA Gate B", 1641.5100,-2423.1333,14.4730},
{"LSA Gate C", 1562.1697,-2428.0403,14.4765},
{"LVA Gate A", 1561.0095,1397.6116,11.7708},
{"LVA Gate B", 1574.6689,1539.6458,11.7481},
{"SFA Gate B", -1382.1825,-225.9442,15.0717},
{"SFA Gate C", -1323.3275,-255.5832,15.0703},
{"Stoneland Int. Gate C", 2717.9512,681.2523,11.2553},
{"Stoneland Int. Gate D", 2742.9993,679.6970,11.2612}
};
It sets it to Stoneland int. Gate D every single time.
Hope to get some help soon.
AW: Get closests starting point -
Nero_3D - 26.04.2013
Your problem is that you create
LowestDistance inside the loop, thus setting it each time to 50000000.0
Also you could use Float: 0x7F800000 which represents infinity
Re: Get closests starting point -
SomebodyAndMe - 26.04.2013
Oh thanks for noticing that, I totally didn't see that one coming.
I have the current problem now with it tho: when typing /work it says unknown command in a andromada, although when typing the same command in a shamal sets their work for a shamal. How the hell does that happen?
AW: Get closests starting point -
Nero_3D - 26.04.2013
I cant say much if I dont have the code the best is if you debug it out, put prints before the if statment, after and inside and check what gets printed, also print out the values