SA-MP Forums Archive
The correct way to do this? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: The correct way to do this? (/showthread.php?tid=123368)



The correct way to do this? - Torran - 25.01.2010

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


Re: The correct way to do this? - Correlli - 25.01.2010

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.


Re: The correct way to do this? - On_Top_Non_Stop - 25.01.2010

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



Re: The correct way to do this? - smeti - 25.01.2010

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;
}



Re: The correct way to do this? - Torran - 25.01.2010

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