Saving vehicle
#1

hey i have vehicle system , but i need add it to vehicle_setup.txt for load buyable vehicle .
my problem is how to make it automatically created when player buy it , example
/vbuy Infernus . it will be automatically created on file vehicle_setup.txt and saved .
i have this on my script
pawn Код:
#define V_FILE_LOAD "SATDM/Vehicles/vehicles_setup.txt"
#define V_FILE_SAVE "SATDM/Vehicles/vehicles_save.txt"

stock CountVehicles(filename[]) {
    new File:VehicleFile;
    new blank[256];
    new count = 0;
    if (fexist(V_FILE_SAVE)) {
        VehicleFile = fopen(V_FILE_SAVE);
        while(fread(VehicleFile, blank, sizeof blank)) {
            count++;
        }
        fclose(VehicleFile);
    }
    else {
        VehicleFile = fopen(filename);
        while(fread(VehicleFile, blank, sizeof blank)) {
            count++;
        }
        fclose(VehicleFile);
    }
    return count;
}

stock SetupVehiclesFile()
{
    new File: file;
    file = fopen(V_FILE_SAVE, io_write);
    new SplitDiv[99][MAX_VEHICLES];
    new filestring[256];
    file = fopen(V_FILE_LOAD, io_read);
    new carcost[MAX_VEHICLES];
    for(new vehicleid=1;vehicleid<=vehcount;vehicleid++)
    {
        if (file)
        {
            fread(file, filestring);
            split(filestring, SplitDiv, ',');
            VehicleInfo[vehicleid][model] = strval(SplitDiv[0]);
            VehicleInfo[vehicleid][x_spawn] = floatstr(SplitDiv[1]);
            VehicleInfo[vehicleid][y_spawn] = floatstr(SplitDiv[2]);
            VehicleInfo[vehicleid][z_spawn] = floatstr(SplitDiv[3]);
            VehicleInfo[vehicleid][za_spawn] = floatstr(SplitDiv[4]);
            VehicleInfo[vehicleid][ox_spawn] = floatstr(SplitDiv[1]);
            VehicleInfo[vehicleid][oy_spawn] = floatstr(SplitDiv[2]);
            VehicleInfo[vehicleid][oz_spawn] = floatstr(SplitDiv[3]);
            VehicleInfo[vehicleid][oza_spawn] = floatstr(SplitDiv[4]);
            VehicleInfo[vehicleid][color_1] = strval(SplitDiv[5]);
            VehicleInfo[vehicleid][color_2] = strval(SplitDiv[6]);
            CreateVehicle(VehicleInfo[vehicleid][model], VehicleInfo[vehicleid][x_spawn], VehicleInfo[vehicleid][y_spawn], VehicleInfo[vehicleid][z_spawn], VehicleInfo[vehicleid][za_spawn], VehicleInfo[vehicleid][color_1], VehicleInfo[vehicleid][color_2],20000);
            onsys[vehicleid] = 1;
            carcost[vehicleid] = 50000;
            for(new s=0; s<24; s++) {
                if(VehicleInfo[vehicleid][model] == heavycar[s][0]) {
                    carcost[vehicleid] = 100000;
                }
            }
            for(new a=0; a<11; a++) {
                if(VehicleInfo[vehicleid][model] == boat[a][0]) {
                    carcost[vehicleid] = 50000;
                 }
            }
            for(new mb=0; mb<11; mb++) {
                if(VehicleInfo[vehicleid][model] == mbike[mb][0]) {
                    carcost[vehicleid] = 40000;
                }
            }
            for(new d=0; d<3; d++) {
                if(VehicleInfo[vehicleid][model] == pbike[d][0]) {
                    carcost[vehicleid] = 3000;
                 }
            }
            for(new e=0; e<6; e++) {
                if(VehicleInfo[vehicleid][model] == splane[e][0]) {
                    carcost[vehicleid] = 500000;
                }
            }
            for(new f=0; f<2; f++) {
                if(VehicleInfo[vehicleid][model] == mplane[f][0]) {
                        carcost[vehicleid] = 1500000;
                }
            }
            for(new v=0; v<2; v++) {
                if(VehicleInfo[vehicleid][model] == lplane[v][0]) {
                    carcost[vehicleid] = 2000000;
                }
            }
            for(new n=0; n<4; n++) {
                if(VehicleInfo[vehicleid][model] == milair[n][0]) {
                    carcost[vehicleid] = 4000000;
                }
            }
            for(new j=0; j<4; j++) {
                if(VehicleInfo[vehicleid][model] == sheli[j][0]) {
                    carcost[vehicleid] = 750000;
                }
            }
            for(new k=0; k<3; k++) {
                if(VehicleInfo[vehicleid][model] == lheli[k][0]) {
                    carcost[vehicleid] = 1250000;
                }
            }
            VehicleInfo[vehicleid][vehiclecost] = carcost[vehicleid];
            VehicleInfo[vehicleid][vused] = 0;
            VehicleInfo[vehicleid][bought] = 0;
            VehicleInfo[vehicleid][secure] = 0;
            VehicleInfo[vehicleid][asecure] = 0;
            VehicleInfo[vehicleid][buybar] = 0;
            VehicleInfo[vehicleid][mod1] = 0;
            VehicleInfo[vehicleid][mod2] = 0;
            VehicleInfo[vehicleid][mod3] = 0;
            VehicleInfo[vehicleid][mod4] = 0;
            VehicleInfo[vehicleid][mod5] = 0;
            VehicleInfo[vehicleid][mod6] = 0;
            VehicleInfo[vehicleid][mod7] = 0;
            VehicleInfo[vehicleid][mod8] = 0;
            VehicleInfo[vehicleid][mod9] = 0;
            VehicleInfo[vehicleid][mod10] = 0;
            VehicleInfo[vehicleid][mod11] = 0;
            VehicleInfo[vehicleid][mod12] = 0;
            VehicleInfo[vehicleid][mod13] = 0;
            VehicleInfo[vehicleid][mod14] = 0;
            VehicleInfo[vehicleid][mod15] = 0;
            VehicleInfo[vehicleid][mod16] = 0;
            VehicleInfo[vehicleid][mod17] = 0;
            VehicleInfo[vehicleid][paintjob] = -1;
            strmid(VehicleInfo[vehicleid][owner], DEFAULT_OWNER, 0, strlen(DEFAULT_OWNER), 255);
            strmid(VehicleInfo[vehicleid][name], VehicleName[GetVehicleModel(vehicleid)-400][0], 0, strlen(VehicleName[GetVehicleModel(vehicleid)-400][0]), 255);
            new addmess[256];
            format(addmess,sizeof(addmess),"--:: Vehicle %d (%s) successfully spawned ::--",vehicleid,VehicleInfo[vehicleid][name]);
            //print(addmess);
        }
    }
    fclose(file);
//  print(">------------------------------------------------");
//  print(" ");
//  print(">------------------------------------------------");
//  print("Initialising Vehicle File System - Please Wait For Confirmation...");
//  print(" ");
    SaveVehicles();
//  print(" ");
//  print("Vehicle File System 100% Initialised...");
//  print(">------------------------------------------------");
//  printf(" ");
}

