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(playeridpos[0], pos[1], pos[2]);
            
SetPlayerPos(playeridpos[0], pos[1], pos[2]);
            
SendClientMessage(playeridCOLOR_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:xFloat:yFloat:z;
                
GetPlayerPos(playeridxyz);
                  
FlightPosition[playerid][0] = x;
                
FlightPosition[playerid][1] = y;
                
FlightPosition[playerid][2] = z;
                switch (
airport)
                {
                    case 
0:
                    {
                        
SetPlayerCheckpoint(playerid, -1462.822630.548114.148415.0);
                        
destination "San Fierro Airport";
                    }
                    case 
1:
                    {
                        
SetPlayerCheckpoint(playerid1477.29361664.123410.812515.0);
                        
destination "Las Venturas Airport";
                    }
                }
                
CP[playerid] = 2425;
                
format(stringsizeof(string), "* %s enters the plane and starts it up."RPN(playerid));
                
SendClientMessage(playeridCOLOR_PURPLEstring);
                
SendClientMessage(playeridCOLOR_PURPLE"* 20 minutes later, the passengers board the plane.");
                
format(stringsizeof(string), "Your destination is %s. Land the plane into the checkpoint on the runway."destination);
                
SendClientMessage(playeridCOLOR_YELLOWstring);
            }
            else return 
SendClientMessage(playeridCOLOR_GREY"You have to start the flight first (/startflight).");
        }
    } 
CMD:Startflight
PHP код:
CMD:startflight(playeridparams[])
{
        new 
string[128];
        if(
PlayerInfo[playerid][pJob] != JOB_PILOT && PlayerInfo[playerid][pVIPJob] != JOB_PILOT) return SendClientMessage(playeridCOLOR_GREY"You are not a pilot.");
        {
            if (
IsPlayerInRangeOfPoint(playerid20.01891.9252, -2328.712913.5469))
            {
                if(
PackTime[playerid] > 0)
                {
                    
format(stringsizeof(string), "You need to wait %d more seconds before starting a new flight."PackTime[playerid]);
                     
SendClientMessage(playeridCOLOR_GREYstring);
                    return 
1;
                }
                
PackTime[playerid] = 180;
                
SetTimerEx("PackTimer"1000false"i"playerid);
                if (
FlightStarted[playerid] == 0)
                 {
                    if (
FlightCooldown[playerid] > 0) return format(stringsizeof(string), "You still have %d seconds left before you can do another flight."FlightCooldown[playerid]), SendClientMessage(playeridCOLOR_GREYstring);
                    
FlightStarted[playerid] = 1;
                    
SendClientMessage(playeridCOLOR_YELLOW"You're about to start a flight, enter a plane.");
                    return 
1;
                }
                else return 
SendClientMessage(playeridCOLOR_GREY"    You already started a flight.");
            }
            else return 
SendClientMessage(playeridCOLOR_GREY"    You are not at the flight center.");
        }

stock IsPilotVehicle
PHP код:
stock IsPilotVehicle(vehicleid)
{
    for(new 
i=0i<1i++)
    {
        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=0i<=1i++) // 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(playeridpos[0], pos[1], pos[2]);
            
SetPlayerPos(playeridpos[0], pos[1], pos[2]);
            
SendClientMessage(playeridCOLOR_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=0i<=1i++) // 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(playeridpos[0], pos[1], pos[2]);
            
SetPlayerPos(playeridpos[0], pos[1], pos[2]);
            
SendClientMessage(playeridCOLOR_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(playeridpos[0], pos[1], pos[2]);
                
SetPlayerPos(playeridpos[0], pos[1], pos[2]);
                
SendClientMessage(playeridCOLOR_ORANGE"You cannot start the engine as it belongs to the Los Santos Airline Company.");
            }
        } 
Stock
PHP код:
stock IsPilotVehicle(vehicleid)
{
    for(new 
i=0i<2i++)
    {
        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: 1 Guest(s)