Help with a command, sscanf, vehicle type.
#1

Hi guys, Im making my pilot server, but the command is not working, I don't know why.
So, even if you are in a plane, it says you are not in a plane.
Tried everything, hopefully someone can help me here:
pawn Код:
CMD:flight(playerid, vehicleid, params[])
{
    if(GetVehicleModel(vehicleid) !=511 || GetVehicleModel(vehicleid) !=512 || GetVehicleModel(vehicleid) != 513 || GetVehicleModel(vehicleid) != 519  || GetVehicleModel(vehicleid) != 520  || GetVehicleModel(vehicleid) != 553  || GetVehicleModel(vehicleid) != 577  || GetVehicleModel(vehicleid) != 592  || GetVehicleModel(vehicleid) != 593  || GetVehicleModel(vehicleid) != 460  || GetVehicleModel(vehicleid) != 476)
    return SCM(playerid, COLOR_RED, "You need to be in a plane to use this!");
    else if (GetVehicleModel(vehicleid) ==511 || GetVehicleModel(vehicleid) ==512 || GetVehicleModel(vehicleid) == 513 || GetVehicleModel(vehicleid) == 519  || GetVehicleModel(vehicleid) == 520  || GetVehicleModel(vehicleid) == 553  || GetVehicleModel(vehicleid) == 577  || GetVehicleModel(vehicleid) == 592  || GetVehicleModel(vehicleid) == 593  || GetVehicleModel(vehicleid) == 460  || GetVehicleModel(vehicleid)== 476)
    {
        new destination[32];
        if(sscanf(destination, "s[32]", destination))
        {
            SCM(playerid, COLOR_WHITE, "USAGE: /flight [destination]!");
            SCM(playerid, Grey, "Available Destinations: LS | SF | LV");
        }
        if(strcmp(destination, "LS", true) == 0)
        {
            if(IsAtLS[playerid] == 1) return SCM(playerid, COLOR_YELLOW, "Choose another destination, you already are at the Los Santos Airport!");
            else
            {
            IsDoingJob[playerid] = 1;
            lsarrive = CreateDynamicCP(1809.7552,-2593.3799,13.5469, 10, -1, -1, playerid, 100);
            SendClientMessage(playerid, COLOR_YELLOW, "Your next destination has been set at Los Santos Airport. Check your radar for directions!");
            }
        }
        if(strcmp(destination, "SF", true) == 0)
        {
            if(IsAtSF[playerid] == 1) return SCM(playerid, COLOR_YELLOW,"Choose another destination, you already are at the San Fierro Airport!");
            else
            {
            IsDoingJob[playerid] = 1;
            sfarrive = CreateDynamicCP(-1379.8064,116.2202,14.8811, 10, -1, -1, playerid, 100);
            SendClientMessage(playerid, COLOR_YELLOW, "Your next destination has been set at San Fierro Airport. Check your radar for directions!");
            }

        }
    }
    return 1;
}
Again, it keeps saying Im not in a plane.
If someone could help, I'd appreciate it.
Thank you.
Reply
#2

Well, you need to understand logical operations.

pawn Код:
if(A != 5 || A != 6)
|| means or, so if A is not equal 5 then first condition is met, and if A is not equal 6 then the second condition is met. This makes this statement redundant, and in your case wrong. You need && operator in first line
pawn Код:
if(GetVehicleModel(vehicleid) !=511 && GetVehicleModel(vehicleid) !=512 && ... GetVehicleModel(vehicleid) != 476)
Notice! Don't touch the OR (||) operator when you are checking for specific id, like
pawn Код:
else if (GetVehicleModel(vehicleid) ==511 || GetVehicleModel(vehicleid) ==512 || ... GetVehicleModel(vehicleid)== 476)
This is correct
Reply
#3

Well all I need is that when you're in one of them above vehicle IDs, the CMD will function.
I even tried the:
pawn Код:
if(GetVehicleModel(vehicleid) !=511 && GetVehicleModel(vehicleid) !=512 && GetVehicleModel(vehicleid) != 513 && GetVehicleModel(vehicleid) != 519  && GetVehicleModel(vehicleid) != 520  && GetVehicleModel(vehicleid) != 553  && GetVehicleModel(vehicleid) != 577  && GetVehicleModel(vehicleid) != 592  && GetVehicleModel(vehicleid) != 593  && GetVehicleModel(vehicleid) != 460  && GetVehicleModel(vehicleid) != 476)
Didn't work either....
What should I do now?
Reply
#4

#up: I didn't mean to say that OR should be avoided, sorry for poor wording (english confuses me sometimes)

Ok, let's try diffrent approach. Currently your code is quite messy, remember that brackets are very important, and if you are skipping them you have to be very, very careful. Your return currently cuts of else if, and I don't know if, but probably isn't even executed in if context. Are you sure that CMD provides vehicleid? I don't trust this.


Take a look at this code: I've removed unnecessary GetVehicleModel function calls, and unncessary strcmp instructions in case some condition is not met.

pawn Код:
CMD:flight(playerid, params[])
{
    new
        vid = GetPlayerVehicleID(playerid),
        vehicleModel = INVALID_VEHICLE_ID == vid ? INVALID_VEHICLE_ID : GetVehicleModel(vid);

    switch(vehicleModel) {
        case 511, 512, 513, 519, 520, 553, 577, 592, 593, 460, 476: {
            new destination[32];
            if(sscanf(destination, "s[32]", destination))
            {
                SCM(playerid, COLOR_WHITE, "USAGE: /flight [destination]!");
                return SCM(playerid, Grey, "Available Destinations: LS | SF | LV");
            }
           
            if(!strcmp(destination, "LS", true))
            {
                if(IsAtLS[playerid] == 1) return SCM(playerid, COLOR_YELLOW, "Choose another destination, you already are at the Los Santos Airport!");
                else
                {
                    IsDoingJob[playerid] = 1;
                    lsarrive = CreateDynamicCP(1809.7552,-2593.3799,13.5469, 10, -1, -1, playerid, 100);
                    return SendClientMessage(playerid, COLOR_YELLOW, "Your next destination has been set at Los Santos Airport. Check your radar for directions!");
                }
            }
            if(!strcmp(destination, "SF", true))
            {
                if(IsAtSF[playerid] == 1) return SCM(playerid, COLOR_YELLOW,"Choose another destination, you already are at the San Fierro Airport!");
                else
                {
                    IsDoingJob[playerid] = 1;
                    sfarrive = CreateDynamicCP(-1379.8064,116.2202,14.8811, 10, -1, -1, playerid, 100);
                    return SendClientMessage(playerid, COLOR_YELLOW, "Your next destination has been set at San Fierro Airport. Check your radar for directions!");
                }
            }
        }
        default: {
            return SCM(playerid, COLOR_RED, "You need to be in a plane to use this!");
        }
    }
}
Reply
#5

Fixed, nevermind.

EDIT: Just a question, checkpoint is not visible until I approach the area..
I think it's the stream distance which bugs it, but I did stream distance to -1, should I do like 9999999 or -1?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)