The correct way to do this?
#1

Whats the correct way of doing this?
Ive done it as a example,
But i dont know the correct way,

pawn Код:
public IsACopCar(vehicleid)
{
   if(GetVehicleModel(vehicleid) == 427)
   {
   else if(GetVehicleModel(vehicleid) == 523);
   {
   else if(GetVehicleModel(vehicleid) == 596);
   {
   else if(GetVehicleModel(vehicleid) == 597);
   {
   else if(GetVehicleModel(vehicleid) == 598);
   {
   else if(GetVehicleModel(vehicleid) == 599);
   {
   else if(GetVehicleModel(vehicleid) == 601)
   {
      return 1;
   }
   else return 0;
}
It used to be:

pawn Код:
public IsACopCar(vehicleid)
{
   if(GetVehicleModel(vehicleid) == 596)
   {
      return 1;
   }
   else return 0;
}
But i want to make it for all cop cars,
How would i do it correctly
Reply
#2

pawn Код:
stock IsACopCar(vehicleid)
{
  if(GetVehicleModel(vehicleid) == 427 || GetVehicleModel(vehicleid) == 523 || GetVehicleModel(vehicleid) == 596
  || GetVehicleModel(vehicleid) == 597 || GetVehicleModel(vehicleid) == 598 || GetVehicleModel(vehicleid) == 599
  || GetVehicleModel(vehicleid) == 601) return true;
  return false;
}
|| stands for OR, so if vehicleModel-ID is 427 OR 523 OR 596 OR .. return true (1), otherwise return false (0).

This is just one of the ways which could be simple for you to understand.
Reply
#3

You could also use switch.
pawn Код:
stock IsACopCar(vehicleid)
{
    switch (vehicleid)
    {
        case 427, 523, 596, 597, 598, 599, 601: return 1;
    }
    return 0;
}
Reply
#4

Quote:
Originally Posted by OnTop2K9
You could also use switch.
pawn Код:
stock IsACopCar(vehicleid)
{
    switch (vehicleid)
    {
        case 427, 523, 596, 597, 598, 599, 601: return 1;
    }
    return 0;
}
Not switch vehicleid.
Switch vehicle model ID.
pawn Код:
stock IsACopCar(vehicleid)
{
    switch(GetVehicleModel(vehicleid))
    {
      case 427, 523, 596..599, 601: return 1;
    }
    return 0;
}
OR:
pawn Код:
stock IsACopCar(vehicleid)
{
    new
        ModelID = GetVehicleModel(vehicleid),
        CopCarID[] = { 427, 523, 596, 597, 598, 599, 601 };
    for(new i; i < sizeof CopCarID; i++)
    {
        if(ModelID == CopCarID[i]) return 1;
    }
    return 0;
}
Reply
#5

Quote:
Originally Posted by Phento
Quote:
Originally Posted by OnTop2K9
You could also use switch.
pawn Код:
stock IsACopCar(vehicleid)
{
    switch (vehicleid)
    {
        case 427, 523, 596, 597, 598, 599, 601: return 1;
    }
    return 0;
}
pawn Код:
stock IsACopCar(vehicleid)
{
    switch(GetVehicleModel(vehicleid))
    {
      case 427, 523, 596..599, 601: return 1;
    }
    return 0;
}
OR:
pawn Код:
stock IsACopCar(vehicleid)
{
    new
        ModelID = GetVehicleModel(vehicleid),
        CopCarID[] = { 427, 523, 596, 597, 598, 599, 601 };
    for(new i; i < sizeof CopCarID; i++)
    {
        if(ModelID == CopCarID[i]) return 1;
    }
    return 0;
}
XD, Im using Don Correlli's,
Anyone check my other topic too: http://forum.sa-mp.com/index.php?topic=148593.0
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)