Vehicle loading problem
#1

The problem I think is simple, the system loads too many vehicles. It loads 30 vehicles instead of like 3

pawn Код:
public OnVehicleLoad()
{
    new rows, fields;
    cache_get_data(rows, fields, mysql);
    if(rows)
    {
        for(new i = 0; i < rows && i < MAX_VEHICLES; i++){
            for(new x = 0; x < MAX_LOADED_CARS;x++) {
                VehInfo[i][VehMasterID] = cache_get_field_content_int(i,"MasterID");
                VehInfo[i][VID] = cache_get_field_content_int(i,"ID");
                VehInfo[i][ModelID] = cache_get_field_content_int(i,"ModelID");
                VehInfo[i][Color1] = cache_get_field_content_int(i,"Color1");
                VehInfo[i][Color2] = cache_get_field_content_int(i,"Color2");
                VehInfo[i][VehPosX] = cache_get_field_content_float(i,"PosX");
                VehInfo[i][VehPosY] = cache_get_field_content_float(i,"PosY");
                VehInfo[i][VehPosZ] = cache_get_field_content_float(i,"PosZ");
                VehInfo[i][VehPosA] = cache_get_field_content_float(i,"PosA");
                VehInfo[i][VRespawnTime] = cache_get_field_content_int(i,"RespawnTime");
                VehInfo[i][VPrice] = cache_get_field_content_int(i,"Price");
                VehInfo[i][DamageStatus] = cache_get_field_content_float(i,"Damage");
                VehInfo[i][FuelStatus] = cache_get_field_content_int(i,"FuelStatus");
                VehInfo[i][EngineStatus] = cache_get_field_content_int(i,"EngineStatus");
                VehInfo[i][Kilometrage] = cache_get_field_content_float(i,"Kilometrage");
                VehInfo[i][vSiren] = cache_get_field_content_int(i,"Siren");
                VehInfo[i][vOwned] = cache_get_field_content_int(i,"Owned");
                VehInfo[i][VehWorld] = cache_get_field_content_int(i,"VirtualWorld");
                VehInfo[i][VehInterior] = cache_get_field_content_int(i,"Interior");
                VehInfo[i][vCreated][x] = CreateServerVehicle(VehInfo[i][ModelID],VehInfo[i][VehPosX],VehInfo[i][VehPosY],VehInfo[i][VehPosZ],VehInfo[i][VehPosA],VehInfo[i][Color1],VehInfo[i][Color2],VehInfo[i][VRespawnTime],VehInfo[i][vSiren]);
                SetVehicleVirtualWorld(VehInfo[i][vCreated][x],VehInfo[i][VehWorld]);
                LinkVehicleToInterior(VehInfo[i][vCreated][x],VehInfo[i][VehInterior]);
                SetVehiclePos(VehInfo[i][vCreated][x],VehInfo[i][VehPosX],VehInfo[i][VehPosY],VehInfo[i][VehPosZ]);
                SetVehicleZAngle(VehInfo[i][vCreated][x],VehInfo[i][VehPosA]);
                VehiclesLoaded++;
            }
        }
        printf("Total %i vehicles spawned",VehiclesLoaded);
    }
    else print("No vehicles to be loaded..");
    return true;
}
pawn Код:
#define MAX_LOADED_CARS 10
enum VINFO
{
    VID,
    VehMasterID,
    ModelID,
    Color1,
    Color2,
    Float:VehPosX,
    Float:VehPosY,
    Float:VehPosZ,
    Float:VehPosA,
    VRespawnTime,
    VPrice,
    Float:DamageStatus,
    FuelStatus,
    EngineStatus,
    Float:Kilometrage,
    vSiren,
    vOwned,
    VehWorld,
    VehInterior,
    vCreated[MAX_LOADED_CARS]
}

What I think the problem is basically
VehInfo[i][vCreated][x]
But im trying to create all vehicles and assign them to some unique ID
Reply
#2

Well, you have a loop in a loop, but I won't bother too much with that.

