else if and case:
#4

Quote:
Originally Posted by J4mmyHD
Посмотреть сообщение
pawn Код:
IsAPlane(vehicleid)
{
     switch(GetVehicleModel(vehicleid))
     {
          case 460, 476, 511, 512, 513, 519, 520, 553, 577, 592, 593: return 1;
          default: return 0;
     }
     return 0;
}


CMD:airplane(playerid, params[])
{
    new Vehicleid = GetPlayerVehicleID(playerid);
    If(IsAPlane(vehicleid)) return SendClientMessage(playerid, 0xFFFFFFFF, "You are in a Plane!");
    If(!IsAPlane(vehicleid)) return SendClientMessage(playerid, 0xFFFFFFFF, "You are not in a Plane!");
    return 1;
}
If the model is not any of those above, it will just end the switch so the default is pointless.
There's if and not If. An as for the example, you don't need to store the vehicleid to a variable and neither use it IsAPlane function twice.

pawn Код:
// Forward it before using it because of the bool tag.
forward bool: IsAPlane(vehicleid);

// ---

CMD:airplane(playerid, params[])
{
    if(IsAPlane(GetPlayerVehicleID(playerid))) SendClientMessage(playerid, 0xFFFFFFFF, "You are in a Plane!");
    else SendClientMessage(playerid, 0xFFFFFFFF, "You are not in a Plane!");
    return 1;
}

// At the bottom:
stock bool: IsAPlane(vehicleid)
{
    switch(GetVehicleModel(vehicleid))
    {
        case 460, 476, 511 .. 513, 519, 520, 553, 577, 592, 593: return true;
    }
    return false;
}
Reply


Messages In This Thread
else if and case: - by BpX - 30.11.2013, 18:11
Re: else if and case: - by Loot - 30.11.2013, 18:17
Re: else if and case: - by J4mmyHD - 30.11.2013, 18:23
Re: else if and case: - by Konstantinos - 30.11.2013, 18:48
Re: else if and case: - by BpX - 01.12.2013, 13:16

Forum Jump:


Users browsing this thread: 5 Guest(s)