Advertisement
OtaconEvil

[CODE] cargado/guardado de vehiculos - By OTACON

Nov 30th, 2014
592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.71 KB | None | 0 0
  1. #define MAX_COCHES (100)
  2. new cochesitos[MAX_COCHES];
  3.  
  4. // leer el archivo
  5. new File:archivo = fopen("coches/cars.cfg", io_read), datos[200], autos;
  6. if(archivo){
  7.     while(fread(archivo, datos)){
  8.         _StripNewLine(datos);
  9.         new Float:coord[4], model;
  10.         if(!sscanf(datos, "p<,>dffff", model, coord[0],coord[1],coord[2], coord[4])){
  11.             cochesitos[autos] = AddStaticVehicleEx(model, coord[0],coord[1],coord[2], coord[4], -1, -1, 99999);
  12.         }
  13.         autos++;
  14.     }
  15.     fclose(archivo);
  16. }
  17.  
  18. // guardar en archivo
  19. new File:archivo = fopen("coches/cars.cfg", io_write), datos[200];
  20. if(archivo){
  21.     for(new vehicleid=0; vehicleid<MAX_VEHICLES; vehicleid++)   {
  22.         if(IsValidVehicle(vehicleid)){
  23.             for(new autos=0; autos<sizeof(cochesitos); autos++){
  24.                 if(vehicleid == cochesitos[autos]){
  25.                     new Float:coord[4], model;
  26.                     model = GetVehicleModel(cochesitos[autos]);
  27.                     GetVehiclePos(cochesitos[autos], coord[0],coord[1],coord[2]);
  28.                     GetVehicleZAngle(cochesitos[autos], coord[4]);
  29.                     format(datos,sizeof(datos),"%d,%f,%f,%f,%f\r\n", model,coord[0],coord[1],coord[2], coord[4]);
  30.                     fwrite(archivo, datos);
  31.                     DestroyVehicle(cochesitos[autos]);
  32.                 }
  33.             }
  34.         }
  35.     }
  36.     fclose(archivo);
  37. }
  38.  
  39. stock _StripNewLine(string[]) {//dini
  40.     new len = strlen(string);
  41.     if (string[0]==0) return ;
  42.     if ((string[len - 1] == '\n') || (string[len - 1] == '\r')) {
  43.         string[len - 1] = 0;
  44.         if (string[0]==0) return ;
  45.         if ((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0;
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement