SA-MP Forums Archive
How to write more of those on a row - 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)
+--- Thread: How to write more of those on a row (/showthread.php?tid=615979)



How to write more of those on a row - AndreiWow - 29.08.2016

Код:
if(vehicleid == meatcar_1 ... meatcar_2 .... meatcar_3
I want them on a row instead of:
Код:
if(vehicleid == meatcar_1)
{
 bla bla
}
if(vehicleid == meatcar_2)

....



Re: How to write more of those on a row - 99fe3rnando - 29.08.2016

PHP код:
if(vehicleid == meatcar_1||vehicleid == meatcar_2



Re: How to write more of those on a row - AndreiWow - 29.08.2016

It works thanks but why I can only enther the third vehicle?
meatcar_1 = CreateVehicle(413,-88.068,1339.272,10.766,187.255,65,0,-1);
meatcar_2 = CreateVehicle(413,-85.147,1339.661,10.875,187.084,65,0,-1);
meatcar_3 = CreateVehicle(413,-106.629,1362.633,10.278,184.002,65,0,-1);
meatcar_4 = CreateVehicle(413,-78.739,1340.336,11.131,186.607,65,0,-1);
meatcar_5 = CreateVehicle(413,-81.778,1339.995,10.993,186.600,65,0,-1);


Re: How to write more of those on a row - Vince - 29.08.2016

Use arrays if you have more than two or three items. This allows for easy loops and easy expansion later on; i.e;:

PHP код:
// global
new gMeatcar[5];

// GameModeInit
gMeatcar[0] = CreateVehicle(...);
// etc

// Wherever
for(new isizeof(gMeatcar); i++)
{
    if(
vehicleid == gMeatcar[i])
    {
        
// do stuff
        
break;
    }




Re: How to write more of those on a row - AndreiWow - 29.08.2016

Oh damn, forgot of that, thank you both