Advertisement
Chaoz

SA-MP Load/Save vehicle

Jun 24th, 2013
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.02 KB | None | 0 0
  1. #include <a_samp>
  2. #include <sscanf2>
  3.  
  4. enum ENUM_VEHICLE_DATA
  5. {
  6.     v_color[2],
  7.     v_delay,
  8. };
  9.  
  10. new VData[MAX_VEHICLES][ENUM_VEHICLE_DATA];
  11.  
  12. stock _AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2, respawn_delay=65535)
  13. {
  14.     new
  15.         id;
  16.  
  17.     if(respawn_delay == 65535)
  18.         id = AddStaticVehicle(modelid, spawn_x, spawn_y, spawn_z, angle, color1, color2);
  19.     else
  20.         id = AddStaticVehicleEx(modelid, spawn_x, spawn_y, spawn_z, angle, color1, color2, respawn_delay);
  21.  
  22.     if(id < 1 || id > 2000)
  23.         return id;
  24.  
  25.     VData[id][v_color][0] = color1;
  26.     VData[id][v_color][1] = color2;
  27.     VData[id][v_delay] = respawn_delay;
  28.  
  29.     return id;
  30. }
  31.  
  32. #if defined _ALS_AddStaticVehicle
  33.     #undef AddStaticVehicle
  34. #else
  35.     #define _ALS_AddStaticVehicle
  36. #endif
  37.  
  38. #define AddStaticVehicle _AddStaticVehicle
  39.  
  40. #if defined _ALS_AddStaticVehicleEx
  41.     #undef AddStaticVehicleEx
  42. #else
  43.     #define _ALS_AddStaticVehicleEx
  44. #endif
  45.  
  46. #define AddStaticVehicleEx _AddStaticVehicle
  47.  
  48. stock _CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay)
  49. {
  50.     new
  51.         id;
  52.  
  53.     id = CreateVehicle(modelid, x, y, z, angle, color1, color2, respawn_delay);
  54.  
  55.     if(id < 1 || id > 2000)
  56.         return id;
  57.  
  58.     VData[id][v_color][0] = color1;
  59.     VData[id][v_color][1] = color2;
  60.     VData[id][v_delay] = respawn_delay;
  61.  
  62.     return id;
  63. }
  64.  
  65. #if defined _ALS_CreateVehicle
  66.     #undef CreateVehicle
  67. #else
  68.     #define _ALS_CreateVehicle
  69. #endif
  70.  
  71. #define CreateVehicle _CreateVehicle
  72.  
  73. stock SaveVehicle(const path[], vehicleid)
  74. {
  75.     new
  76.         model;
  77.        
  78.     if(!(model = GetVehicleModel(vehicleid)))
  79.         return 0;
  80.  
  81.     new
  82.         File:fhnd,
  83.         Float:P[4],
  84.         color[2],
  85.         delay,
  86.         buffer[64];
  87.        
  88.     fhnd = fopen(path, ((!fexist(path)) ? (io_write) : (io_append)));
  89.    
  90.     GetVehiclePos(vehicleid, P[0], P[1], P[2]);
  91.     GetVehicleZAngle(vehicleid, P[3]);
  92.     GetVehicleColor(vehicleid, color[0], color[1]);
  93.     GetVehicleDelay(vehicleid, delay);
  94.    
  95.     format(buffer, 64, "%i %f %f %f %f %i %i %i\r\n", model, P[0], P[1], P[2], P[3], color[0], color[1], delay);
  96.  
  97.     fwrite(fhnd, buffer);
  98.     fclose(fhnd);
  99.    
  100.     return 1;
  101. }
  102.  
  103. stock LoadVehicles(const path[])
  104. {
  105.     if(!fexist(path))
  106.         return 0;
  107.  
  108.     new
  109.         File:fhnd,
  110.         buffer[64],
  111.         model,
  112.         Float:P[4],
  113.         color[2],
  114.         delay;
  115.    
  116.     fhnd = fopen(path, io_read);
  117.     while(fread(fhnd, buffer))
  118.     {
  119.         if(buffer[0] == '#')
  120.             continue;
  121.  
  122.         sscanf(buffer, "iffffiii", model, P[0], P[1], P[2], P[3], color[0], color[1], delay);
  123.         AddStaticVehicleEx(model, P[0], P[1], P[2], P[3], color[0], color[1], delay);
  124.     }
  125.     fclose(fhnd);
  126.    
  127.     return 1;
  128. }
  129.  
  130. stock GetVehicleColor(vehicleid, &color1, &color2)
  131. {
  132.     if(vehicleid < 1 || vehicleid > MAX_VEHICLES)
  133.         return 0;
  134.        
  135.     color1 = VData[vehicleid][v_color][0];
  136.     color2 = VData[vehicleid][v_color][1];
  137.    
  138.     return 1;
  139. }
  140.  
  141. stock GetVehicleDelay(vehicleid, &delay)
  142. {
  143.     if(vehicleid < 1 || vehicleid > MAX_VEHICLES)
  144.         return 0;
  145.  
  146.     delay = VData[vehicleid][v_delay];
  147.  
  148.     return 1;
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement