Assigning a vehicle (id) to an array problem
#1

5th Dec - Resolved

Hi all,
I have a 'stock' to load a vehicle from its file, however when i go to spawn the vehicle and associate that vehicle (and its id) to an array, it becomes -1. The vehicle still spawns, but according to the array, the vehicle id is -1 (this is for all vehicles)

Here is the 'LoadVehicle' stock
pawn Код:
stock LoadVehicle(vid)
{
    DestroyVehicle(Vehicles[vid]);
    DestroyDynamic3DTextLabel(VehicleText[vid]);

    new file[64], string[64], Float:x, Float:y, Float:z;
    format(file, sizeof(file), "vehicles/%i.veh", vid);
    Vehicles[vid] = CreateVehicle(dini_Int(file, "Model"), dini_Float(file, "x"), dini_Float(file, "y"), dini_Float(file, "z"), dini_Float(file, "rot"), dini_Int(file, "Colour1"), dini_Int(file, "Colour2"), -1);
    format(string, sizeof(string), "This vehicle is owned by %s\nIt cost %i", dini_Get(file, "Owner"), dini_Int(file, "Cost"));
    GetVehiclePos(Vehicles[vid], x, y, z);
    VehicleText[vid] = CreateDynamic3DTextLabel(string, COLOUR, x, y, z, 5.0, -1, Vehicles[vid], 0, -1, -1, -1, 100.0);
    printf("%i", Vehicles[vid]); //is -1
}
If i wanted to load all vehicles, i would do this...
pawn Код:
for(new i; i < LastID; i++) // Last ID is a variable that is saved to file on filterscript close, and the number is retrieved on filterscript init - this means less looping because i dont have to go through till my max vehicle limit
{
     LoadVehicle(i);
}
Has anyone got any ideas? Its probably a stupid error knowing me

Thanks in advance
Ash
Reply
#2

How large is the array, and what is the maximum value of LastID?
Reply
#3

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
How large is the array, and what is the maximum value of LastID?
The array is the size of LastID (the current maximum vehicles controlled by the script)

The maximum value of LastID is 500. However currently, with the vehicle files loaded, the size dynamically would be 1. This is true as i have printed the 'LastID' variable as well as Vehicles[vid] just to make sure.
Reply
#4

I really can't reproduce this, not with 0.3b or 0.3c. Are you sure you're looking at the right prints ?
Reply
#5

Can you show me where you create this Vehicles[] variable?
Reply
#6

I have the same problem. It doesn't give the ID with -1 but with another number
Reply
#7

Quote:
Originally Posted by xpeppe
Посмотреть сообщение
I have the same problem. It doesn't give the ID with -1 but with another number
Yes, with the actually vehicle id
Reply
#8

Sorry about bumping a now very old thread, however i've ran into the same problem again :/ - Its using the same script, in pretty much the same way.

In response to JaTochNietDan;
pawn Код:
new Vehicles[GENERAL_MAX_VEHICLES]; //GENERAL_MAX_VEHICLES = 500
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)