2000 cells big array
#1

I wanted to make an inventory system for every vehicle on the server. For that I would need an array big enough for every vehicle and that is a 2000 cells big array. So my question is: is there any better way of doing that?
Reply
#2

Depends how many vehicles you really have and what kind of data you need to store.
Reply
#3

It should be a dynamic system where you can add any vehicle on the server and a player can automatically use inventory system for that vehicle.
Reply
#4

Then you probably won't need 2000 vehicles I made a quick mock-up to give you an idea of what you will need to do.

pawn Код:
#define         MAX_DYNAMIC_VEHICLES            1000

enum VEHICLEINFO
{
    p_PlayerID,
    p_CarVID,
    p_CarModel,
    Float:p_CarX,
    Float:p_CarY,
    Float:p_CarZ,
    Float:p_CarFA,
}

static VehicleData[MAX_DYNAMIC_VEHICLES][VEHICLEINFO];
static Iterator:DynCars<MAX_DYNAMIC_VEHICLES>;

AddVehicle(playerid, model, Float:x, Float:y, Float:z, Float:fa)
{
    new index = Iter_Free(DynCars);
    if(index > -1)
    {
        Iter_Add(DynCars, index);
        VehicleData[index][p_CarVID] = CreateVehicle(...);
        VehicleData[index][p_CarModel] = model;
        VehicleData[index][p_CarX] = x;
        VehicleData[index][p_CarY] = y;
        VehicleData[index][p_CarZ] = z;
        VehicleData[index][p_CarFA] = fa;
        return index;
    }
    print("AddVehicle::Tried to add too many vehicles");
    return -1;
}

RemoveVehicle(index)
{
    if(Iter_Contains(DynCars, index))
    {
        new next;
        Iter_SafeRemove(DynCars, index, next);
        return next;
    }
    print("RemoveVehicle::Tried to remove a vehicle that does not exist");
    return -1;
}
Reply
#5

Yeah, I thought something like that as well. But I thought it could be made with less than 1000 cells, but it can't. Thanks for the help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)