Pilot commands doesnt work
#1

Heya
I am trying to edit my pilot job and when I tried restricting vehicle entry to pilots only
It simply allows everyone + If you are actually a pilot and taking a flight, Nothing appears
I tried debugging it to printf the vehicle id when IsPilotVehicle is called :
Nothing pops up in console: IsPilotVehicle doesnt work

Code:

OnPlayerEnterVehicle
PHP код:
        else if(IsPilotVehicle(vehicleid) && PlayerInfo[playerid][pJob] != JOB_PILOT && PlayerInfo[playerid][pVIPJob] != JOB_PILOT)
        {
            
printf("TEST = %i.",vehicleid);
              new 
Float:pos[3];
            
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            
SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            
SendClientMessage(playerid, COLOR_ORANGE, "You cannot start the engine as it belongs to the Los Santos Airline Company.");
            return 
1;
        }
        else if(
IsPilotVehicle(vehicleid) && PlayerInfo[playerid][pJob] == JOB_PILOT || PlayerInfo[playerid][pVIPJob] == JOB_PILOT)
        {
            if(
FlightStarted[playerid] == 1)
            {
                    new
                    
airport = random(2),
                    
destination[24],
                    
string[128],
                    
Float:x, Float:y, Float:z;
                
GetPlayerPos(playerid, x, y, z);
                  
FlightPosition[playerid][0] = x;
                
FlightPosition[playerid][1] = y;
                
FlightPosition[playerid][2] = z;
                switch (
airport)
                {
                    case 
0:
                    {
                        
SetPlayerCheckpoint(playerid, -1462.8226, 30.5481, 14.1484, 15.0);
                        
destination = "San Fierro Airport";
                    }
                    case 
1:
                    {
                        
SetPlayerCheckpoint(playerid, 1477.2936, 1664.1234, 10.8125, 15.0);
                        
destination = "Las Venturas Airport";
                    }
                }
                
CP[playerid] = 2425;
                
format(string, sizeof(string), "* %s enters the plane and starts it up.", RPN(playerid));
                
SendClientMessage(playerid, COLOR_PURPLE, string);
                
SendClientMessage(playerid, COLOR_PURPLE, "* 20 minutes later, the passengers board the plane.");
                
format(string, sizeof(string), "Your destination is %s. Land the plane into the checkpoint on the runway.", destination);
                
SendClientMessage(playerid, COLOR_YELLOW, string);
            }
            else return 
SendClientMessage(playerid, COLOR_GREY, "You have to start the flight first (/startflight).");
        }
    } 
CMD:Startflight
PHP код:
CMD:startflight(playerid, params[])
{
        new 
string[128];
        if(
PlayerInfo[playerid][pJob] != JOB_PILOT && PlayerInfo[playerid][pVIPJob] != JOB_PILOT) return SendClientMessage(playerid, COLOR_GREY, "You are not a pilot.");
        {
            if (
IsPlayerInRangeOfPoint(playerid, 20.0, 1891.9252, -2328.7129, 13.5469))
            {
                if(
PackTime[playerid] > 0)
                {
                    
format(string, sizeof(string), "You need to wait %d more seconds before starting a new flight.", PackTime[playerid]);
                     
SendClientMessage(playerid, COLOR_GREY, string);
                    return 
1;
                }
                
PackTime[playerid] = 180;
                
SetTimerEx("PackTimer", 1000, false, "i", playerid);
                if (
FlightStarted[playerid] == 0)
                 {
                    if (
FlightCooldown[playerid] > 0) return format(string, sizeof(string), "You still have %d seconds left before you can do another flight.", FlightCooldown[playerid]), SendClientMessage(playerid, COLOR_GREY, string);
                    
FlightStarted[playerid] = 1;
                    
SendClientMessage(playerid, COLOR_YELLOW, "You're about to start a flight, enter a plane.");
                    return 
1;
                }
                else return 
SendClientMessage(playerid, COLOR_GREY, "    You already started a flight.");
            }
            else return 
SendClientMessage(playerid, COLOR_GREY, "    You are not at the flight center.");
        }
} 
stock IsPilotVehicle
PHP код:
stock IsPilotVehicle(vehicleid)
{
    for(new 
i=0; i<1; i++)
    {
        if(
vehicleid == Plane[i]) return 1;
        
printf("Plane Vehicle ID = %i.",vehicleid);
    }
    return 
0;
} 
CreateVehicle:
PHP код:
    Plane[0] = AddStaticVehicle(592,1922.0416,-2258.0427,14.7435,182.1580,1,1);
    
