Array. - 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: Array. (
/showthread.php?tid=366710)
Array. -
BaubaS - 07.08.2012
I have a question, is it possible to make one thing. For example, there is array:
pawn Код:
new Sirens[MAX_SIRENS][someenum] =
{
{411, object x, object y, object z, object rx, object ry, object rz},
{560, object x, object y, object z, object rx, object ry, object rz},
{562, object x, object y, object z, object rx, object ry, object rz}
+-20 other vehicles
};
411, 560, 562 - vehicle model.
Then, for example, I need to attach sirens object to vehicle model 560, but I need to get coordinates from array. How to do that, without having checking IDs like that
pawn Код:
if (GetVehicleModel(some vehicleid) == 411)
{
}
if (GetVehicleModel(some vehicleid) == 560)
{
}
if (GetVehicleModel(some vehicleid) == 562)
{
}
Re: Array. -
Vince - 07.08.2012
Use a loop, I guess. Not really any other way I can think of besides SQLite, which may be too excessive for such a simple thing.
Re: Array. -
BaubaS - 07.08.2012
Like that?
pawn Код:
for (new i; i < MAX_SIRENS; ++i)
{
if (Sirens[i][0] == GetVehicleModel(...))
{
CreateObject(id, Sirens[i][1], Sirens[i][2], Sirens[i][3], Sirens[i][4], Sirens[i][5], Sirens[i][6]);
.........
}
}
Re: Array. -
Vince - 07.08.2012
I'd rather write a custom function to retrieve the array index, but that should work as well.
Re: Array. -
BaubaS - 07.08.2012
I dont think it is better to create a function here, because I will use this only in one piece of code.