SA-MP Forums Archive
[SOLVED]Vehicles in array mb? - 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: [SOLVED]Vehicles in array mb? (/showthread.php?tid=77484)



[SOLVED]Vehicles in array mb? - kLx - 11.05.2009

Hi. How to create an array and then spawn them all?
Should be something like thiz i think :
Код:
new Float:Lvl1Cars[6][4] = {
{475,-2403.4028,-585.0956,132.4523},
{496,-2401.5789,-587.4331,132.3648},
{516,-2398.2153,-592.2234,132.4835},
{526,-2396.0784,-594.5043,132.4151},
{527,-2394.3152,-596.9808,132.3637}
};
And then what i should do, with create vehicle?
If I'm wrong, fix me.
Thx


Re: Vehicles in array mb? - Weirdosport - 11.05.2009

for(new a=0; a<6; a++)
{
CreateVehicle(Lvl1Cars[a][0],Lvl1Cars[a][1],Lvl1Cars[a][2],Lvl1Cars[a][3], 0.0, -1, -1, 10);
}

-1 and -1 are random car colours, and 10 is the respawn time. Seeing as you don't have rotations in the array, I left it as 0.0


Re: Vehicles in array mb? - kLx - 11.05.2009

Thx, will try tomorrow


Re: Vehicles in array mb? - Ipuvaepe - 11.05.2009

Quote:
Originally Posted by Weirdosport
for(new a=0; a<6; a++)
{
CreateVehicle(Lvl1Cars[a][0],Lvl1Cars[a][1],Lvl1Cars[a][2],Lvl1Cars[a][3], 0.0, -1, -1, 10);
}

-1 and -1 are random car colours, and 10 is the respawn time. Seeing as you don't have rotations in the array, I left it as 0.0
-1 and -1 work, but IMO it would be better to use random(127) as that will randomly pick a color. -1 is a client side color value and it will (due to random nature it could theoretically be the same sometimes) be different on each client.


Re: Vehicles in array mb? - kLx - 12.05.2009

Код:
new Float:Lvl1Cars[6][7] = {
{475,-2403.4028,-585.0956,132.4523,124.0673,9,39},
{496,-2401.5789,-587.4331,132.3648,124.0307,66,72},
{516,-2398.2153,-592.2234,132.4835,125.1812,119,1},
{526,-2396.0784,-594.5043,132.4151,125.4051,17,1},
{527,-2394.3152,-596.9808,132.3637,126.0274,66,1}
};
I've added rotations, and car colors.
I've edited the code i got by WeirdSport to this :
Код:
  for(new a=0; a<6; a++)
{
CreateVehicle(Lvl1Cars[a][0],Lvl1Cars[a][1],Lvl1Cars[a][2],Lvl1Cars[a][3], Lvl1Cars[a][4], Lvl1Cars[a][5], Lvl1Cars[a][6], 10);
}
And I get these errors/warnings :

Код:
D:\Drift\gamemodes\drift.pwn(32) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(32) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(32) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(33) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(33) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(33) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(34) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(34) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(34) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(35) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(35) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(35) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(36) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(36) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(36) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(37) : error 052: multi-dimensional arrays must be fully initialized
D:\Drift\gamemodes\drift.pwn(773) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(773) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(773) : warning 213: tag mismatch
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.



Re: Vehicles in array mb? - yom - 12.05.2009

Because your Lvl1Cars[a][0], Lvl1Cars[a][5] and Lvl1Cars[a][6] aren't Floats.

You have to use an enum as in this example:
pawn Код:
enum CARS_DATA
{
  MODELID,
  Float:X,
  Float:Y,
  Float:Z,
  Float:A,
  C1,
  C2
};

new Lvl1Cars[][CARS_DATA] =
{
  {475,-2403.4028,-585.0956,132.4523,124.0673,9,39},
  {496,-2401.5789,-587.4331,132.3648,124.0307,66,72},
  {516,-2398.2153,-592.2234,132.4835,125.1812,119,1},
  {526,-2396.0784,-594.5043,132.4151,125.4051,17,1},
  {527,-2394.3152,-596.9808,132.3637,126.0274,66,1}
};
Notice the new Lvl1Cars[][CARS_DATA]. When no size is specified, it's calculated when you compile. Then you can use sizeof to get the size of this array, so you don't need to modify the size in the loop each time you add a vehicle in the array. This will solve the error 52.

pawn Код:
for(new a=0; a< sizeof Lvl1Cars; a++)
{
  CreateVehicle
  (
    Lvl1Cars[a][MODELID],
    Lvl1Cars[a][X],
    Lvl1Cars[a][Y],
    Lvl1Cars[a][Z],
    Lvl1Cars[a][A],
    Lvl1Cars[a][C1],
    Lvl1Cars[a][C2],
    10
  );
}



Re: Vehicles in array mb? - kLx - 12.05.2009

Thx for helping !
But when I added the enum, with the data, and added what you game, I even get more errors/warning.
Код:
D:\Drift\gamemodes\drift.pwn(783) : warning 217: loose indentation
D:\Drift\gamemodes\drift.pwn(800) : warning 217: loose indentation
D:\Drift\gamemodes\drift.pwn(1609) : warning 219: local variable "Z" shadows a variable at a preceding level
D:\Drift\gamemodes\drift.pwn(1610) : warning 219: local variable "X" shadows a variable at a preceding level
D:\Drift\gamemodes\drift.pwn(1611) : warning 219: local variable "Y" shadows a variable at a preceding level
D:\Drift\gamemodes\drift.pwn(1633) : error 035: argument type mismatch (argument 2)
D:\Drift\gamemodes\drift.pwn(1634) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(1634) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(1634) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(1649) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(1650) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(1651) : warning 213: tag mismatch
D:\Drift\gamemodes\drift.pwn(1611) : warning 203: symbol is never used: "Y"
D:\Drift\gamemodes\drift.pwn(1610) : warning 203: symbol is never used: "X"
D:\Drift\gamemodes\drift.pwn(1609) : warning 203: symbol is never used: "Z"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Maybe I'm too dumb?


Re: Vehicles in array mb? - yom - 12.05.2009

It was just an example. Of course if you already have some variables called new X or new Y, you have to modify in the enum and replace with something like CAR_X, CAR_Y, etc..


Re: Vehicles in array mb? - kLx - 12.05.2009

Thanks 0rb, you're amazing.