Anyway, try this.
PHP код:
public OnVehicleLoad()
{
    new 
rowsfields;
    
cache_get_data(rowsfieldsmysql);
    if(
rows)
    {
        for(new 
0rows && MAX_VEHICLESi++){
            for(new 
0MAX_LOADED_CARS;x++) {
                if(
VehInfo[i][vCreated][x]) continue;
                
VehInfo[i][VehMasterID] = cache_get_field_content_int(i,"MasterID");
                
VehInfo[i][VID] = cache_get_field_content_int(i,"ID");
                
VehInfo[i][ModelID] = cache_get_field_content_int(i,"ModelID");
                
VehInfo[i][Color1] = cache_get_field_content_int(i,"Color1");
                
VehInfo[i][Color2] = cache_get_field_content_int(i,"Color2");
                
VehInfo[i][VehPosX] = cache_get_field_content_float(i,"PosX");
                
VehInfo[i][VehPosY] = cache_get_field_content_float(i,"PosY");
                
VehInfo[i][VehPosZ] = cache_get_field_content_float(i,"PosZ");
                
VehInfo[i][VehPosA] = cache_get_field_content_float(i,"PosA");
                
VehInfo[i][VRespawnTime] = cache_get_field_content_int(i,"RespawnTime");
                
VehInfo[i][VPrice] = cache_get_field_content_int(i,"Price");
                
VehInfo[i][DamageStatus] = cache_get_field_content_float(i,"Damage");
                
VehInfo[i][FuelStatus] = cache_get_field_content_int(i,"FuelStatus");
                
VehInfo[i][EngineStatus] = cache_get_field_content_int(i,"EngineStatus");
                
VehInfo[i][Kilometrage] = cache_get_field_content_float(i,"Kilometrage");
                
VehInfo[i][vSiren] = cache_get_field_content_int(i,"Siren");
                
VehInfo[i][vOwned] = cache_get_field_content_int(i,"Owned");
                
VehInfo[i][VehWorld] = cache_get_field_content_int(i,"VirtualWorld");
                
VehInfo[i][VehInterior] = cache_get_field_content_int(i,"Interior");
                
VehInfo[i][vCreated][x] = CreateServerVehicle(VehInfo[i][ModelID],VehInfo[i][VehPosX],VehInfo[i][VehPosY],VehInfo[i][VehPosZ],VehInfo[i][VehPosA],VehInfo[i][Color1],VehInfo[i][Color2],VehInfo[i][VRespawnTime],VehInfo[i][vSiren]);
                
SetVehicleVirtualWorld(VehInfo[i][vCreated][x],VehInfo[i][VehWorld]);
                
LinkVehicleToInterior(VehInfo[i][vCreated][x],VehInfo[i][VehInterior]);
                
SetVehiclePos(VehInfo[i][vCreated][x],VehInfo[i][VehPosX],VehInfo[i][VehPosY],VehInfo[i][VehPosZ]);
                
SetVehicleZAngle(VehInfo[i][vCreated][x],VehInfo[i][VehPosA]);
                
VehiclesLoaded++;
            }
        }
        
printf("Total %i vehicles spawned",VehiclesLoaded);
    }
    else print(
"No vehicles to be loaded..");
    return 
true;

Reply
#3

Naah still the same
Reply
#4

What is the point of the second loop?

PHP код:
for(new 0MAX_LOADED_CARS;x++) 
Try without it.
Reply
#5

Okay so basically I need the 2nd loop for MAX_LOADED_CARS for the line
pawn Код:
VehInfo[MAX_VEHICLES][vCreated][MAX_LOADED_CARS]
It stores vehicles inside of it so I can later on use it at some point


Edit: I need MAX_LOADED_CARS since Im allowing the player to have more than 1 vehicle
Reply
#6

I think I see what you're trying to do, to assign a vehicle an ID (MySQL ID on the database you must do this...I don't understand where you're creating the vehicles...

Try something like this:

pawn Код:
public OnVehicleLoad()
{
    new rows, fields;
    cache_get_data(rows, fields, mysql);
    for(new i = 0; i != rows; i++)
    {
        new vehicleid = CreateVehicle(VehInfo[i][ModelID]), VehInfo[vehicleid][VehPosX],VehInfo[vehicleid][VehPosY],VehInfo[vehicleid][VehPosZ], 90, 1, 1, 0, 0);
        VehInfo[vehicleid][VehMasterID] = cache_get_field_content_int(i,"MasterID");
        VehInfo[vehicleid][VID] = cache_get_field_content_int(i,"ID");
        VehInfo[vehicleid][ModelID] = cache_get_field_content_int(i,"ModelID");
        VehInfo[vehicleid][Color1] = cache_get_field_content_int(i,"Color1");
        VehInfo[vehicleid][Color2] = cache_get_field_content_int(i,"Color2");
        VehInfo[vehicleid][VehPosX] = cache_get_field_content_float(i,"PosX");
        VehInfo[vehicleid][VehPosY] = cache_get_field_content_float(i,"PosY");
        VehInfo[vehicleid][VehPosZ] = cache_get_field_content_float(i,"PosZ");
        VehInfo[vehicleid][VehPosA] = cache_get_field_content_float(i,"PosA");
        VehInfo[vehicleid][VRespawnTime] = cache_get_field_content_int(i,"RespawnTime");
        VehInfo[vehicleid][VPrice] = cache_get_field_content_int(i,"Price");
        VehInfo[vehicleid][DamageStatus] = cache_get_field_content_float(i,"Damage");
        VehInfo[vehicleid][FuelStatus] = cache_get_field_content_int(i,"FuelStatus");
        VehInfo[vehicleid][EngineStatus] = cache_get_field_content_int(i,"EngineStatus");
        VehInfo[vehicleid][Kilometrage] = cache_get_field_content_float(i,"Kilometrage");
        VehInfo[vehicleid][vSiren] = cache_get_field_content_int(i,"Siren");
        VehInfo[vehicleid][vOwned] = cache_get_field_content_int(i,"Owned");
        VehInfo[vehicleid][VehWorld] = cache_get_field_content_int(i,"VirtualWorld");
        VehInfo[vehicleid][VehInterior] = cache_get_field_content_int(i,"Interior");
        SetVehicleVirtualWorld(vehicleid,VehInfo[vehicleid][VehWorld]);
        LinkVehicleToInterior(vehicleid,VehInfo[vehicleid][VehInterior]);
        SetVehiclePos(vehicleid,VehInfo[vehicleid][VehPosX],VehInfo[vehicleid][VehPosY],VehInfo[vehicleid][VehPosZ]);
        SetVehicleZAngle(vehicleid, VehInfo[vehicleid][VehPosA]);
        VehiclesLoaded++;
    }
    printf("Total %i vehicles spawned",VehiclesLoaded);
    if(VehiclesLoaded == 0)
    {
        printf("No vehicles loaded.");
    }
}
You added a lot of unnecessary functions. Just use the created vehicle id! Hope this helps. I've not tested it, it's possibly not complete or I've missed something.
Reply
#7

