Help In CP Distance
#1

Hello
I am Scripting a new Server. so i need a Help in getting nearest Checkpoint :

Here is the code

PHP Code:
public StartMission(playerid)
{
    if(
TypeFlight[playerid] == 1// Andromada
    
{
        
StartedMission[playerid] = 1;
        new 
rand random(sizeof(ALocations));
        new 
string2[65], message[128];
        
SetPlayerFlightCheckpoint(playeridALocations[rand][LocX],ALocations[rand][LocY],ALocations[rand][LocZ], 15.0);
        
format(string2sizeof(string2), "%s"ALocations[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."ALocations[rand][LocationName]);
        
SendClientMessage(playeridCOLOR_WHITEmessage);
        
TypeFlight[playerid] = 1;
        
MissionStage[playerid] = 1;
        
WantsRecording[playerid] = 1;
        
Pos1[playerid] = ALocations[rand][LocX];
        
Pos2[playerid] = ALocations[rand][LocY];
        
Pos3[playerid] = ALocations[rand][LocZ]; 
Reply
#2

anyone who can help me ?
Reply
#3

+rep if Helped
Reply
#4

What do you mean?
Reply
#5

I meant that :

When a Player types /work Command it should set the cp that is nearest to that players.
Reply
#6

The closest location instead of random that it currently is?

pawn Code:
new closest_location, Float: tmp_cd, Float: closest_distance = GetPlayerDistanceFromPoint(playerid, ALocations[0][LocX], ALocations[0][LocY], ALocations[0][LocZ]);

for (new i = 1; i != sizeof ALocations; i++)
{
    if ((tmp_cd = GetPlayerDistanceFromPoint(playerid, ALocations[i][LocX], ALocations[i][LocY], ALocations[i][LocZ])) < closest_distance)
    {
        closest_distance = tmp_cd;
        closest_location = i;
    }
}

// to set the position to the closest location use:
ALocations[closest_location][LocX], ALocations[closest_location][LocY], ALocations[closest_location][LocZ]
Reply
#7

this makng my pawno Crash
Reply
#8

Can you post where you placed it/how you used it?
Reply
#9

Here is the Full Code of/work

PHP Code:
//-------- Dodo + Shamal Compatible --------------------------------------------
new DSLocations[][TLocation] =
{
    
// LocationName, LocationX, LocationY, LocationZ
    
{"Prickle Pine Airport Gate A"1109.0206,2563.8406,10.9826},
    {
"Bayside Airport Gate C", -2454.9817,2540.1506,24.7591},
    {
"Palomino Creek Airport Gate C"1919.4451,-483.7521,26.3312},
    {
"Palomino Creek Airport Gate D"1885.7271,-502.4863,26.3312},
    {
"K.A.C.C Regional Gate C"2799.7319,2767.1943,10.8687},
    {
"K.A.C.C Regional Gate D"2815.5737,2757.7551,10.8687},
    {
"K.A.C.C Regional Gate F"2831.6379,2749.2725,10.8687},
    {
"Montgomery Airport Gate D"1277.0098,410.7339,20.3572},
    {
"Montgomery Airport Gate C"1292.0890,431.3974,20.3372},
    {
"Angel Pine Airport Gate C", -1798.5845,-2992.4514,8.4916},
    {
"Angel Pine Airport Gate D", -1808.1495,-2987.5530,8.4916},
    {
"Blueberry Airport Gate C"11.0526,-95.6858,4.2813},
    {
"Blueberry Airport Gate D"9.1205,-118.0340,4.2433},
    {
"Shady Creek Airport Gate D", -1352.9548,-2176.4211,27.6743},
    {
"Shady Creek Airport Gate E", -1336.2051,-2182.0254,26.7054},
    {
"Shady Creek Airport Gate F", -1313.5453,-2185.2051,26.7054},
    {
"Santa Maria Airport Gate D"43.1413,-1717.3152,4.8812},
    {
"Santa Maria Airport Gate F"38.5412,-1703.2230,4.8205},
    {
"Indiana Airport Gate C", -694.9243,1272.1669,12.2733},
    {
"Indiana Airport Gate D", -681.6368,1270.1713,12.2733}
};
else if(
TypeFlight[playerid] == 3// Shamal
    
{
        
StartedMission[playerid] = 1;
        new 
rand random(sizeof(DSLocations));
        new 
string2[65], message[128];
        
SetPlayerFlightCheckpoint(playeridDSLocations[rand][LocX],DSLocations[rand][LocY],DSLocations[rand][LocZ], 15.0);
        
format(string2sizeof(string2), "%s"DSLocations[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 passengers."DSLocations[rand][LocationName]);
        
SendClientMessage(playeridCOLOR_WHITEmessage);
        
MissionStage[playerid] = 1;
        
WantsRecording[playerid] = 1;
        
Pos1[playerid] = DSLocations[rand][LocX];
        
Pos2[playerid] = DSLocations[rand][LocY];
        
Pos3[playerid] = DSLocations[rand][LocZ];
    }
if(
strcmp(cmd"/work"true) == || strcmp(cmd"/w"true) == 0)
    {
        if(
StartedMission[playerid] == 1)
        {
            
SendClientMessage(playeridCOLOR_ERROR"You are already on a mission! (/cancel to quit the mission)");
            return 
1;
        }
        if(
IsTracingHouse[playerid] == 1)
        {
            
SendClientMessage(playeridCOLOR_ERROR"You are currently locating a house. Please complete it first.");
            return 
1;
        }
        if(
IsLocatingVehicle[playerid] == 1)
        {
            
SendClientMessage(playeridCOLOR_ERROR"You are currently locating a vehicle. Please complete it first.");
            return 
1;
        }
        new 
vehid GetPlayerVehicleID(playerid);
        if(
GetPlayerVehicleSeat(playerid) != 0)
        {
            
SendClientMessage(playeridCOLOR_ERROR"You must be the main driver of a vehicle to start working!");
            return 
1;
        }
        if(
IsAirVehicle(vehid))
        {
            if(
PInfo[playerid][TotalScore] == 0)
            {
                new 
msg[200];
                
format(msg,sizeof(msg),"Hey! It looks like you have not completed a flight yet! This is just to help you out:");
                
SendClientMessage(playeridCOLOR_GREENmsg);
                
format(msg,sizeof(msg),"-When you do missions (/work), it will ask you to fly to a destination. Fly there and land, and it will give another checkpoint.");
                
SendClientMessage(playeridCOLOR_GREENmsg);
                
format(msg,sizeof(msg),"-When you complete the mission, you gain money, in which you can purchase vehicle's, houses or even your own airline!");
                
SendClientMessage(playeridCOLOR_GREENmsg);
                
format(msg,sizeof(msg),"-All of that information is just to help you understand the main features of the PoT, but there is ALOT more to come! - Have fun!");
                
SendClientMessage(playeridCOLOR_GREENmsg);
            }
            new 
modelid GetVehicleModel(vehid);
            if(
modelid == 592//andromada
            
{
                
TypeFlight[playerid] = 1;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 577// at-400
            
{
                   
TypeFlight[playerid] = 2;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 519// shamal
            
{
                   
TypeFlight[playerid] = 3;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 593// dodo
            
{
                   
TypeFlight[playerid] = 4;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 553// nevada
            
{
                   
TypeFlight[playerid] = 5;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 487// Maverick
            
{
                
TypeFlight[playerid] = 6;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 488// News Maverick
            
{
                
TypeFlight[playerid] = 7;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 497// Police Maverick
            
{
                
TypeFlight[playerid] = 8;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 417// Leviathan
            
{
                
TypeFlight[playerid] = 9;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 447// Seasparrow
            
{
                
TypeFlight[playerid] = 10;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 469// Sparrow
            
{
                
TypeFlight[playerid] = 11;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 548// Cargobob
            
{
                
TypeFlight[playerid] = 12;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 563//Raindance
            
{
                
TypeFlight[playerid] = 13;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 425//Hunter
            
{
                
TypeFlight[playerid] = 14;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 460//Skimmer
            
{
                
TypeFlight[playerid] = 15;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 512//Cropduster
            
{
                
TypeFlight[playerid] = 16;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 511//Beagle
            
{
                
TypeFlight[playerid] = 17;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 520//Hydra
            
{
                
TypeFlight[playerid] = 18;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
        }
        else
        {
            
SendClientMessage(playeridCOLOR_ERROR"You must be in an plane/helicopter to start working !");
            return 
1;
        }
    } 
Where i Have to Add it ??
Reply
#10

Quote:
Originally Posted by Shaheen
View Post
Here is the Full Code of/work

PHP Code:
else if(TypeFlight[playerid] == 3// Shamal
    
{
        
StartedMission[playerid] = 1;
        new 
rand random(sizeof(DSLocations));
        new 
string2[65], message[128];
        
SetPlayerFlightCheckpoint(playeridDSLocations[rand][LocX],DSLocations[rand][LocY],DSLocations[rand][LocZ], 15.0);
        
format(string2sizeof(string2), "%s"DSLocations[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 passengers."DSLocations[rand][LocationName]);
        
SendClientMessage(playeridCOLOR_WHITEmessage);
        
MissionStage[playerid] = 1;
        
WantsRecording[playerid] = 1;
        
Pos1[playerid] = DSLocations[rand][LocX];
        
Pos2[playerid] = DSLocations[rand][LocY];
        
Pos3[playerid] = DSLocations[rand][LocZ];
    } 
This is out of any callback? and i don't see nothing from what Konstantinos gave you yet
Reply
#11

Quote:
Originally Posted by Shinja
View Post
This is out of any callback? and i don't see nothing from what Konstantinos gave you yet
when i use that callbacks my pawno getting crashed
Reply
#12

bump anyone plz
Reply
#13

guys its been 2 days still no replay
Plz Help
Reply
#14

Bumbp Anyone plxx
Reply
#15

I have Done this but my Pawno Crashes

[php]
Here is the Full Code of/work

PHP Code:
//-------- Dodo + Shamal Compatible --------------------------------------------
new DSLocations[][TLocation] =
{
    
// LocationName, LocationX, LocationY, LocationZ
    
{"Prickle Pine Airport Gate A"1109.0206,2563.8406,10.9826},
    {
"Bayside Airport Gate C", -2454.9817,2540.1506,24.7591},
    {
"Palomino Creek Airport Gate C"1919.4451,-483.7521,26.3312},
    {
"Palomino Creek Airport Gate D"1885.7271,-502.4863,26.3312},
    {
"K.A.C.C Regional Gate C"2799.7319,2767.1943,10.8687},
    {
"K.A.C.C Regional Gate D"2815.5737,2757.7551,10.8687},
    {
"K.A.C.C Regional Gate F"2831.6379,2749.2725,10.8687},
    {
"Montgomery Airport Gate D"1277.0098,410.7339,20.3572},
    {
"Montgomery Airport Gate C"1292.0890,431.3974,20.3372},
    {
"Angel Pine Airport Gate C", -1798.5845,-2992.4514,8.4916},
    {
"Angel Pine Airport Gate D", -1808.1495,-2987.5530,8.4916},
    {
"Blueberry Airport Gate C"11.0526,-95.6858,4.2813},
    {
"Blueberry Airport Gate D"9.1205,-118.0340,4.2433},
    {
"Shady Creek Airport Gate D", -1352.9548,-2176.4211,27.6743},
    {
"Shady Creek Airport Gate E", -1336.2051,-2182.0254,26.7054},
    {
"Shady Creek Airport Gate F", -1313.5453,-2185.2051,26.7054},
    {
"Santa Maria Airport Gate D"43.1413,-1717.3152,4.8812},
    {
"Santa Maria Airport Gate F"38.5412,-1703.2230,4.8205},
    {
"Indiana Airport Gate C", -694.9243,1272.1669,12.2733},
    {
"Indiana Airport Gate D", -681.6368,1270.1713,12.2733}
};
else if(
TypeFlight[playerid] == 3// Shamal
    
{
        
StartedMission[playerid] = 1;
        new 
rand random(sizeof(DSLocations));
        new 
string2[65], message[128];
        
SetPlayerFlightCheckpoint(playeridDSLocations[rand][LocX],DSLocations[rand][LocY],DSLocations[rand][LocZ], 15.0);
        
format(string2sizeof(string2), "%s"DSLocations[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 passengers."DSLocations[rand][LocationName]);
        
SendClientMessage(playeridCOLOR_WHITEmessage);
        
MissionStage[playerid] = 1;
        
WantsRecording[playerid] = 1;
        
Pos1[playerid] = DSLocations[rand][LocX];
        
Pos2[playerid] = DSLocations[rand][LocY];
        
Pos3[playerid] = DSLocations[rand][LocZ];
    }
new 
closest_locationFloattmp_cdFloatclosest_distance GetPlayerDistanceFromPoint(playeridALocations[0][LocX], ALocations[0][LocY], ALocations[0][LocZ]);
for (new 
1!= sizeof ALocationsi++)
{
    if ((
tmp_cd GetPlayerDistanceFromPoint(playeridALocations[i][LocX], ALocations[i][LocY], ALocations[i][LocZ])) < closest_distance)
    {
          
closest_distance tmp_cd;
          
closest_location i;
    }
}
// to set the position to the closest location use:
ALocations[closest_location][LocX], ALocations[closest_location][LocY], ALocations[closest_location][LocZ]
if(
strcmp(cmd"/work"true) == || strcmp(cmd"/w"true) == 0)
    {
        if(
StartedMission[playerid] == 1)
        {
            
SendClientMessage(playeridCOLOR_ERROR"You are already on a mission! (/cancel to quit the mission)");
            return 
1;
        }
        if(
IsTracingHouse[playerid] == 1)
        {
            
SendClientMessage(playeridCOLOR_ERROR"You are currently locating a house. Please complete it first.");
            return 
1;
        }
        if(
IsLocatingVehicle[playerid] == 1)
        {
            
SendClientMessage(playeridCOLOR_ERROR"You are currently locating a vehicle. Please complete it first.");
            return 
1;
        }
        new 
vehid GetPlayerVehicleID(playerid);
        if(
GetPlayerVehicleSeat(playerid) != 0)
        {
            
SendClientMessage(playeridCOLOR_ERROR"You must be the main driver of a vehicle to start working!");
            return 
1;
        }
        if(
IsAirVehicle(vehid))
        {
            if(
PInfo[playerid][TotalScore] == 0)
            {
                new 
msg[200];
                
format(msg,sizeof(msg),"Hey! It looks like you have not completed a flight yet! This is just to help you out:");
                
SendClientMessage(playeridCOLOR_GREENmsg);
                
format(msg,sizeof(msg),"-When you do missions (/work), it will ask you to fly to a destination. Fly there and land, and it will give another checkpoint.");
                
SendClientMessage(playeridCOLOR_GREENmsg);
                
format(msg,sizeof(msg),"-When you complete the mission, you gain money, in which you can purchase vehicle's, houses or even your own airline!");
                
SendClientMessage(playeridCOLOR_GREENmsg);
                
format(msg,sizeof(msg),"-All of that information is just to help you understand the main features of the PoT, but there is ALOT more to come! - Have fun!");
                
SendClientMessage(playeridCOLOR_GREENmsg);
            }
            new 
modelid GetVehicleModel(vehid);
            if(
modelid == 592//andromada
            
{
                
TypeFlight[playerid] = 1;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 577// at-400
            
{
                   
TypeFlight[playerid] = 2;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 519// shamal
            
{
                   
TypeFlight[playerid] = 3;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 593// dodo
            
{
                   
TypeFlight[playerid] = 4;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 553// nevada
            
{
                   
TypeFlight[playerid] = 5;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 487// Maverick
            
{
                
TypeFlight[playerid] = 6;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 488// News Maverick
            
{
                
TypeFlight[playerid] = 7;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 497// Police Maverick
            
{
                
TypeFlight[playerid] = 8;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 417// Leviathan
            
{
                
TypeFlight[playerid] = 9;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 447// Seasparrow
            
{
                
TypeFlight[playerid] = 10;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 469// Sparrow
            
{
                
TypeFlight[playerid] = 11;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 548// Cargobob
            
{
                
TypeFlight[playerid] = 12;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 563//Raindance
            
{
                
TypeFlight[playerid] = 13;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 425//Hunter
            
{
                
TypeFlight[playerid] = 14;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 460//Skimmer
            
{
                
TypeFlight[playerid] = 15;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 512//Cropduster
            
{
                
TypeFlight[playerid] = 16;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 511//Beagle
            
{
                
TypeFlight[playerid] = 17;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
            else if(
modelid == 520//Hydra
            
{
                
TypeFlight[playerid] = 18;
                
MissionVehicle[playerid] = vehid;
                
StartMission(playerid);
                return 
1;
            }
        }
        else
        {
            
SendClientMessage(playeridCOLOR_ERROR"You must be in an plane/helicopter to start working !");
            return 
1;
        }
    } 
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)