SA-MP Forums Archive
Need help with getting closest checkpoint - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Need help with getting closest checkpoint (/showthread.php?tid=619222)



Need help with getting closest checkpoint - bugmenotlol - 15.10.2016

hi
i need a function to get closest checkpoint in this :

PHP код:
new CD1Locations[][TLocation] =
{
    {
"SF Driving School Stop", -2070.2134,-76.9065,35.3203},
    {
"Burger Shot", -2327.7761,-183.9470,35.3203},
    {
"SF Hotel", -2724.3123,-314.2257,7.1867},
    {
"Clukin Bell", -2657.7583,280.5651,4.3281},
    {
"Supa Save", -2451.0186,737.3842,35.0156},
    {
"Esplanade North", -1951.1077,1327.4839,7.1888},
    {
"WangCars stop", -1998.8578,252.6071,30.3579}
}; 



Re: Need help with getting closest checkpoint - Mencent - 15.10.2016

Hello.

Do you mean something like this?
PHP код:
new Float:dist,Float:maxdist 99999.9,index;
for(new 
i,j=sizeof(CD1Locations);i<j;i++)
{
    
dist GetPlayerDistanceFromPoint(playerid,CD1Locations[i][1],CD1Locations[i][2],CD1Locations[i][3]);
    if(
dist maxdist)
    {
        
maxdist dist;
        
index i;
    }
}
printf("The closest location is %s",CD1Locations[index][0]); 



Re: Need help with getting closest checkpoint - bugmenotlol - 15.10.2016

Quote:
Originally Posted by Mencent
Посмотреть сообщение
Hello.

Do you mean something like this?
PHP код:
new Float:dist,Float:maxdist 99999.9,index;
for(new 
i,j=sizeof(CD1Locations);i<j;i++)
{
    
dist GetPlayerDistanceFromPoint(playerid,CD1Locations[i][1],CD1Locations[i][2],CD1Locations[i][3]);
    if(
dist maxdist)
    {
        
maxdist dist;
        
index i;
    }
}
printf("The closest location is %s",CD1Locations[index][0]); 
PHP код:
if(TypeFlight[playerid] == 1// Andromada 
    

        
StartedMission[playerid] = 1
        new 
rand random(sizeof(cd1Locations)); 
        new 
string2[65], message[128]; 
        
SetPlayerFlightCheckpoint(playeridcd1Locations[rand][LocX],cd1Locations[rand][LocY],cd1Locations[rand][LocZ], 15.0); 
        
format(string2sizeof(string2), "%s"cd1Locations[rand][LocationName]); //PASSWORD 
        
strmid(FirstAPName[playerid], string20strlen(string2), 128); //PASSWORD 
        //FirstAPName[playerid] = ALocations[rand][LocationName]; 
        //FirstAPName[playerid] = AndroDName; 
        
format(message,sizeof(message), "Head to {1B8AE4}%s {FFFFFF}and pick up the cargo goods."cd1Locations[rand][LocationName]); 
        
SendClientMessage(playeridCOLOR_WHITEmessage); 
        
TypeFlight[playerid] = 1
        
MissionStage[playerid] = 1
        
WantsRecording[playerid] = 1
        
Pos1[playerid] = cd1Locations[rand][LocX]; 
        
Pos2[playerid] = cd1Locations[rand][LocY]; 
        
Pos3[playerid] = cd1Locations[rand][LocZ]; 
i need to get it for this function


Re: Need help with getting closest checkpoint - Mencent - 15.10.2016

It's that what do you mean?
PHP код:
if(TypeFlight[playerid] == 1// Andromada
{
    new 
Float:dist,Float:maxdist 99999.9,index;
    for(new 
i,j=sizeof(CD1Locations);i<j;i++)
    {
        
dist GetPlayerDistanceFromPoint(playerid,CD1Locations[i][1],CD1Locations[i][2],CD1Locations[i][3]);
        if(
dist maxdist)
        {
            
maxdist dist;
            
index i;
        }
    }
    
StartedMission[playerid] = 1;
    new 
string2[65], message[128];
    
SetPlayerFlightCheckpoint(playeridcd1Locations[index][LocX],cd1Locations[index][LocY],cd1Locations[index][LocZ], 15.0);
    
format(string2sizeof(string2), "%s"cd1Locations[index][LocationName]); //PASSWORD
    
strmid(FirstAPName[playerid], string20strlen(string2), 128); //PASSWORD
    //FirstAPName[playerid] = ALocations[index][LocationName];
    //FirstAPName[playerid] = AndroDName;
    
format(message,sizeof(message), "Head to {1B8AE4}%s {FFFFFF}and pick up the cargo goods."cd1Locations[index][LocationName]);
    
SendClientMessage(playeridCOLOR_WHITEmessage);
    
TypeFlight[playerid] = 1;
    
MissionStage[playerid] = 1;
    
WantsRecording[playerid] = 1;
    
Pos1[playerid] = cd1Locations[index][LocX];
    
Pos2[playerid] = cd1Locations[index][LocY];
    
Pos3[playerid] = cd1Locations[index][LocZ]; 
You want to get the closest checkpoint, don't you?


Re: Need help with getting closest checkpoint - bugmenotlol - 15.10.2016

it gives some warn for these lines
PHP код:
dist GetPlayerDistanceFromPoint(playerid,CD1Locations[i][1],CD1Locations[i][2],CD1Locations[i][3]); 
warning : tag mismatch


Re: Need help with getting closest checkpoint - bugmenotlol - 15.10.2016

and also it only gives first checkpoint and not giving other cps


Re: Need help with getting closest checkpoint - bugmenotlol - 15.10.2016

Bumb


Re: Need help with getting closest checkpoint - bugmenotlol - 15.10.2016

Problem Solved
Rep ++ to Mencent
Ty Mate <3