Yeah, thats something I wanted to do, but the problem is, lets say I want to check if the player is inside that vehicle and if the vehicle MasterID is same as AccInfo[playerid][ID] how do I do it?

Thats why I used the stuff above.

Also the player will have few vehicles spawned at once, Im not doing the /vspawn method, but preety much creating vehicle straight away and player can later on do w/e he wants with it.

Basically how do I recognize if its his vehicle now?

Example:
pawn Код:
if(IsPlayerInVehicle(playerid,myservercar) {
    if(MyServerCar[MasterID] == AccInfo[playerid][ID] {
        print("hi");
    }
}
Now I know what I would do if it was 1 vehicle, but in this case Ill enable the player to have multiple vehicles spawned at once


ie, imagine
pawn Код:
MyCar[0] = CreateVehicle...
MyCar[1]= CreateVehicle...
MyCar[2] = Createvehicle..
Reply
#8

Can you show the CreateServerVehicle function?

Are you sure it is returning the vehicle ID?
Reply
#9

Hmmm returning the ID? Hmmm
pawn Код:
stock CreateServerVehicle(Model,Float:X,Float:Y,Float:Z,Float:A,vColor1,vColor2,VehRespawnTime,SirenOption) {
    new vehicleid;
    VehInfo[vehicleid][ModelID] = Model;
    VehInfo[vehicleid][VehPosX] = X;
    VehInfo[vehicleid][VehPosY] = Y;
    VehInfo[vehicleid][VehPosZ] = Z;
    VehInfo[vehicleid][VehPosA] = A;
    VehInfo[vehicleid][Color1] = vColor1;
    VehInfo[vehicleid][Color2] = vColor2;
    VehInfo[vehicleid][VRespawnTime] = VehRespawnTime;
    VehInfo[vehicleid][vSiren] = SirenOption;
    AddStaticVehicleEx(Model,X,Y,Z,A,vColor1,vColor2,VehRespawnTime,SirenOption);
    return true;
}
Reply
#10

Can you change the
PHP код:
return true
to
PHP код:
return vehicleid
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)