stock LoadVehicles()
{
    if(fexist(V_FILE_SAVE)) {
        new SplitDiv[99][MAX_VEHICLES];
        new filestring[256];
        new File: file = fopen(V_FILE_SAVE, io_read);
        if (file) {
            for(new vehicleid = 1;vehicleid<=vehcount;vehicleid++)
            {
                fread(file, filestring);
                split(filestring, SplitDiv, ',');
                VehicleInfo[vehicleid][model] = strval(SplitDiv[0]);
                VehicleInfo[vehicleid][x_spawn] = floatstr(SplitDiv[1]);
                VehicleInfo[vehicleid][y_spawn] = floatstr(SplitDiv[2]);
                VehicleInfo[vehicleid][z_spawn] = floatstr(SplitDiv[3]);
                VehicleInfo[vehicleid][za_spawn] = floatstr(SplitDiv[4]);
                VehicleInfo[vehicleid][ox_spawn] = floatstr(SplitDiv[5]);
                VehicleInfo[vehicleid][oy_spawn] = floatstr(SplitDiv[6]);
                VehicleInfo[vehicleid][oz_spawn] = floatstr(SplitDiv[7]);
                VehicleInfo[vehicleid][oza_spawn] = floatstr(SplitDiv[8]);
                VehicleInfo[vehicleid][color_1] = strval(SplitDiv[9]);
                VehicleInfo[vehicleid][color_2] = strval(SplitDiv[10]);
                VehicleInfo[vehicleid][vehiclecost] = strval(SplitDiv[11]);
                VehicleInfo[vehicleid][bought] = strval(SplitDiv[12]);
                VehicleInfo[vehicleid][secure] = strval(SplitDiv[13]);
                VehicleInfo[vehicleid][asecure] = strval(SplitDiv[14]);
                VehicleInfo[vehicleid][vused] = 0;
                VehicleInfo[vehicleid][buybar] = strval(SplitDiv[16]);
                VehicleInfo[vehicleid][mod1] = strval(SplitDiv[17]);
                VehicleInfo[vehicleid][mod2] = strval(SplitDiv[18]);
                VehicleInfo[vehicleid][mod3] = strval(SplitDiv[19]);
                VehicleInfo[vehicleid][mod4] = strval(SplitDiv[20]);
                VehicleInfo[vehicleid][mod5] = strval(SplitDiv[21]);
                VehicleInfo[vehicleid][mod6] = strval(SplitDiv[22]);
                VehicleInfo[vehicleid][mod7] = strval(SplitDiv[23]);
                VehicleInfo[vehicleid][mod8] = strval(SplitDiv[24]);
                VehicleInfo[vehicleid][mod9] = strval(SplitDiv[25]);
                VehicleInfo[vehicleid][mod10] = strval(SplitDiv[26]);
                VehicleInfo[vehicleid][mod11] = strval(SplitDiv[27]);
                VehicleInfo[vehicleid][mod12] = strval(SplitDiv[28]);
                VehicleInfo[vehicleid][mod13] = strval(SplitDiv[29]);
                VehicleInfo[vehicleid][mod14] = strval(SplitDiv[30]);
                VehicleInfo[vehicleid][mod15] = strval(SplitDiv[31]);
                VehicleInfo[vehicleid][mod16] = strval(SplitDiv[32]);
                VehicleInfo[vehicleid][mod17] = strval(SplitDiv[33]);
                VehicleInfo[vehicleid][paintjob] = strval(SplitDiv[36]);
                strmid(VehicleInfo[vehicleid][owner], SplitDiv[34], 0, strlen(SplitDiv[34]), 255);
                strmid(VehicleInfo[vehicleid][name], SplitDiv[35], 0, strlen(SplitDiv[35]), 255);
                CreateVehicle(VehicleInfo[vehicleid][model], VehicleInfo[vehicleid][x_spawn], VehicleInfo[vehicleid][y_spawn], VehicleInfo[vehicleid][z_spawn], VehicleInfo[vehicleid][za_spawn], VehicleInfo[vehicleid][color_1], VehicleInfo[vehicleid][color_2],20000);
                onsys[vehicleid] = 1;
                new addmess[256];
                format(addmess,sizeof(addmess),"--:: Vehicle %d (%s) successfully Loaded and placed - owner: %s ::--",vehicleid,VehicleInfo[vehicleid][name],VehicleInfo[vehicleid][owner]);
                //print(addmess);
            }
        }
        fclose(file);
    }
    else {
        SetupVehiclesFile();
    }
}

