Problem with if(GetVehicleModel(vehicleid) == 596||597||598||427||523||599||601)
#1

I am wanting to have some functions only run if the vehicle id is a certain vehicle model.
I know that || is supposed to mean "or" when in an "if"

So that if I did something like:
pawn Код:
// My code that displays for all vehicles, not just the ones listed
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(GetVehicleModel(vehicleid) == 596||597||598||427||523||599||601)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Nice Police Vehicle!");
    }
    return 1;
}
One thing it does fine is sending the message.
What is does wrong is that it sends it for all vehicles and not just the IDs specified (police vehicles)

Is there something I am doing wrong, or is it bugged, since the Wiki example for GetVehicleModel is exactly the same, except for the fact I am using || so that it will display on more then just the one ID:
pawn Код:
// Example from the wiki https://sampwiki.blast.hk/wiki/GetVehicleModel
public OnPlayerEnterVehicle(playerid,vehicleid,ispassenger)
{
    if(GetVehicleModel(vehicleid) == 411) // 411 is the infernus model
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Nice Infernus!");
    }
    return 1;
}
Thanks for any help!
Reply
#2

Try this:

pawn Код:
// My code that displays for all vehicles, not just the ones listed
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(vehicleid == 596||597||598||427||523||599||601)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Nice Police Vehicle!");
    }
    return 1;
}
Reply
#3

use OnPlayerStateChange.
Reply
#4

Ignore them^^

Your if statement is wrong. Here is switch, and also how an if statement should be. Use the switch though its better.

pawn Код:
switch( GetVehicleModel(vehicleid) )
{
    case 596, 597, 598, 427, 523, 599, 601:
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Nice Police Vehicle!");
    }
}

//Or an if statement

new vehiclemodel = GetVehicleModel( vehicleid );

if( vehiclemodel == 596 || vehiclemodel == 597 || vehiclemodel == 427 || vehiclemodel == 523 || vehiclemodel == 599 || vehiclemodel == 601 )
{
    SendClientMessage(playerid, 0xFFFFFFFF, "Nice Police Vehicle!");
}
Reply
#5

Quote:
Originally Posted by pasha97
Посмотреть сообщение
Try this:

pawn Код:
// My code that displays for all vehicles, not just the ones listed
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(vehicleid == 596||597||598||427||523||599||601)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Nice Police Vehicle!");
    }
    return 1;
}
Well the vehicle ID is just the number assigned by the server, so the first vehicle spawned would be 0, the second would be 1 and so on, and not the actual car model.

Quote:
Originally Posted by Romel
Посмотреть сообщение
use OnPlayerStateChange.
I don't see how that would make a difference where I put the code.

EDIT:

Quote:
Originally Posted by iggy1
Посмотреть сообщение
Ignore them^^

Your if statement is wrong. Here is switch, and also how an if statement should be. Use the switch though its better.

pawn Код:
switch( GetVehicleModel(vehicleid) )
{
    case 596, 597, 598, 427, 523, 599, 601:
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "Nice Police Vehicle!");
    }
}

//Or an if statement

new vehiclemodel = GetVehicleModel( vehicleid );

if( vehiclemodel == 596 || vehiclemodel == 597 || vehiclemodel == 427 || vehiclemodel == 523 || vehiclemodel == 599 || vehiclemodel == 601 )
{
    SendClientMessage(playerid, 0xFFFFFFFF, "Nice Police Vehicle!");
}
This is exactly what I was looking for, thanks a ton!
Reply
#6

Try this:

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/work", cmdtext, true, 10) == 0)
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        if(GetVehicleModel(vehicleid) == 519 || GetVehicleModel(vehicleid) == 592 || GetVehicleModel(vehicleid) == 520)
        {
           PilotJob[playerid] = 1;
           SetPlayerCheckpoint(playerid, -1301.9893,-347.4291,14.1484,3.50);
           SendClientMessage(playerid, -1,"{CE0000}You started a mission,Go to SF Airport Gate 2 to start the flight!");
           return 1;
        }
        else SendClientMessage(playerid, -1,"You have to be on a plane to start the flight!");
    }
    return 0;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(GetVehicleModel(vehicleid) == 519 || GetVehicleModel(vehicleid) == 592 || GetVehicleModel(vehicleid) == 520)
    {
        SendClientMessage(playerid, -1, "Job: You can start the flight by using {00FF00}/work");
    }
    else SendClientMessage(playerid,-1,"Sorry You can't start mission if you don't type /work");
    return 0;
}
I'm fairly certain you cannot just put the numbers between the or statements. You must do the same thing you did for the first one.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)