SA-MP Forums Archive
[Tutorial] Saving Vehicles on your server - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Saving Vehicles on your server (/showthread.php?tid=387996)



Saving Vehicles on your server - Glad2BeHere - 27.10.2012

I made this myself, and i tried to explain as best as i understand, nope its not a gf_edit from anything.

Hope i help, im open for all good/bad comments about the tutorial and what i can do 2 make more tutorial like, yes i read ****** thing so please dont post it -_-

pawn Код:
//the amount of you want to have on ur server
#define MAX_CARS 10000


enum CarSystem//the name of the enum we are creating
{
 cModel,//car model
 Float:Carx,//the X-axis of the car
 Float:Cary,//Y-axis of the car
 Float:Carz,//z axis of the car
 Float:Cara,//angle of the car
 cColor1,//color 1
 cColor2//color 2
}
new CarLoader[MAX_CARS][CarSystem];
pawn Код:
stock SaveCars()
{
    new idx = 1, File:file;// new interger call idx which iz = to the id of each car, idx = +1
    new string[256];// string
    while(idx < MAX_CARS)// ensure that each car on the server is not more the the maximum,
    {
        format(string, sizeof(string), "%d|%f|%f|%f|%f|%d|%d\r\n",//%d represents the information of the interger && %f floats the positions of the vehicles
        CarLoader[idx][cModel],//idx in each represents +1 towards max cars
        CarLoader[idx][Carx],
        CarLoader[idx][Cary],
        CarLoader[idx][Carz],
        CarLoader[idx][Cara],
        CarLoader[idx][cColor1],
        CarLoader[idx][cColor2],
        if(idx == 1)//checking
        {
            file = fopen("CARS.cfg", io_write);//opening and writing the file name cars into the scriptfiles folders
        }
        else
        {
            file = fopen("CARS.cfg", io_append);//opening the file
        }
        fwrite(file, string);//writing
        fclose(file);//closing it
        idx++;//setting id +!
    }
    print("Cars Loaded");//showing that cars loaded in the sampServer.exe
}
pawn Код:
stock LoadCars()
{
    new CarInfo[7];//the amount of car of information in Carinfo
    new string[256];//string
    new File:file = fopen("CARS.cfg", io_read);//open the file and reading it
    if(file)
    {
        new idx = 1;//ids == 1
        while(idx < MAX_CARS)//reading all files under the max cars
        {
            fread(file, string);
            split(string, CarInfo, '|');
            CarLoader[idx][cModel] = strval(CarInfo[0]);
            CarLoader[idx][Carx = floatstr(CarInfo[1]);
            CarLoader[idx][Cary] = floatstr(CarInfo[2]);
            CarLoader[idx][Carz] = floatstr(CarInfo[3]);
            CarLoader[idx][Cara] = floatstr(CarInfo[4]);
            CarLoader[idx][cColor1] = strval(CarInfo[5]);
            CarLoader[idx][cColor2] = strval(CarInfo[6]);
//information of the car being read and making vehicle a behicle
            CreateVehicle(CarLoader[idx][cModel],CarLoader[idx][Carx],CarLoader[idx][Cary],CarLoader[idx][Carz],CarLoader[idx][Cara],CarLoader[idx][cColor1],CarLoader[idx][cColor2],-1);
 
            idx++;//idx goes +1 for every car created
        }
    }
    print("CARS loaded successfully.");
    return 1;
}
https://sampwiki.blast.hk/wiki/Strval
https://sampwiki.blast.hk/wiki/Floatstr


Re: Saving Vehicles on your server - Infinity - 27.10.2012

Quote:
Originally Posted by Glad2BeHere
yes i read ****** thing so please dont post it -_-
Then you should read it over and over until you actually understand it, because this tutorial is a waste of time. It's not even a tutorial to begin with! Just a rushed snippit split into 3 parts.