stock SaveVehicles()
{
    new filestring[512];
    new File: vfile = fopen(V_FILE_SAVE, io_write);
    for(new vehicleid = 1;vehicleid<=vehcount;vehicleid++)
    {
        format(filestring, sizeof(filestring), "%d,%f,%f,%f,%f,%f,%f,%f,%f,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%s,%s,%d\n",
        VehicleInfo[vehicleid][model],
        VehicleInfo[vehicleid][x_spawn],
        VehicleInfo[vehicleid][y_spawn],
        VehicleInfo[vehicleid][z_spawn],
        VehicleInfo[vehicleid][za_spawn],
        VehicleInfo[vehicleid][ox_spawn],
        VehicleInfo[vehicleid][oy_spawn],
        VehicleInfo[vehicleid][oz_spawn],
        VehicleInfo[vehicleid][oza_spawn],
        VehicleInfo[vehicleid][color_1],
        VehicleInfo[vehicleid][color_2],
        VehicleInfo[vehicleid][vehiclecost],
        VehicleInfo[vehicleid][bought],
        VehicleInfo[vehicleid][secure],
        VehicleInfo[vehicleid][asecure],
        VehicleInfo[vehicleid][vused],
        VehicleInfo[vehicleid][buybar],
        VehicleInfo[vehicleid][mod1],
        VehicleInfo[vehicleid][mod2],
        VehicleInfo[vehicleid][mod3],
        VehicleInfo[vehicleid][mod4],
        VehicleInfo[vehicleid][mod5],
        VehicleInfo[vehicleid][mod6],
        VehicleInfo[vehicleid][mod7],
        VehicleInfo[vehicleid][mod8],
        VehicleInfo[vehicleid][mod9],
        VehicleInfo[vehicleid][mod10],
        VehicleInfo[vehicleid][mod11],
        VehicleInfo[vehicleid][mod12],
        VehicleInfo[vehicleid][mod13],
        VehicleInfo[vehicleid][mod14],
        VehicleInfo[vehicleid][mod15],
        VehicleInfo[vehicleid][mod16],
        VehicleInfo[vehicleid][mod17],
        VehicleInfo[vehicleid][owner],
        VehicleInfo[vehicleid][name],
        VehicleInfo[vehicleid][paintjob]
        );
        fwrite(vfile, filestring);
    }
    fclose(vfile);
}

