Advertisement
Guest User

Coole210

a guest
Jun 17th, 2009
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.25 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. #pragma unused CarAutolock
  16. #define COLOR_RED 0xFF0000AA
  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, "You already own a car, type /car sell if you want to buy this one!");
  151. return 1;
  152. }
  153. if(CarInfo[i][cOwned]==1)
  154. {
  155. SendClientMessage(playerid, COLOR_GREY, "Someone already owns this car");
  156. return 1;
  157. }
  158. if(CallRemoteFunction("GetPlayerTcash","i",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. CallRemoteFunction("GivePlayerTcash","i",playerid,-CarInfo[i][cValue]);
  166. GameTextForPlayer(playerid, "~w~Congratulations~n~This is your car until you sell it!", 5000, 3);
  167. SendClientMessage(playerid, COLOR_GRAD2, "Congratulations on your new purchase!");
  168. SendClientMessage(playerid, COLOR_GRAD2, "Type /car manual to view the car manual!");
  169. TogglePlayerControllable(playerid, 1);
  170. SaveCars();
  171. return 1;
  172. }
  173. else
  174. {
  175. SendClientMessage(playerid, COLOR_GREY, " You don't have the Tcash for that!");
  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_WHITE,"(( Use /help car for detailed instructions for: ))");
  191. return 1;
  192. }
  193. if(strcmp(tmp, "/help car", true) == 0)
  194. {
  195. if(IsPlayerConnected(playerid))
  196. {
  197. if(PlayerInfo[playerid][pCarKey]!=0)
  198. {
  199. format(string,sizeof(string),"________________%s________________",CarInfo[CheckOwner(playerid)][cDescription]);
  200. SendClientMessage(playerid, COLOR_GREEN,string);
  201. SendClientMessage(playerid, COLOR_GREEN,"** /buy - Buys the car (if for sale)");
  202. SendClientMessage(playerid, COLOR_GREEN,"** /sell - Sells the car");
  203. SendClientMessage(playerid, COLOR_GREEN,"** /help car - Shows this list");
  204. SendClientMessage(playerid, COLOR_GREEN,"** /whereismycar - Uses the car's On-Star to locate");
  205. SendClientMessage(playerid, COLOR_GREEN,"** /lock - Locks the car");
  206. SendClientMessage(playerid, COLOR_GREEN,"** /unlock - Unlocks the car");
  207. return 1;
  208. }
  209. else
  210. {
  211. SendClientMessage(playerid,COLOR_RED,"** You do not currently own a car! **");
  212. return 1;
  213. }
  214. }
  215. return 1;
  216. }
  217. if(strcmp(tmp, "/buy", true) == 0)
  218. {
  219. if(IsPlayerConnected(playerid))
  220. {
  221. for(new i = 0; i < sizeof(CarInfo); i++)
  222. {
  223. if(CarInfo[i][ownedvehicle] == vehid)
  224. {
  225. if(PlayerInfo[playerid][pCarKey]!=0)
  226. {
  227. SendClientMessage(playerid, COLOR_RED, "You already own a car! type /sell to sell yours.");
  228. }
  229. if(CarInfo[i][cOwned]==1)
  230. {
  231. SendClientMessage(playerid, COLOR_RED, "Someone already owns this car");
  232. return 1;
  233. }
  234. if(CallRemoteFunction("GetPlayerTcash","i",playerid) >= CarInfo[i][cValue])
  235. {
  236. PlayerInfo[playerid][pCarKey] = i;
  237. CarInfo[i][cOwned] = 1;
  238. CarOffered[playerid]=0;
  239. GetPlayerName(playerid, sendername, sizeof(sendername));
  240. strmid(CarInfo[i][cOwner], sendername, 0, strlen(sendername), 999);
  241. CallRemoteFunction("GivePlayerTcash","i",playerid,-CarInfo[i][cValue]);
  242. SendClientMessage(playerid, COLOR_GREEN, "This car is now yours!");
  243. SendClientMessage(playerid, COLOR_GREEN, "Congratulations on your new purchase!");
  244. SendClientMessage(playerid, COLOR_GREEN, "Type /manual to view the car manual!");
  245. TogglePlayerControllable(playerid, 1);
  246. SaveCars();
  247. return 1;
  248. }
  249. else
  250. {
  251. SendClientMessage(playerid, COLOR_GREY, " You don't have the cash for that!");
  252. return 1;
  253. }
  254. }
  255. }
  256. }
  257. return 1;
  258. }
  259. if(strcmp(tmp, "/sell", true) == 0)
  260. {
  261. if(IsPlayerConnected(playerid))
  262. {
  263. GetPlayerName(playerid, playername, sizeof(playername));
  264. if(PlayerInfo[playerid][pCarKey] == 0)
  265. {
  266. SendClientMessage(playerid, COLOR_GREY, "You don't own a car.");
  267. return 1;
  268. }
  269. if(PlayerInfo[playerid][pCarKey] != 0 && strcmp(playername, CarInfo[PlayerInfo[playerid][pCarKey]][cOwner], true) == 0)
  270. {
  271. new car = PlayerInfo[playerid][pCarKey];
  272. CarInfo[car][cOwned] = 0;
  273. GetPlayerName(playerid, sendername, sizeof(sendername));
  274. strmid(CarInfo[car][cOwner], "Dealership", 0, strlen("Dealership"), 999);
  275. CallRemoteFunction("GivePlayerTcash","i",playerid,CarInfo[car][cValue]);
  276. PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
  277. format(string, sizeof(string), "You have sold your car for %d Tcash", CarInfo[car][cValue]);
  278. SendClientMessage(playerid, COLOR_GREEN,string);
  279. RemovePlayerFromVehicle(playerid);
  280. TogglePlayerControllable(playerid, 1);
  281. PlayerInfo[playerid][pCarKey] = 999;
  282. return 1;
  283. }
  284. }
  285. return 1;
  286. }
  287. if(strcmp(tmp, "/whereismycar", true) == 0)
  288. {
  289. if(!IsPlayerConnected(playerid)) { return 1; }
  290. if(PlayerInfo[playerid][pCarKey] == 0) { GameTextForPlayer(playerid, "~w~You do not have a car to locate", 2500, 3); return 1; }
  291. if(cartrack[playerid]==0)
  292. {
  293. SendClientMessage(playerid,COLOR_WHITE,"On-Star: This is On-Star's automated vehicle tracking system");
  294. SendClientMessage(playerid,COLOR_WHITE,"On-Star: Please enter your PIN # and password now");
  295. SendClientMessage(playerid,COLOR_WHITE,"On-Star: Your vehicle's location is now uploaded to your phone");
  296. SetPlayerCheckpoint(playerid,CarInfo[PlayerInfo[playerid][pCarKey]][cLocationx], CarInfo[PlayerInfo[playerid][pCarKey]][cLocationy], CarInfo[PlayerInfo[playerid][pCarKey]][cLocationz], 5.0);
  297. cartrack[playerid] = 1;
  298. return 1;
  299. }
  300. else
  301. {
  302. SendClientMessage(playerid,COLOR_WHITE,"On-Star: This is On-Star's automated vehicle tracking system");
  303. SendClientMessage(playerid,COLOR_WHITE,"On-Star: The tracking on your vehicle has been canceled");
  304. DisablePlayerCheckpoint(playerid);
  305. cartrack[playerid] = 0;
  306. return 1;
  307. }
  308. }
  309. if(strcmp(tmp, "/lockmycar 1", true) == 0)
  310. {
  311. new keycar = PlayerInfo[playerid][pCarKey];
  312. if(IsPlayerConnected(playerid))
  313. {
  314. for(new i = 0; i < MAX_PLAYERS; i++)
  315. {
  316. SetVehicleParamsForPlayer(CarInfo[keycar][ownedvehicle],i,0,1);
  317. }
  318. format(string, sizeof(string), "Car locked to public.");
  319. SendClientMessage(playerid, COLOR_GREEN,string);
  320. CarInfo[keycar][cLock] = 1;
  321. return 1;
  322. }
  323. }
  324. if(strcmp(tmp, "/lockmycar 0", true) == 0)
  325. {
  326. new keycar = PlayerInfo[playerid][pCarKey];
  327. if(IsPlayerConnected(playerid))
  328. {
  329. for(new i = 0; i < MAX_PLAYERS; i++)
  330. {
  331. SetVehicleParamsForPlayer(CarInfo[keycar][ownedvehicle],i,0,0);
  332. }
  333. format(string, sizeof(string), "Car unlocked to public.");
  334. SendClientMessage(playerid, COLOR_GREEN,string);
  335. CarInfo[keycar][cLock] = 0;
  336. return 1;
  337. }
  338. }
  339. }
  340. return 0;
  341. }
  342. /*----------Car Save Functions----------*/
  343. public LoadCar()
  344. {
  345. new arrCoords[13][64];
  346. new strFromFile2[256];
  347. new File: file = fopen("[FS]CarOwnership.cfg", io_read);
  348. if (file)
  349. {
  350. new idx = 0;
  351. while (idx < sizeof(CarInfo))
  352. {
  353. fread(file, strFromFile2);
  354. split(strFromFile2, arrCoords, ',');
  355. CarInfo[idx][cModel] = strval(arrCoords[0]);
  356. CarInfo[idx][cLocationx] = floatstr(arrCoords[1]);
  357. CarInfo[idx][cLocationy] = floatstr(arrCoords[2]);
  358. CarInfo[idx][cLocationz] = floatstr(arrCoords[3]);
  359. CarInfo[idx][cAngle] = floatstr(arrCoords[4]);
  360. CarInfo[idx][cColorOne] = strval(arrCoords[5]);
  361. CarInfo[idx][cColorTwo] = strval(arrCoords[6]);
  362. strmid(CarInfo[idx][cOwner], arrCoords[7], 0, strlen(arrCoords[7]), 255);
  363. strmid(CarInfo[idx][cDescription], arrCoords[8], 0, strlen(arrCoords[8]), 255);
  364. CarInfo[idx][cValue] = strval(arrCoords[9]);
  365. CarInfo[idx][cLicense] = strval(arrCoords[10]);
  366. CarInfo[idx][cOwned] = strval(arrCoords[11]);
  367. CarInfo[idx][cLock] = strval(arrCoords[12]);
  368. printf("CarInfo: %d Owner:%s LicensePlate %s",idx,CarInfo[idx][cOwner],CarInfo[idx][cLicense]);
  369. idx++;
  370. }
  371. }
  372. return 1;
  373. }
  374. public SaveCars()
  375. {
  376. new idx;
  377. new File: file2;
  378. while (idx < sizeof(CarInfo))
  379. {
  380. new coordsstring[256];
  381. format(coordsstring, sizeof(coordsstring), "%d,%f,%f,%f,%f,%d,%d,%s,%s,%d,%s,%d,%d\n",
  382. CarInfo[idx][cModel],
  383. CarInfo[idx][cLocationx],
  384. CarInfo[idx][cLocationy],
  385. CarInfo[idx][cLocationz],
  386. CarInfo[idx][cAngle],
  387. CarInfo[idx][cColorOne],
  388. CarInfo[idx][cColorTwo],
  389. CarInfo[idx][cOwner],
  390. CarInfo[idx][cDescription],
  391. CarInfo[idx][cValue],
  392. CarInfo[idx][cLicense],
  393. CarInfo[idx][cOwned],
  394. CarInfo[idx][cLock]);
  395. if(idx == 0)
  396. {
  397. file2 = fopen("[FS]CarOwnership.cfg", io_write);
  398. }
  399. else
  400. {
  401. file2 = fopen("[FS]CarOwnership.cfg", io_append);
  402. }
  403. fwrite(file2, coordsstring);
  404. idx++;
  405. fclose(file2);
  406. }
  407. return 1;
  408. }
  409. public OnPlayerExitVehicle(playerid, vehicleid)
  410. {
  411. if(IsPlayerConnected(playerid))
  412. {
  413. for(new i = 0; i < sizeof(CarInfo); i++)
  414. {
  415. if(vehicleid == CarInfo[i][ownedvehicle])
  416. {
  417. new Float:x,Float:y,Float:z;
  418. new Float:a;
  419. GetVehiclePos(vehicleid, x, y, z);
  420. GetVehicleZAngle(vehicleid, a);
  421. CarInfo[i][cLocationx] = x;
  422. CarInfo[i][cLocationy] = y;
  423. CarInfo[i][cLocationz] = z;
  424. CarInfo[i][cAngle] = a;
  425. }
  426. }
  427. }
  428. return 1;
  429. }
  430. public OnPlayerStateChange(playerid, newstate, oldstate)
  431. {
  432. new vehid = GetPlayerVehicleID(playerid);
  433. if(newstate==2)
  434. {
  435. for(new i = 0; i < sizeof(CarInfo); i++)
  436. {
  437. new newcar = GetPlayerVehicleID(playerid);
  438. new string[256];
  439. if(newcar == CarInfo[i][ownedvehicle])
  440. {
  441. if(CarInfo[i][cOwned]==0)
  442. {
  443. TogglePlayerControllable(playerid, 1);
  444. CarOffered[playerid]=1;
  445. format(string,sizeof(string),"[ ! ] ID: %d ' %s ' Price: %d Tcash",vehid,CarInfo[i][cDescription],CarInfo[i][cValue]);
  446. SendClientMessage(playerid,COLOR_GREY,string);
  447. }
  448. }
  449. if(newstate==2)
  450. {
  451. new keycar = PlayerInfo[playerid][pCarKey];
  452. if(CarInfo[i][cOwned]==1)
  453. CarInfo[keycar][cLock] = 1;
  454. {
  455. TogglePlayerControllable(playerid, 1);
  456. CarOffered[playerid]=0;
  457. format(string,sizeof(string),"[ ! ] ID: %d ' %s ' Bought by: %s",vehid,CarInfo[i][cDescription],CarInfo[i][cOwner]);
  458. SendClientMessage(playerid,COLOR_GREY,string);
  459. }
  460. }
  461. if(newstate==2)
  462. {
  463. new keycar = PlayerInfo[playerid][pCarKey];
  464. if(CarInfo[i][cOwned]==1)
  465. CarInfo[keycar][cLock] = 1;
  466. {
  467. TogglePlayerControllable(playerid, 1);
  468. CarOffered[playerid]=0;
  469. format(string,sizeof(string),"[ ! ] ID: %d ' %s ' Bought by: %s",vehid,CarInfo[i][cDescription],CarInfo[i][cOwner]);
  470. format(string,sizeof(string),"[ ! ] This vehicle is locked by the buyer !");
  471. SendClientMessage(playerid,COLOR_GREY,string);
  472. }
  473. }
  474. }
  475. }
  476. return 1;
  477. }
  478. public OnPlayerEnterCheckpoint(playerid)
  479. {
  480. if(cartrack[playerid]!=0)
  481. {
  482. SendClientMessage(playerid,COLOR_YELLOW,"SMS: On-Star: Our sensors show that you have come within 5.0 metres of your vehicle");
  483. DisablePlayerCheckpoint(playerid);
  484. cartrack[playerid] = 0;
  485. }
  486. return 1;
  487. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement