Get closests starting point
#1

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.
Reply


Messages In This Thread
Get closests starting point - by SomebodyAndMe - 26.04.2013, 13:52
AW: Get closests starting point - by Nero_3D - 26.04.2013, 15:45
Re: Get closests starting point - by SomebodyAndMe - 26.04.2013, 17:52
AW: Get closests starting point - by Nero_3D - 26.04.2013, 18:25

Forum Jump:


Users browsing this thread: 2 Guest(s)