stock ModVehicle(vehicleid)
{
    new tuned2 = 0;
    if(VehicleInfo[vehicleid][mod1] != 0) {
        AddVehicleComponent(vehicleid,VehicleInfo[vehicleid][mod1]);
        tuned2 = 1;
    }
    if(VehicleInfo[vehicleid][mod2] != 0) {
        AddVehicleComponent(vehicleid,VehicleInfo[vehicleid][mod2]);
        tuned2 = 1;
    }
    if(VehicleInfo[vehicleid][mod3] != 0) {
        AddVehicleComponent(vehicleid,VehicleInfo[vehicleid][mod3]);
        tuned2 = 1;
    }
    if(VehicleInfo[vehicleid][mod4] != 0) {
        AddVehicleComponent(vehicleid,VehicleInfo[vehicleid][mod4]);
        tuned2 = 1;
    }
    if(VehicleInfo[vehicleid][mod5] != 0) {
        AddVehicleComponent(vehicleid,VehicleInfo[vehicleid][mod5]);
        tuned2 = 1;
    }
    if(VehicleInfo[vehicleid][mod6] != 0) {
        AddVehicleComponent(vehicleid,VehicleInfo[vehicleid][mod6]);
        tuned2 = 1;
    }
    if(VehicleInfo[vehicleid][mod7] != 0) {
        AddVehicleComponent(vehicleid,VehicleInfo[vehicleid][mod7]);
        tuned2 = 1;
    }
    if(VehicleInfo[vehicleid][mod8] != 0) {
        AddVehicleComponent(vehicleid,VehicleInfo[vehicleid][mod8]);
        tuned2 = 1;
    }
    if(VehicleInfo[vehicleid][mod9] != 0) {
        AddVehicleComponent(vehicleid,VehicleInfo[vehicleid][mod9]);
        tuned2 = 1;
    }
    if(VehicleInfo[vehicleid][mod10] != 0) {
        AddVehicleComponent(vehicleid,VehicleInfo[vehicleid][mod10]);
        tuned2 = 1;
    }
    if(VehicleInfo[vehicleid][mod11] != 0) {
        AddVehicleComponent(vehicleid,VehicleInfo[vehicleid][mod11]);
        tuned2 = 1;
    }
    if(VehicleInfo[vehicleid][mod12] != 0) {
        AddVehicleComponent(vehicleid,VehicleInfo[vehicleid][mod12]);
        tuned2 = 1;
    }
    if(VehicleInfo[vehicleid][mod13] != 0) {
        AddVehicleComponent(vehicleid,VehicleInfo[vehicleid][mod13]);
        tuned2 = 1;
    }
    if(VehicleInfo[vehicleid][mod14] != 0) {
        AddVehicleComponent(vehicleid,VehicleInfo[vehicleid][mod14]);
        tuned2 = 1;
    }
    if(VehicleInfo[vehicleid][mod15] != 0) {
        AddVehicleComponent(vehicleid,VehicleInfo[vehicleid][mod15]);
        tuned2 = 1;
    }
    if(VehicleInfo[vehicleid][mod16] != 0) {
        AddVehicleComponent(vehicleid,VehicleInfo[vehicleid][mod16]);
        tuned2 = 1;
    }
    if(VehicleInfo[vehicleid][mod17] != 0) {
        AddVehicleComponent(vehicleid,VehicleInfo[vehicleid][mod17]);
        tuned2 = 1;
    }
    if(VehicleInfo[vehicleid][color_1] > -1 || VehicleInfo[vehicleid][color_2] > -1) {
        ChangeVehicleColor(vehicleid,VehicleInfo[vehicleid][color_1],VehicleInfo[vehicleid][color_2]);
        tuned2 = 1;
    }
    if(VehicleInfo[vehicleid][paintjob] > -1) {
        ChangeVehiclePaintjob(vehicleid,VehicleInfo[vehicleid][paintjob]);
        tuned2 = 1;
    }
    if(tuned2 == 1) {
        tuned++;
    }
}

