Guest User

Untitled

a guest
Jan 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.79 KB | None | 0 0
  1. //===========================Section: Includes==================================
  2. #include <a_samp>
  3. //===========================Section: Definations===============================
  4. #define COLOR_GRAD1 0xB4B5B7FF
  5. #define COLOR_GRAD2 0xBFC0C2FF
  6. #define COLOR_GRAD3 0xCBCCCEFF
  7. #define COLOR_GRAD4 0xD8D8D8FF
  8. #define COLOR_GRAD5 0xE3E3E3FF
  9. #define COLOR_GRAD6 0xF0F0F0FF
  10. #define COLOR_GREEN 0x33AA33AA
  11. #define COLOR_GREY 0xAFAFAFAA
  12. #define COLOR_WHITE 0xFFFFFFAA
  13. #define COLOR_YELLOW 0xFFFF00AA
  14. #define COLOR_YELLOW2 0xF5DEB3AA
  15. #define COLOR_LIGHTRED 0xFF8080FF
  16. #define COLOR_GOLD 0xFFD700FF
  17. //===========================Section: Forwards==================================
  18. forward split(const strsrc[], strdest[][], delimiter);
  19. forward LoadCar();
  20. forward CheckOwner(playerid);
  21. forward SaveCars();
  22. //===========================Section: Variables=================================
  23. enum pInfo
  24. {
  25. pCarKey,
  26. }
  27. new PlayerInfo[256][pInfo];
  28. enum cInfo
  29. {
  30. cModel,
  31. Float:cLocationx,
  32. Float:cLocationy,
  33. Float:cLocationz,
  34. Float:cAngle,
  35. cColorOne,
  36. cColorTwo,
  37. cOwner[MAX_PLAYER_NAME],
  38. cDescription[MAX_PLAYER_NAME],
  39. cValue,
  40. cLicense,
  41. cRegistration,
  42. cOwned,
  43. cLock,
  44. ownedvehicle,
  45. };
  46. new CarInfo[12][cInfo];
  47.  
  48. new CarAutolock[999]; // Variable for Autolocking Car Doors
  49. new cartrack[256];
  50. new CarOffered[256];
  51. //===========================Section: strtok & split============================
  52. strtok(const string[], &index)
  53. {
  54. new length = strlen(string);
  55. while ((index < length) && (string[index] <= ' '))
  56. {
  57. index++;
  58. }
  59.  
  60. new offset = index;
  61. new result[20];
  62. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  63. {
  64. result[index - offset] = string[index];
  65. index++;
  66. }
  67. result[index - offset] = EOS;
  68. return result;
  69. }
  70.  
  71. public split(const strsrc[], strdest[][], delimiter)
  72. {
  73. new i, li;
  74. new aNum;
  75. new len;
  76. while(i <= strlen(strsrc)){
  77. if(strsrc[i]==delimiter || i==strlen(strsrc)){
  78. len = strmid(strdest[aNum], strsrc, li, i, 128);
  79. strdest[aNum][len] = 0;
  80. li = i+1;
  81. aNum++;
  82. }
  83. i++;
  84. }
  85. return 1;
  86. }
  87. //===========================Section: Callbacks & Functions=====================
  88. public OnFilterScriptInit()
  89. {
  90. printf("Filterscript [FS]CarOwnership.amx Initiated\n");
  91. LoadCar();
  92. for(new i = 1; i < sizeof(CarInfo); i++)
  93. {
  94. CarInfo[i][ownedvehicle] = CreateVehicle(CarInfo[i][cModel],CarInfo[i][cLocationx],CarInfo[i][cLocationy],CarInfo[i][cLocationz],CarInfo[i][cAngle],CarInfo[i][cColorOne],CarInfo[i][cColorTwo],300000);
  95. }
  96. SetTimer("SaveCars",60000,1);
  97. SetTimer("CheckOwner",5000,1);
  98. return 1;
  99. }
  100. public OnVehicleSpawn(vehicleid)
  101. {
  102. for(new i = 1; i < sizeof(CarInfo); i++)
  103. {
  104. ChangeVehicleColor(CarInfo[i][ownedvehicle],CarInfo[vehicleid][cColorOne],CarInfo[vehicleid][cColorTwo]);
  105. }
  106. return 1;
  107. }
  108. public CheckOwner(playerid)
  109. {
  110. if(IsPlayerConnected(playerid))
  111. {
  112. for(new i = 1; i < sizeof(CarInfo); i++)
  113. {
  114. new playername[MAX_PLAYER_NAME];
  115. GetPlayerName(playerid,playername,sizeof(playername));
  116. if(strcmp(playername,CarInfo[i][cOwner],true)==0)
  117. {
  118. PlayerInfo[i][pCarKey] = i;
  119. return i;
  120. }
  121. }
  122. }
  123. return 1;
  124. }
  125. public OnPlayerConnect(playerid)
  126. {
  127. PlayerInfo[playerid][pCarKey] = 0;
  128. CheckOwner(playerid);
  129. return 1;
  130. }
  131. public OnPlayerCommandText(playerid, cmdtext[])
  132. {
  133. new idx;
  134. new string[256];
  135. new cmd[256];
  136. new tmp[256];
  137. new sendername[MAX_PLAYER_NAME];
  138. cmd = strtok(cmdtext, idx);
  139. new vehid = GetPlayerVehicleID(playerid);
  140. if(strcmp(cmd, "/carbuy", true) == 0)
  141. {
  142. if(IsPlayerConnected(playerid))
  143. {
  144. for(new i = 0; i < sizeof(CarInfo); i++)
  145. {
  146. if(CarInfo[i][ownedvehicle] == vehid)
  147. {
  148. if(PlayerInfo[playerid][pCarKey]!=0)
  149. {
  150. SendClientMessage(playerid, COLOR_GREY, "Vec imate auto, napisite /car sell da prodate svoj te kupite novi!!");
  151. return 1;
  152. }
  153. if(CarInfo[i][cOwned]==1)
  154. {
  155. SendClientMessage(playerid, COLOR_GREY, "Ovo vozilo vec ima vlasnika!");
  156. return 1;
  157. }
  158. if(GetPlayerMoney(playerid) >= CarInfo[i][cValue])
  159. {
  160. PlayerInfo[playerid][pCarKey] = i;
  161. CarInfo[i][cOwned] = 1;
  162. CarOffered[playerid]=0;
  163. GetPlayerName(playerid, sendername, sizeof(sendername));
  164. strmid(CarInfo[i][cOwner], sendername, 0, strlen(sendername), 999);
  165. GivePlayerMoney(playerid,-CarInfo[i][cValue]);
  166. GameTextForPlayer(playerid, "~w~Cestitamo~n~Kupili ste auto te je vas dok ga ne prodate!", 5000, 3);
  167. SendClientMessage(playerid, COLOR_GOLD, "INFO: Cestitamo na novoj kupnji!!");
  168. SendClientMessage(playerid, COLOR_GOLD, "INFO: Napisite /car manual da vidite vise informacija!");
  169. TogglePlayerControllable(playerid, 1);
  170. SaveCars();
  171. return 1;
  172. }
  173. else
  174. {
  175. SendClientMessage(playerid, COLOR_LIGHTRED, " Nemate dovoljno novaca!");
  176. return 1;
  177. }
  178. }
  179. }
  180. }
  181. return 1;
  182. }
  183. if(strcmp(cmd,"/car",true)==0)
  184. {
  185. new playername[MAX_PLAYER_NAME];
  186. GetPlayerName(playerid,playername,sizeof(playername));
  187. tmp = strtok(cmdtext, idx);
  188. if(!strlen(tmp))
  189. {
  190. SendClientMessage(playerid,COLOR_GOLD,"INFO: Koristite /car manual za popis mogucih komandi");
  191. return 1;
  192. }
  193. if(strcmp(tmp,"exit",true)==0)
  194. {
  195. CarOffered[playerid]=0;
  196. RemovePlayerFromVehicle(playerid);
  197. TogglePlayerControllable(playerid, 1);
  198. return 1;
  199. }
  200. if(strcmp(tmp, "manual", true) == 0)
  201. {
  202. if(IsPlayerConnected(playerid))
  203. {
  204. if(PlayerInfo[playerid][pCarKey]!=0)
  205. {
  206. format(string,sizeof(string),"________________%s________________",CarInfo[CheckOwner(playerid)][cDescription]);
  207. SendClientMessage(playerid, COLOR_GREEN,string);
  208. SendClientMessage(playerid, COLOR_GRAD2,"** /carbuy - Kupuje auto (ako je za prodaju)");
  209. SendClientMessage(playerid, COLOR_GRAD2,"** /car sell - Prodaje taj auto");
  210. SendClientMessage(playerid, COLOR_GRAD2,"** /car manual - Pokazuje ove komande");
  211. SendClientMessage(playerid, COLOR_GRAD2,"** /car exit - Izlazi iz auta");
  212. SendClientMessage(playerid, COLOR_GRAD2,"** /car locate - Uses the car's On-Star to locate");
  213. SendClientMessage(playerid, COLOR_GRAD2,"** /car lock - Zakljucava auto");
  214. SendClientMessage(playerid, COLOR_GRAD2,"** /car unlock - Otkljucava auto");
  215. SendClientMessage(playerid, COLOR_GRAD2,"** /car autolock - Automatski zakljucava auto kada izadete!");
  216. return 1;
  217. }
  218. else
  219. {
  220. SendClientMessage(playerid,COLOR_LIGHTRED,"ERROR: Nemate auto!");
  221. return 1;
  222. }
  223. }
  224. return 1;
  225. }
  226. if(strcmp(tmp, "buy", true) == 0)
  227. {
  228. if(IsPlayerConnected(playerid))
  229. {
  230. for(new i = 0; i < sizeof(CarInfo); i++)
  231. {
  232. if(CarInfo[i][ownedvehicle] == vehid)
  233. {
  234. if(PlayerInfo[playerid][pCarKey]!=0)
  235. {
  236. SendClientMessage(playerid, COLOR_GREY, "Vec imate auto, napisite /car sell da prodate svoj te kupite novi!!");
  237. return 1;
  238. }
  239. if(CarInfo[i][cOwned]==1)
  240. {
  241. SendClientMessage(playerid, COLOR_GREY, "Netko vec posjeduje ovaj auto!");
  242. return 1;
  243. }
  244. if(GetPlayerMoney(playerid) >= CarInfo[i][cValue])
  245. {
  246. PlayerInfo[playerid][pCarKey] = i;
  247. CarInfo[i][cOwned] = 1;
  248. CarOffered[playerid]=0;
  249. GetPlayerName(playerid, sendername, sizeof(sendername));
  250. strmid(CarInfo[i][cOwner], sendername, 0, strlen(sendername), 999);
  251. GivePlayerMoney(playerid,-CarInfo[i][cValue]);
  252. GameTextForPlayer(playerid, "~w~Cestitamo~n~Kupili ste auto te je vas dok ga ne prodate!", 5000, 3);
  253. SendClientMessage(playerid, COLOR_GOLD, "INFO: Cestitamo na novoj kupnji!!");
  254. SendClientMessage(playerid, COLOR_GOLD, "INFO: Napisite /car manual da vidite vise informacija!");
  255. TogglePlayerControllable(playerid, 1);
  256. SaveCars();
  257. return 1;
  258. }
  259. else
  260. {
  261. SendClientMessage(playerid, COLOR_GREY, " You don't have the cash for that!");
  262. return 1;
  263. }
  264. }
  265. }
  266. }
  267. return 1;
  268. }
  269. if(strcmp(tmp, "sell", true) == 0)
  270. {
  271. if(IsPlayerConnected(playerid))
  272. {
  273. GetPlayerName(playerid, playername, sizeof(playername));
  274. if(PlayerInfo[playerid][pCarKey] == 0)
  275. {
  276. SendClientMessage(playerid, COLOR_GREY, "You don't own a car.");
  277. return 1;
  278. }
  279. if(PlayerInfo[playerid][pCarKey] != 0 && strcmp(playername, CarInfo[PlayerInfo[playerid][pCarKey]][cOwner], true) == 0)
  280. {
  281. new car = PlayerInfo[playerid][pCarKey];
  282. CarInfo[car][cOwned] = 0;
  283. GetPlayerName(playerid, sendername, sizeof(sendername));
  284. strmid(CarInfo[car][cOwner], "Dealership", 0, strlen("Dealership"), 999);
  285. GivePlayerMoney(playerid,CarInfo[car][cValue]);
  286. PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
  287. format(string, sizeof(string), "~w~You have sold your car for: ~n~~g~$%d", CarInfo[car][cValue]);
  288. GameTextForPlayer(playerid, string, 10000, 3);
  289. RemovePlayerFromVehicle(playerid);
  290. TogglePlayerControllable(playerid, 1);
  291. PlayerInfo[playerid][pCarKey] = 999;
  292. return 1;
  293. }
  294. }
  295. return 1;
  296. }
  297. if(strcmp(tmp, "locate", true) == 0)
  298. {
  299. if(!IsPlayerConnected(playerid)) { return 1; }
  300. if(PlayerInfo[playerid][pCarKey] == 0) { GameTextForPlayer(playerid, "~w~You do not have a car to locate", 2500, 3); return 1; }
  301. if(cartrack[playerid]==0)
  302. {
  303. SendClientMessage(playerid,COLOR_WHITE,"On-Star: This is On-Star's automated vehicle tracking system");
  304. SendClientMessage(playerid,COLOR_WHITE,"On-Star: Please enter your PIN # and password now");
  305. SendClientMessage(playerid,COLOR_WHITE,"On-Star: Your vehicle's location is now uploaded to your phone");
  306. SetPlayerCheckpoint(playerid,CarInfo[PlayerInfo[playerid][pCarKey]][cLocationx], CarInfo[PlayerInfo[playerid][pCarKey]][cLocationy], CarInfo[PlayerInfo[playerid][pCarKey]][cLocationz], 5.0);
  307. cartrack[playerid] = 1;
  308. return 1;
  309. }
  310. else
  311. {
  312. SendClientMessage(playerid,COLOR_WHITE,"On-Star: This is On-Star's automated vehicle tracking system");
  313. SendClientMessage(playerid,COLOR_WHITE,"On-Star: The tracking on your vehicle has been canceled");
  314. DisablePlayerCheckpoint(playerid);
  315. cartrack[playerid] = 0;
  316. return 1;
  317. }
  318. }
  319. if(strcmp(tmp, "lock", true) == 0)
  320. {
  321. new keycar = PlayerInfo[playerid][pCarKey];
  322. if(IsPlayerConnected(playerid))
  323. {
  324. for(new i = 0; i < MAX_PLAYERS; i++)
  325. {
  326. SetVehicleParamsForPlayer(CarInfo[keycar][ownedvehicle],i,0,1);
  327. }
  328. format(string, sizeof(string), "~w~Car~n~~r~Locked");
  329. GameTextForPlayer(playerid, string, 10000, 3);
  330. CarInfo[keycar][cLock] = 1;
  331. return 1;
  332. }
  333. }
  334. if(strcmp(tmp, "unlock", true) == 0)
  335. {
  336. new keycar = PlayerInfo[playerid][pCarKey];
  337. if(IsPlayerConnected(playerid))
  338. {
  339. for(new i = 0; i < MAX_PLAYERS; i++)
  340. {
  341. SetVehicleParamsForPlayer(CarInfo[keycar][ownedvehicle],i,0,0);
  342. }
  343. format(string, sizeof(string), "~w~Car~n~~g~Unlocked");
  344. GameTextForPlayer(playerid, string, 10000, 3);
  345. CarInfo[keycar][cLock] = 0;
  346. return 1;
  347. }
  348. }
  349. if(strcmp(tmp, "autolock", true) == 0)
  350. {
  351. new keycar = PlayerInfo[playerid][pCarKey];
  352. if(CarAutolock[CarInfo[keycar][ownedvehicle]] == 0) { CarAutolock[CarInfo[keycar][ownedvehicle]] = 1; format(string, sizeof(string), "~w~Car Autolock~n~~r~Engaged"); return 1; }
  353. if(CarAutolock[CarInfo[keycar][ownedvehicle]] == 1) { CarAutolock[CarInfo[keycar][ownedvehicle]] = 0; format(string, sizeof(string), "~w~Car Autolock~n~~g~Disengaged"); return 1; }
  354. GameTextForPlayer(playerid, string, 10000, 3);
  355. return 1;
  356. }
  357. }
  358. return 0;
  359. }
  360. /*----------Car Save Functions----------*/
  361. public LoadCar()
  362. {
  363. new arrCoords[13][64];
  364. new strFromFile2[256];
  365. new File: file = fopen("[FS]CarOwnership.cfg", io_read);
  366. if (file)
  367. {
  368. new idx = 0;
  369. while (idx < sizeof(CarInfo))
  370. {
  371. fread(file, strFromFile2);
  372. split(strFromFile2, arrCoords, ',');
  373. CarInfo[idx][cModel] = strval(arrCoords[0]);
  374. CarInfo[idx][cLocationx] = floatstr(arrCoords[1]);
  375. CarInfo[idx][cLocationy] = floatstr(arrCoords[2]);
  376. CarInfo[idx][cLocationz] = floatstr(arrCoords[3]);
  377. CarInfo[idx][cAngle] = floatstr(arrCoords[4]);
  378. CarInfo[idx][cColorOne] = strval(arrCoords[5]);
  379. CarInfo[idx][cColorTwo] = strval(arrCoords[6]);
  380. strmid(CarInfo[idx][cOwner], arrCoords[7], 0, strlen(arrCoords[7]), 255);
  381. strmid(CarInfo[idx][cDescription], arrCoords[8], 0, strlen(arrCoords[8]), 255);
  382. CarInfo[idx][cValue] = strval(arrCoords[9]);
  383. CarInfo[idx][cLicense] = strval(arrCoords[10]);
  384. CarInfo[idx][cOwned] = strval(arrCoords[11]);
  385. CarInfo[idx][cLock] = strval(arrCoords[12]);
  386. printf("CarInfo: %d Owner:%s LicensePlate %s",idx,CarInfo[idx][cOwner],CarInfo[idx][cLicense]);
  387. idx++;
  388. }
  389. }
  390. return 1;
  391. }
  392. public SaveCars()
  393. {
  394. new idx;
  395. new File: file2;
  396. while (idx < sizeof(CarInfo))
  397. {
  398. new coordsstring[256];
  399. format(coordsstring, sizeof(coordsstring), "%d,%f,%f,%f,%f,%d,%d,%s,%s,%d,%s,%d,%d\n",
  400. CarInfo[idx][cModel],
  401. CarInfo[idx][cLocationx],
  402. CarInfo[idx][cLocationy],
  403. CarInfo[idx][cLocationz],
  404. CarInfo[idx][cAngle],
  405. CarInfo[idx][cColorOne],
  406. CarInfo[idx][cColorTwo],
  407. CarInfo[idx][cOwner],
  408. CarInfo[idx][cDescription],
  409. CarInfo[idx][cValue],
  410. CarInfo[idx][cLicense],
  411. CarInfo[idx][cOwned],
  412. CarInfo[idx][cLock]);
  413. if(idx == 0)
  414. {
  415. file2 = fopen("[FS]CarOwnership.cfg", io_write);
  416. }
  417. else
  418. {
  419. file2 = fopen("[FS]CarOwnership.cfg", io_append);
  420. }
  421. fwrite(file2, coordsstring);
  422. idx++;
  423. fclose(file2);
  424. }
  425. return 1;
  426. }
  427.  
  428. public OnVehicleRespray(vehicleid, color1, color2)
  429. {
  430. for(new i = 0; i < sizeof(CarInfo); i++)
  431. {
  432. if(vehicleid == CarInfo[i][ownedvehicle])
  433. {
  434. CarInfo[i][cColorOne] = color1;
  435. CarInfo[i][cColorTwo] = color2;
  436. printf("[FS]CarOwnership report");
  437. printf("** Car %s[%d] painted %d and %d",CarInfo[i][cDescription],i,color1,color2);
  438. }
  439. }
  440. return 1;
  441. }
  442. public OnPlayerExitVehicle(playerid, vehicleid)
  443. {
  444. if(IsPlayerConnected(playerid))
  445. {
  446. for(new i = 0; i < sizeof(CarInfo); i++)
  447. {
  448. if(vehicleid == CarInfo[i][ownedvehicle])
  449. {
  450. new Float:x,Float:y,Float:z;
  451. new Float:a;
  452. GetVehiclePos(vehicleid, x, y, z);
  453. GetVehicleZAngle(vehicleid, a);
  454. CarInfo[i][cLocationx] = x;
  455. CarInfo[i][cLocationy] = y;
  456. CarInfo[i][cLocationz] = z;
  457. CarInfo[i][cAngle] = a;
  458. }
  459. if(CarAutolock[vehicleid] == 1)
  460. {
  461. for(new j = 0; j < MAX_PLAYERS; i++)
  462. {
  463. if (IsPlayerConnected(j))
  464. {
  465. SetVehicleParamsForPlayer(vehicleid,j,0,1);
  466. GameTextForPlayer(playerid,"~w~Car~n~~r~Autolocked",2500,3);
  467. return 1;
  468. }
  469. }
  470. }
  471. }
  472. }
  473. return 1;
  474. }
  475. public OnPlayerStateChange(playerid, newstate, oldstate)
  476. {
  477. if(newstate==2)
  478. {
  479. for(new i = 0; i < sizeof(CarInfo); i++)
  480. {
  481. new newcar = GetPlayerVehicleID(playerid);
  482. new string[256];
  483. if(newcar == CarInfo[i][ownedvehicle])
  484. {
  485. if(CarInfo[i][cOwned]==0)
  486. {
  487. TogglePlayerControllable(playerid, 0);
  488. CarOffered[playerid]=1;
  489. format(string,sizeof(string),"~w~Model: %s~n~Cijena: ~g~%d~n~~w~/carbuy da kupite auto!",CarInfo[i][cDescription],CarInfo[i][cValue]);
  490. GameTextForPlayer(playerid,string,5000,5);
  491. }
  492. }
  493. }
  494. }
  495. return 1;
  496. }
  497. public OnPlayerEnterCheckpoint(playerid)
  498. {
  499. if(cartrack[playerid]!=0)
  500. {
  501. SendClientMessage(playerid,COLOR_GOLD,"SMS: On-Star: Our sensors show that you have come within 5.0 metres of your vehicle");
  502. DisablePlayerCheckpoint(playerid);
  503. cartrack[playerid] = 0;
  504. }
  505. return 1;
  506. }
Add Comment
Please, Sign In to add comment