Plane[1] = AddStaticVehicle(592,1873.4792,-2285.5344,14.7054,269.9822,1,1); 
Reply
#2

PHP код:
stock IsPilotVehicle(vehicleid)
{
    
printf("IsPilotVehicle(%d)", vehicleid);
    for(new 
i=0; i<=1; i++) // you used < instead of <= here
    
{
        
printf("%d", Plane[i]); // also put the printf before the return
        
if(vehicleid == Plane[i]) return 1;
    }
    
printf("No match");
    return 
0;
} 
Be aware that && is superior to ||, you have to use brackets here
PHP код:
else if(IsPilotVehicle(vehicleid) && (PlayerInfo[playerid][pJob] == JOB_PILOT || PlayerInfo[playerid][pVIPJob] == JOB_PILOT)) 
Check Operator precedence in pawn-lang.pdf (page number 110)

Use if and else and avoid calling functions twice if it isn't necessary
PHP код:
else if(IsPilotVehicle(vehicleid))
{
    if(
PlayerInfo[playerid][pJob] != JOB_PILOT && PlayerInfo[playerid][pVIPJob] != JOB_PILOT)
    {
            
printf("TEST = %i.",vehicleid);
              new 
Float:pos[3];
            
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            
SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            
SendClientMessage(playerid, COLOR_ORANGE, "You cannot start the engine as it belongs to the Los Santos Airline Company.");
            return 
1;
    } else {
        if(
FlightStarted[playerid] == 1)
        { 
        
// ...
    
}
} 
Reply
#3

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
PHP код:
stock IsPilotVehicle(vehicleid)
{
    
printf("IsPilotVehicle(%d)", vehicleid);
    for(new 
i=0; i<=1; i++) // you used < instead of <= here
    
{
        
printf("%d", Plane[i]); // also put the printf before the return
        
if(vehicleid == Plane[i]) return 1;
    }
    
printf("No match");
    return 
0;
} 
Be aware that && is superior to ||, you have to use brackets here
PHP код:
else if(IsPilotVehicle(vehicleid) && (PlayerInfo[playerid][pJob] == JOB_PILOT || PlayerInfo[playerid][pVIPJob] == JOB_PILOT)) 
Check Operator precedence in pawn-lang.pdf (page number 110)

Use if and else and avoid calling functions twice if it isn't necessary
PHP код:
else if(IsPilotVehicle(vehicleid))
{
    if(
PlayerInfo[playerid][pJob] != JOB_PILOT && PlayerInfo[playerid][pVIPJob] != JOB_PILOT)
    {
            
printf("TEST = %i.",vehicleid);
              new 
Float:pos[3];
            
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            
SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            
SendClientMessage(playerid, COLOR_ORANGE, "You cannot start the engine as it belongs to the Los Santos Airline Company.");
            return 
1;
    } else {
        if(
FlightStarted[playerid] == 1)
        { 
        
// ...
    
}
} 
P.S: You have taught me something new with the && superior, Thanks in advice!

Well I moved the route starting to PlayerStateChange
That's the new code I tried, It works perfect on another job (Trucker Job - works perfect) - Still doesnt work

StateChange
PHP код:
else if(IsPilotVehicle(vehicleid))
        {
            if(
PlayerInfo[playerid][pFac] != JOB_PILOT && PlayerInfo[playerid][pVIPJob] != JOB_PILOT)
            {
                
printf("TEST = %i.",vehicleid);
                  new 
Float:pos[3];
                
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
                
SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
                
SendClientMessage(playerid, COLOR_ORANGE, "You cannot start the engine as it belongs to the Los Santos Airline Company.");
            }
        } 
Stock
PHP код:
stock IsPilotVehicle(vehicleid)
{
    for(new 
i=0; i<2; i++)
    {
        if(
vehicleid == JobInfo[JOB_PILOT][jCars][i]) return 1;
    }
    return 
0;
} 
Reply
#4

anyone ?
Reply
#5

There should be a fix
Reply


Forum Jump:


Users browsing this thread: