Loading Vehicles.
#1

Hello, I've tried to make it so when my game mode loads up, the vehicles load up with it that have been made in game.

pawn Код:
stock LoadCars()
{
    new vinfo[12][32];
    new string[256];
    new File:file = fopen("cars.cfg", io_read);
    if(file)
    {
        new idx = 1;
        while(idx < MAX_CARS)
        {
            fread(file, string);
            splits(string, vinfo, '|');
            VehicleInfo[idx][vModel] = strval(vinfo[0]);
            VehicleInfo[idx][vX] = floatstr(vinfo[1]);
            VehicleInfo[idx][vY] = floatstr(vinfo[2]);
            VehicleInfo[idx][vZ] = floatstr(vinfo[3]);
            VehicleInfo[idx][vAngle] = floatstr(vinfo[4]);
            VehicleInfo[idx][vColor1] = strval(vinfo[5]);
            VehicleInfo[idx][vColor2] = strval(vinfo[6]);
           
            CreateVehicle(strval(vinfo[0]), floatstr(vinfo[1]),  floatstr(vinfo[2]),  floatstr(vinfo[3]),  floatstr(vinfo[4]), strval(vinfo[5]), strval(vinfo[6]), -1);
            //CreateVehicle(VehicleInfo[idx][vModel], VehicleInfo[idx][vX], VehicleInfo[idx][vY], VehicleInfo[idx][vZ], VehicleInfo[idx][vAngle], VehicleInfo[idx][vColor1], VehicleInfo[idx][vColor2], -1);
            //CreateVehicle(Vehiclenfop, Float:vX, Float:vY, Float:vZ, Float:vAngle, vColor1, vColor2, -1);
            //print("Loaded?");
            idx++;
        }
    }
    //idx++;
    print("Universal Gaming: Vehicles are susscefully loaded!");
    return 1;
}
I've debugged it, it loads it up but doesn't create the vehicle. Can someone help me, Thank you for in advance.
Reply
#2

Have you checked that everything is actually loading correctly? Odds are you have 0 as the value for the things you're loading from the file. Use print statements in your code.
Reply
#3

It just doesn't create the vehicle. It loads up the data far as I know.

Please help me fix this issue.
Reply
#4

Quote:
Originally Posted by Death1300
Посмотреть сообщение
far as I know.
Which means, you don't really know 100% that it's loading up the data. Use the print() statements. If you can't even do that, then I'm not even going to try and help you!
Reply
#5

under fread(file, string); add print(string); and check what it actually loads.
Reply
#6

I've already used the print statements.

pawn Код:
//print("Loaded?");
It loads up the data (The maximum I have set it witch would be 4 for now) but it doesn't create the vehicle. In the server console I get this when I use the print statement:

Код:
Loaded?
Loaded?
Loaded?
Loaded?
Universal Gaming: Vehicles are susscefully loaded!
EDIT: I'll try adding the print statement were you told me. 1 sec

EDIT: After adding that print, I get this in my console: (SS) - http://gyazo.com/9ef730ee7674f5f23d53ebff3baf1614
Reply
#7

Okay, so it's loading one vehicle and then the rest of them are loading as 0.0, 0.0, 0.0. 0 as a modelid for a vehicle is invalid, therefore no vehicle will be created. "print("Loaded?");" doesn't mean they are loaded, it means that the loop to GET the information was processed. I believe your loop is too early in the function, though. Try this:

pawn Код:
stock LoadCars()
{
    new idx;
    new vinfo[12][32];
    new string[256];
    new File:file = fopen("cars.cfg", io_read);
    if(file)
    {
        fread(file, string);
        while(splits(string, vinfo, '|') && idx < MAX_CARS)
        {
            VehicleInfo[idx][vModel] = strval(vinfo[0]);
            VehicleInfo[idx][vX] = floatstr(vinfo[1]);
            VehicleInfo[idx][vY] = floatstr(vinfo[2]);
            VehicleInfo[idx][vZ] = floatstr(vinfo[3]);
            VehicleInfo[idx][vAngle] = floatstr(vinfo[4]);
            VehicleInfo[idx][vColor1] = strval(vinfo[5]);
            VehicleInfo[idx][vColor2] = strval(vinfo[6]);
           
            CreateVehicle(strval(vinfo[0]), floatstr(vinfo[1]),  floatstr(vinfo[2]),  floatstr(vinfo[3]),  floatstr(vinfo[4]), strval(vinfo[5]), strval(vinfo[6]), -1);
            //CreateVehicle(VehicleInfo[idx][vModel], VehicleInfo[idx][vX], VehicleInfo[idx][vY], VehicleInfo[idx][vZ], VehicleInfo[idx][vAngle], VehicleInfo[idx][vColor1], VehicleInfo[idx][vColor2], -1);
            //CreateVehicle(Vehiclenfop, Float:vX, Float:vY, Float:vZ, Float:vAngle, vColor1, vColor2, -1);
            //print("Loaded?");
            idx++;
        }
    }
    //idx++;
    print("Universal Gaming: Vehicles are susscefully loaded!");
    return 1;
}
Reply
#8

Sorry about that, I didn't realized I created a loop. What did you change?

This still doesn't work. I just replaced the code/ format you added but the vehicle wasn't loaded/ created.
Reply
#9

shouldnt it be while(fread(file, string)) ?

also close the file fclose(file); after it done with reading
Reply
#10

Quote:
Originally Posted by ikey07
Посмотреть сообщение
shouldnt it be while(fread(file, string)) ?

also close the file fclose(file); after it done with reading
Ah, yes. It should be. Sorry, I hate files so I never do anything with them...

pawn Код:
stock LoadCars()
{
    new idx;
    new vinfo[12][32];
    new string[256];
    new File:file = fopen("cars.cfg", io_read);
    if(file)
    {
        while(fread(file, string) && idx < MAX_CARS)
        {
            splits(string, vinfo, '|');
            VehicleInfo[idx][vModel] = strval(vinfo[0]);
            VehicleInfo[idx][vX] = floatstr(vinfo[1]);
            VehicleInfo[idx][vY] = floatstr(vinfo[2]);
            VehicleInfo[idx][vZ] = floatstr(vinfo[3]);
            VehicleInfo[idx][vAngle] = floatstr(vinfo[4]);
            VehicleInfo[idx][vColor1] = strval(vinfo[5]);
            VehicleInfo[idx][vColor2] = strval(vinfo[6]);
           
            CreateVehicle(strval(vinfo[0]), floatstr(vinfo[1]),  floatstr(vinfo[2]),  floatstr(vinfo[3]),  floatstr(vinfo[4]), strval(vinfo[5]), strval(vinfo[6]), -1);
            //CreateVehicle(VehicleInfo[idx][vModel], VehicleInfo[idx][vX], VehicleInfo[idx][vY], VehicleInfo[idx][vZ], VehicleInfo[idx][vAngle], VehicleInfo[idx][vColor1], VehicleInfo[idx][vColor2], -1);
            //CreateVehicle(Vehiclenfop, Float:vX, Float:vY, Float:vZ, Float:vAngle, vColor1, vColor2, -1);
            //print("Loaded?");
            idx++;
        }
    }
    //idx++;
    print("Universal Gaming: Vehicles are susscefully loaded!");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)