Sistema de vehнculos
#4

pawn Код:
#define MAX_COCHES (100)
new cochesitos[MAX_COCHES];
pawn Код:
// leer el archivo
new File:archivo = fopen("coches/cars.cfg", io_read), datos[200], autos;
if(archivo){
    while(fread(archivo, datos)){
        _StripNewLine(datos);
        new Float:coord[4], model;
        if(!sscanf(datos, "p<,>dffff", model, coord[0],coord[1],coord[2], coord[4])){
            cochesitos[autos] = AddStaticVehicleEx(model, coord[0],coord[1],coord[2], coord[4], -1, -1, 99999);
        }
        autos++;
    }
    fclose(archivo);
}
pawn Код:
// guardar en archivo
new File:archivo = fopen("coches/cars.cfg", io_write), datos[200];
if(archivo){
    for(new vehicleid=0; vehicleid<MAX_VEHICLES; vehicleid++)   {
        if(IsValidVehicle(vehicleid)){
            for(new autos=0; autos<sizeof(cochesitos); autos++){
                if(vehicleid == cochesitos[autos]){
                    new Float:coord[4], model;
                    model = GetVehicleModel(cochesitos[autos]);
                    GetVehiclePos(cochesitos[autos], coord[0],coord[1],coord[2]);
                    GetVehicleZAngle(cochesitos[autos], coord[4]);
                    format(datos,sizeof(datos),"%d,%f,%f,%f,%f\r\n", model,coord[0],coord[1],coord[2], coord[4]);
                    fwrite(archivo, datos);
                    DestroyVehicle(cochesitos[autos]);
                }
            }
        }
    }
    fclose(archivo);
}
pawn Код:
stock _StripNewLine(string[]) {//dini
    new len = strlen(string);
    if (string[0]==0) return ;
    if ((string[len - 1] == '\n') || (string[len - 1] == '\r')) {
        string[len - 1] = 0;
        if (string[0]==0) return ;
        if ((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0;
    }
}
https://sampwiki.blast.hk/wiki/File_Functions
Reply


Messages In This Thread
Sistema de vehнculos - by ib95 - 29.11.2014, 21:47
Respuesta: Sistema de vehнculos - by jwalker - 30.11.2014, 03:35
Re: Sistema de vehнculos - by ib95 - 30.11.2014, 10:09
Respuesta: Sistema de vehнculos - by OTACON - 30.11.2014, 13:07
Re: Sistema de vehнculos - by ib95 - 30.11.2014, 14:42
Respuesta: Sistema de vehнculos - by OTACON - 30.11.2014, 17:05
Respuesta: Re: Sistema de vehнculos - by jwalker - 30.11.2014, 17:52
Re: Respuesta: Re: Sistema de vehнculos - by ib95 - 30.11.2014, 18:24
Respuesta: Sistema de vehнculos - by hotspicytaco - 30.11.2014, 18:38
Re: Respuesta: Sistema de vehнculos - by ib95 - 30.11.2014, 19:27

Forum Jump:


Users browsing this thread: 3 Guest(s)