Array.
#1

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)
{
}
Reply
#2

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.
Reply
#3

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]);
        .........
    }
}
Reply
#4

I'd rather write a custom function to retrieve the array index, but that should work as well.
Reply
#5

I dont think it is better to create a function here, because I will use this only in one piece of code.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)