Advertisement
Guest User

Untitled

a guest
Aug 15th, 2010
2,918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.89 KB | None | 0 0
  1. // Vehicle mod saving FS by Fresh Killa.
  2.  
  3. #include <a_samp>
  4.  
  5. forward Starting();
  6. forward LoadComponents(vehicleid);
  7. forward LoadMods();
  8. forward SaveMods();
  9. forward split(const strsrc[], strdest[][], delimiter);
  10.  
  11. new VehiclesMod[MAX_VEHICLES][11];
  12.  
  13. strtok(const string[], &index)
  14. {
  15. new length = strlen(string);
  16. while ((index < length) && (string[index] <= ' '))
  17. {
  18. index++;
  19. }
  20.  
  21. new offset = index;
  22. new result[20];
  23. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  24. {
  25. result[index - offset] = string[index];
  26. index++;
  27. }
  28. result[index - offset] = EOS;
  29. return result;
  30. }
  31.  
  32. public OnFilterScriptInit()
  33. {
  34. LoadMods();
  35. SetTimer("Starting", 10000, 0);
  36. return 1;
  37. }
  38.  
  39. public Starting()
  40. {
  41. for(new v = 0; v < MAX_VEHICLES; v++)
  42. {
  43. LoadComponents(v);
  44. }
  45. }
  46.  
  47. public OnVehicleSpawn(vehicleid)
  48. {
  49. LoadComponents(vehicleid);
  50. return 1;
  51. }
  52.  
  53. public OnVehicleMod(playerid,vehicleid,componentid)
  54. {
  55.  
  56. SendClientMessage(playerid,0xFFFFFF96,"Vehicle component bought for 100$.");
  57. GivePlayerMoney(playerid,-100);
  58. SaveMods();
  59.  
  60. if(VehiclesMod[vehicleid][0] == 0)
  61. {
  62. VehiclesMod[vehicleid][0] = componentid;
  63. }
  64. else if(VehiclesMod[vehicleid][1] == 0)
  65. {
  66. VehiclesMod[vehicleid][1] = componentid;
  67. }
  68. else if(VehiclesMod[vehicleid][2] == 0)
  69. {
  70. VehiclesMod[vehicleid][2] = componentid;
  71. }
  72. else if(VehiclesMod[vehicleid][3] == 0)
  73. {
  74. VehiclesMod[vehicleid][3] = componentid;
  75. }
  76. else if(VehiclesMod[vehicleid][4] == 0)
  77. {
  78. VehiclesMod[vehicleid][4] = componentid;
  79. }
  80. else if(VehiclesMod[vehicleid][5] == 0)
  81. {
  82. VehiclesMod[vehicleid][5] = componentid;
  83. }
  84. else if(VehiclesMod[vehicleid][6] == 0)
  85. {
  86. VehiclesMod[vehicleid][6] = componentid;
  87. }
  88. else if(VehiclesMod[vehicleid][7] == 0)
  89. {
  90. VehiclesMod[vehicleid][7] = componentid;
  91. }
  92. else if(VehiclesMod[vehicleid][8] == 0)
  93. {
  94. VehiclesMod[vehicleid][8] = componentid;
  95. }
  96. else if(VehiclesMod[vehicleid][9] == 0)
  97. {
  98. VehiclesMod[vehicleid][9] = componentid;
  99. }
  100. else
  101. {
  102. SendClientMessage(playerid,0xFFFFFF96,"Your vehicle mods are full.");
  103. }
  104. return 1;
  105. }
  106.  
  107. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  108. {
  109. VehiclesMod[vehicleid][10] = paintjobid;
  110. return 1;
  111. }
  112.  
  113. public LoadComponents(vehicleid)
  114. {
  115. if(VehiclesMod[vehicleid][0] >= 1000 && VehiclesMod[vehicleid][0] <= 1193)
  116. {
  117. if(GetVehicleComponentInSlot(vehicleid,GetVehicleComponentType(VehiclesMod[vehicleid][0])) != VehiclesMod[vehicleid][0])
  118. {
  119. AddVehicleComponent(vehicleid,VehiclesMod[vehicleid][0]);
  120. }
  121. }
  122. if(VehiclesMod[vehicleid][1] >= 1000 && VehiclesMod[vehicleid][1] <= 1193)
  123. {
  124. if(GetVehicleComponentInSlot(vehicleid,GetVehicleComponentType(VehiclesMod[vehicleid][1])) != VehiclesMod[vehicleid][1])
  125. {
  126. AddVehicleComponent(vehicleid,VehiclesMod[vehicleid][1]);
  127. }
  128. }
  129. if(VehiclesMod[vehicleid][2] >= 1000 && VehiclesMod[vehicleid][2] <= 1193)
  130. {
  131. if(GetVehicleComponentInSlot(vehicleid,GetVehicleComponentType(VehiclesMod[vehicleid][2])) != VehiclesMod[vehicleid][2])
  132. {
  133. AddVehicleComponent(vehicleid,VehiclesMod[vehicleid][2]);
  134. }
  135. }
  136. if(VehiclesMod[vehicleid][3] >= 1000 && VehiclesMod[vehicleid][3] <= 1193)
  137. {
  138. if(GetVehicleComponentInSlot(vehicleid,GetVehicleComponentType(VehiclesMod[vehicleid][3])) != VehiclesMod[vehicleid][3])
  139. {
  140. AddVehicleComponent(vehicleid,VehiclesMod[vehicleid][3]);
  141. }
  142. }
  143. if(VehiclesMod[vehicleid][4] >= 1000 && VehiclesMod[vehicleid][4] <= 1193)
  144. {
  145. if(GetVehicleComponentInSlot(vehicleid,GetVehicleComponentType(VehiclesMod[vehicleid][4])) != VehiclesMod[vehicleid][4])
  146. {
  147. AddVehicleComponent(vehicleid,VehiclesMod[vehicleid][4]);
  148. }
  149. }
  150. if(VehiclesMod[vehicleid][5] >= 1000 && VehiclesMod[vehicleid][5] <= 1193)
  151. {
  152. if(GetVehicleComponentInSlot(vehicleid,GetVehicleComponentType(VehiclesMod[vehicleid][5])) != VehiclesMod[vehicleid][5])
  153. {
  154. AddVehicleComponent(vehicleid,VehiclesMod[vehicleid][5]);
  155. }
  156. }
  157. if(VehiclesMod[vehicleid][6] >= 1000 && VehiclesMod[vehicleid][6] <= 1193)
  158. {
  159. if(GetVehicleComponentInSlot(vehicleid,GetVehicleComponentType(VehiclesMod[vehicleid][6])) != VehiclesMod[vehicleid][6])
  160. {
  161. AddVehicleComponent(vehicleid,VehiclesMod[vehicleid][6]);
  162. }
  163. }
  164. if(VehiclesMod[vehicleid][7] >= 1000 && VehiclesMod[vehicleid][7] <= 1193)
  165. {
  166. if(GetVehicleComponentInSlot(vehicleid,GetVehicleComponentType(VehiclesMod[vehicleid][7])) != VehiclesMod[vehicleid][7])
  167. {
  168. AddVehicleComponent(vehicleid,VehiclesMod[vehicleid][7]);
  169. }
  170. }
  171. if(VehiclesMod[vehicleid][8] >= 1000 && VehiclesMod[vehicleid][8] <= 1193)
  172. {
  173. if(GetVehicleComponentInSlot(vehicleid,GetVehicleComponentType(VehiclesMod[vehicleid][8])) != VehiclesMod[vehicleid][8])
  174. {
  175. AddVehicleComponent(vehicleid,VehiclesMod[vehicleid][8]);
  176. }
  177. }
  178. if(VehiclesMod[vehicleid][9] >= 1000 && VehiclesMod[vehicleid][9] <= 1193)
  179. {
  180. if(GetVehicleComponentInSlot(vehicleid,GetVehicleComponentType(VehiclesMod[vehicleid][9])) != VehiclesMod[vehicleid][9])
  181. {
  182. AddVehicleComponent(vehicleid,VehiclesMod[vehicleid][9]);
  183. }
  184. }
  185. if(VehiclesMod[vehicleid][10] > 0)
  186. {
  187. ChangeVehiclePaintjob(vehicleid,VehiclesMod[vehicleid][10]);
  188. }
  189. return 1;
  190. }
  191.  
  192. public OnPlayerCommandText(playerid, cmdtext[])
  193. {
  194. new cmd[256];
  195. new idx;
  196. cmd = strtok(cmdtext, idx);
  197.  
  198. if(strcmp("/unmodcar",cmd,true)==0)
  199. {
  200. if (!IsPlayerInAnyVehicle(playerid))
  201. {
  202. SendClientMessage(playerid,0xFFFFFF96,"You must be in a vehicle to unmod it.");
  203. return 1;
  204. }
  205. new vehicleid = GetPlayerVehicleID(playerid);
  206. if(VehiclesMod[vehicleid][0] > 0)
  207. {
  208. VehiclesMod[vehicleid][0] = 0;
  209. VehiclesMod[vehicleid][1] = 0;
  210. VehiclesMod[vehicleid][2] = 0;
  211. VehiclesMod[vehicleid][3] = 0;
  212. VehiclesMod[vehicleid][4] = 0;
  213. VehiclesMod[vehicleid][5] = 0;
  214. VehiclesMod[vehicleid][6] = 0;
  215. VehiclesMod[vehicleid][7] = 0;
  216. VehiclesMod[vehicleid][8] = 0;
  217. VehiclesMod[vehicleid][9] = 0;
  218. VehiclesMod[vehicleid][10] = 0;
  219. SendClientMessage(playerid,0xFFFFFF96,"Vehicle unmoded and Respawned.");
  220. SetVehicleToRespawn(vehicleid);
  221. return 1;
  222. }
  223. else
  224. {
  225. SendClientMessage(playerid,0xFFFFFF96,"This vehicle isnt moded.");
  226. }
  227. return 1;
  228. }
  229.  
  230. return 0;
  231. }
  232.  
  233. public LoadMods()
  234. {
  235. new arrCoords[11][64];
  236. new strFromFile2[256];
  237. new File: file = fopen("carmods.cfg", io_read);
  238. if (file)
  239. {
  240. new idx;
  241. while((idx < MAX_VEHICLES))
  242. {
  243. fread(file, strFromFile2);
  244. split(strFromFile2, arrCoords, '|');
  245. VehiclesMod[idx][0] = strval(arrCoords[0]);
  246. VehiclesMod[idx][1] = strval(arrCoords[1]);
  247. VehiclesMod[idx][2] = strval(arrCoords[2]);
  248. VehiclesMod[idx][3] = strval(arrCoords[3]);
  249. VehiclesMod[idx][4] = strval(arrCoords[4]);
  250. VehiclesMod[idx][5] = strval(arrCoords[5]);
  251. VehiclesMod[idx][6] = strval(arrCoords[6]);
  252. VehiclesMod[idx][7] = strval(arrCoords[7]);
  253. VehiclesMod[idx][8] = strval(arrCoords[8]);
  254. VehiclesMod[idx][9] = strval(arrCoords[9]);
  255. VehiclesMod[idx][10] = strval(arrCoords[10]);
  256. idx++;
  257. }
  258. fclose(file);
  259. }
  260. return 1;
  261. }
  262.  
  263. public SaveMods()
  264. {
  265. new idx;
  266. new File: file2;
  267. while((idx < MAX_VEHICLES))
  268. {
  269. new coordsstring[256];
  270. format(coordsstring, sizeof(coordsstring), "%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d\n",
  271. VehiclesMod[idx][0],
  272. VehiclesMod[idx][1],
  273. VehiclesMod[idx][2],
  274. VehiclesMod[idx][3],
  275. VehiclesMod[idx][4],
  276. VehiclesMod[idx][5],
  277. VehiclesMod[idx][6],
  278. VehiclesMod[idx][7],
  279. VehiclesMod[idx][8],
  280. VehiclesMod[idx][9],
  281. VehiclesMod[idx][10]);
  282. if(idx == 0)
  283. {
  284. file2 = fopen("carmods.cfg", io_write);
  285. }
  286. else
  287. {
  288. file2 = fopen("carmods.cfg", io_append);
  289. }
  290. fwrite(file2, coordsstring);
  291. idx++;
  292. fclose(file2);
  293. }
  294. return 1;
  295. }
  296.  
  297. stock PointOverString(string[], argument, schar)
  298. {
  299. new length = strlen(string), arg, result[128], index;
  300. for (new i = 0; i < length; i++)
  301. {
  302. if (string[i] == schar || i == length || string[i + 1] == 10)
  303. {
  304. arg++;
  305. if (arg == argument + 1)
  306. {
  307. result[i-index] = EOS;
  308. return result;
  309. }
  310. else if (arg == argument)
  311. index = i+1;
  312. }
  313. else if (arg == argument)
  314. result[i - index] = string[i];
  315. }
  316. return result;
  317. }
  318.  
  319. public split(const strsrc[], strdest[][], delimiter)
  320. {
  321. new i, li;
  322. new aNum;
  323. new len;
  324. while(i <= strlen(strsrc)){
  325. if(strsrc[i]==delimiter || i==strlen(strsrc)){
  326. len = strmid(strdest[aNum], strsrc, li, i, 128);
  327. strdest[aNum][len] = 0;
  328. li = i+1;
  329. aNum++;
  330. }
  331. i++;
  332. }
  333. return 1;
  334. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement