shorter code... - 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: shorter code... (
/showthread.php?tid=109877)
shorter code... -
DiddyBop - 22.11.2009
Hi, can somebody explain to me how i can make a shorter code to add Nos to all vehicles? this is what i have..
pawn Код:
lilgunna = AddStaticVehicleEx(560, 288.13833618164, 2472.4133300781, 16.281105041504, 0.000000, -1, -1, 60); //32
lilgunna = AddStaticVehicleEx(560, 284.63854980469, 2472.4951171875, 16.281105041504, 0.000000, -1, -1, 60); //33
lilgunna = AddStaticVehicleEx(560, 280.38958740234, 2472.5947265625, 16.281105041504, 0.000000, -1, -1, 60); //34
lilgunna = AddStaticVehicleEx(560, 276.63958740234, 2472.6826171875, 16.281105041504, 0.000000, -1, -1, 60); //35
Thats the vehicleid, now here is cb.
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if (vehicleid == lilgunna)
{
AddVehicleComponent(lilgunna, 1010); // Nitro
}
return 1;
}
My issue is, its only adding the nos to the last vehicle on that list. So how can i do it without re-making 500 "if(vehicleid"'s?
Re: shorter code... -
Kyosaur - 22.11.2009
use arrays/a loop
![](http://i138.photobucket.com/albums/q278/morrisdamon/cheesy.gif)
.
Re: shorter code... -
DiddyBop - 22.11.2009
im new.. lol.. so like you just saying use arrays/loop pwns my knowledge.
Do you mean like..
pawn Код:
new 1;
new 2;
new 3;
new 4;
new 5;
Do tht?
Re: shorter code... -
Correlli - 22.11.2009
pawn Код:
lilgunna[0] = AddStaticVehicleEx(560, 288.13833618164, 2472.4133300781, 16.281105041504, 0.000000, -1, -1, 60); //32
lilgunna[1] = AddStaticVehicleEx(560, 284.63854980469, 2472.4951171875, 16.281105041504, 0.000000, -1, -1, 60); //33
lilgunna[2] = AddStaticVehicleEx(560, 280.38958740234, 2472.5947265625, 16.281105041504, 0.000000, -1, -1, 60); //34
lilgunna[3] = AddStaticVehicleEx(560, 276.63958740234, 2472.6826171875, 16.281105041504, 0.000000, -1, -1, 60); //35
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
new
i;
for(i = 0; i < sizeof(lilgunna); i++)
{
if(vehicleid == lilgunna[i]) AddVehicleComponent(lilgunna[i], 1010); // Nitro
}
return 1;
}
You could use ******'s foreach, it's faster than normal for.
Re: shorter code... -
DiddyBop - 22.11.2009
thx don