enum vInfo
{
    modding,
    model,
    Float:x_spawn,
    Float:y_spawn,
    Float:z_spawn,
    Float:za_spawn,
    Float:ox_spawn,
    Float:oy_spawn,
    Float:oz_spawn,
    Float:oza_spawn,
    color_1,
    color_2,
    owner[128],
    vehiclecost,
    bought,
    secure,
    asecure,
    vused,
    buybar,
    name[128],
    mod1,
    mod2,
    mod3,
    mod4,
    mod5,
    mod6,
    mod7,
    mod8,
    mod9,
    mod10,
    mod11,
    mod12,
    mod13,
    mod14,
    mod15,
    mod16,
    mod17,
    paintjob,
    Temp,
};

new VehicleInfo[MAX_VEHICLES][vInfo];
and this on vehicle_setup.txt
pawn Код:
427,-1598.9745,651.7614,7.3194,358.6466,-1,-1
490,-1587.9879,673.8334,7.3145,179.7983,-1,-1
490,-1581.6614,651.9380,7.3169,1.1274,-1,-1
415,-2661.0120,988.6339,64.7401,359.9453,-1,-1
415,-2652.3237,854.2040,63.7831,355.9345,-1,-1
481,-2675.3743,936.3604,78.0560,270.2083,-1,-1
411,-2680.0449,867.9384,76.1545,4.5891,-1,-1
451,-2664.6418,913.5606,79.3801,179.6254,-1,-1
411,-2721.8882,915.9191,67.3208,103.3444,-1,-1
506,-2676.9624,906.3179,79.3118,264.7799,-1,-1
487,-2647.9312,1402.5247,24.9422,248.6415,-1,-1
415,-2252.8276,2285.2219,4.8202,90.7733,-1,-1
451,-2271.7480,2297.3911,4.8202,270.8565,-1,-1
562,-2252.5969,2290.9824,4.8202,85.6504,-1,-1
405,-1304.1517,2528.5356,87.6315,181.3323,-1,-1
411,-2691.1743,220.3039,4.1797,89.5966,-1,-1
415,-1989.8328,258.8502,34.9497,268.1773,-1,-1
411,-1266.4242,2525.7771,89.4997,106.5754,-1,-1
424,-2236.2820,-1724.1927,480.8605,10.4293,-1,-1
424,-488.3469,-174.9918,78.2109,175.4913,-1,-1
424,-2653.9656,-2418.3093,2.6874,101.4916,-1,-1
424,-2654.8750,-2413.8379,2.6877,101.4914,-1,-1
559,-1287.0046,2514.1675,86.7848,179.9851,-1,-1
559,-2134.4265,946.1021,79.5791,356.7817,-1,-1
444,-2247.1477,-1727.6178,480.2036,38.2774,-1,-1
444,-557.6980,-177.3288,78.4063,169.0153,-1,-1
444,-1321.4635,2513.2258,92.5406,180.9954,-1,-1
446,-2244.3376,2435.2117,-0.5616,227.1463,-1,-1
446,-2218.8831,2405.2954,-0.5339,45.1995,-1,-1
451,-2047.5374,901.2433,53.6883,8.7998,-1,-1
451,-1945.8147,257.9550,40.7542,88.5571,-1,-1
451,-345.9050,1515.0657,75.1318,358.8066,-1,-1
451,-333.4294,1515.0460,75.1313,1.3186,-1,-1
522,-2079.4136,901.8524,64.1328,1.9898,-1,-1
522,-473.0953,-175.8979,78.2109,180.0741,-1,-1
468,-2243.3403,-1745.0731,480.1822,11.6067,-1,-1
468,-2244.4622,-1739.6124,479.7912,11.6067,-1,-1
468,-2654.0969,-2419.7952,2.5891,106.693,-1,-1
468,-2652.5967,-2424.7976,2.5885,106.6923,-1,-1
470,-1857.3772,-1616.0371,21.8090,181.0974,-1,-1
470,-2271.9880,2285.2322,4.8202,276.4501,-1,-1
470,-500.7715,-200.4563,78.4063,18.7517,-1,-1
Thanks rep ++ for helped
Reply
#2

bump help me
Reply
#3

bump help me
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)