erewefrfwfrewq

Untitled

Oct 31st, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.88 KB | None | 0 0
  1. forward OnLoadGarages();
  2. public OnLoadGarages()
  3. {
  4. new Cache: result, IDD, rows,countsuccess, countfailed;
  5. result = mysql_query(MySQLCon,"SELECT * FROM `garages` ORDER BY `IDD` ASC", true);
  6.  
  7. rows = cache_num_rows();
  8. if(rows >= 1)
  9. {
  10. for (new row; row < rows; row++)
  11. {
  12. IDD = cache_get_field_content_int(row, "IDD");
  13. if ((IDD < 1) || (IDD >= MAX_GARAGES))
  14. {
  15. countfailed++;
  16. printf("*** ERROR: Invalid ID found in table \"garages\": %i", IDD);
  17. continue;
  18. }
  19.  
  20. cache_get_field_content(row, "Owner", GarageInfo[IDD][Owner], MAX_PLAYER_NAME);
  21. GarageInfo[IDD][Owned] = cache_get_field_content_int(row, "Owned");
  22. //GarageInfo[IDD][Size] = cache_get_field_content_int(row, "Size");
  23. GarageInfo[IDD][Price] = cache_get_field_content_int(row, "Price");
  24. GarageInfo[IDD][eX] = cache_get_field_content_float(row, "eX");
  25. GarageInfo[IDD][eY] = cache_get_field_content_float(row, "eY");
  26. GarageInfo[IDD][eZ] = cache_get_field_content_float(row, "eZ");
  27. //edit by Andu
  28. GarageInfo[IDD][GarajVirtual] = cache_get_field_content_int(row, "GarajVirtual");
  29. GarageInfo[IDD][Iesirex] = cache_get_field_content_float(row, "Iesirex");
  30. GarageInfo[IDD][Iesirey] = cache_get_field_content_float(row, "Iesirey");
  31. GarageInfo[IDD][Iesirez] = cache_get_field_content_float(row, "Iesirez");
  32. OnGarage_Update(IDD);
  33. countsuccess++;
  34.  
  35. }
  36. }
  37. printf("*** >>> Garages loaded: %i (successful: %i, failed: %i)", rows, countsuccess, countfailed);
  38. printf("");
  39. cache_delete(result);
  40. }
  41. forward OnGarage_Update(GarageID);
  42. public OnGarage_Update(GarageID)
  43. {
  44. new Msg[64], Float:x, Float:y, Float:z;
  45. x = GarageInfo[GarageID][eX];
  46. y = GarageInfo[GarageID][eY];
  47. z = GarageInfo[GarageID][eZ];
  48. if (IsValidDynamicPickup(GarageInfo[GarageID][PickupID]))
  49. DestroyDynamicPickup(GarageInfo[GarageID][PickupID]);
  50. if (IsValidDynamicMapIcon(GarageInfo[GarageID][MapiconID]))
  51. DestroyDynamicMapIcon(GarageInfo[GarageID][MapiconID]);
  52. if (IsValidDynamic3DTextLabel(GarageInfo[GarageID][Label]))
  53. DestroyDynamic3DTextLabel(GarageInfo[GarageID][Label]);
  54. if (GarageInfo[GarageID][Owned] == 1)
  55. {
  56. GarageInfo[GarageID][PickupID] = CreateDynamicPickup(1272, 1, x, y, z, 0);
  57. format(Msg, sizeof(Msg), "ID: %i\nOwned by: %s\n/enter", GarageID, GarageInfo[GarageID][Owner]);
  58. GarageInfo[GarageID][Label] = CreateDynamic3DTextLabel(Msg, 0x008080FF, x, y, z + 1.0, 50.0);
  59. }
  60. else
  61. {
  62. GarageInfo[GarageID][PickupID] = CreateDynamicPickup(1273, 1, x, y, z, 0);
  63. format(Msg, sizeof(Msg), "Garage available for\n$%i\n/buygarage", GarageInfo[GarageID][Price]);
  64. GarageInfo[GarageID][Label] = CreateDynamic3DTextLabel(Msg, 0x008080FF, x, y, z + 1.0, 50.0);
  65. // Add a streamed icon to the map (green garage), type = 31, color = 0, world = 0, interior = 0, playerid = -1, drawdist = 150.0
  66. GarageInfo[GarageID][MapiconID] = CreateDynamicMapIcon(x, y, z, 31, 0, 0, 0, -1, 150.0);
  67. }
  68. }
  69.  
  70. forward OnGarage_SetOwner(playerid, GarageID);
  71. public OnGarage_SetOwner(playerid, GarageID)
  72. {
  73. if(GarageInfo[GarageID][Owner] == 1)
  74. {
  75. new Name1[MAX_PLAYER_NAME], Msg[128];
  76. GetPlayerName(playerid, Name1, sizeof(Name1));
  77. GarageInfo[GarageID][Owned] = 1;
  78. format(GarageInfo[GarageID][Owner], sizeof(Name1), Name1);
  79. GiveMoney(playerid, -GarageInfo[GarageID][Price]);
  80. OnGarage_Update(GarageID);
  81.  
  82. mysql_format(MySQLCon, Msg, sizeof(Msg), "UPDATE `garages` SET `Owner` = '%e' , `Owned` = 1 WHERE `IDD` = %i" , GarageInfo[GarageID][Owner] , GarageID);
  83. mysql_tquery(MySQLCon, Msg, "","");
  84. format(Msg, sizeof(Msg), "You've bought the garage for $%i", GarageInfo[GarageID][Price]);
  85. SendClientMessage(playerid, -1, Msg);
  86. }
  87. else if(GarageInfo[GarageID][Owner] == 0)
  88. {
  89. new Name1[MAX_PLAYER_NAME], Msg[128];
  90. GetPlayerName(playerid, Name1, sizeof(Name1));
  91. GarageInfo[GarageID][Owned] = 1;
  92. format(GarageInfo[GarageID][Owner], sizeof(Name1), Name1);
  93. GiveMoney(playerid, -GarageInfo[GarageID][Price]);
  94. OnGarage_Update(GarageID);
  95.  
  96. mysql_format(MySQLCon, Msg, sizeof(Msg), "UPDATE `garages` SET `Owner` = '%e' , `Owned` = 1 WHERE `ID` = %i" , GarageInfo[GarageID][Owner] , GarageID);
  97. mysql_tquery(MySQLCon, Msg, "","");
  98. format(Msg, sizeof(Msg), "You've bought the garage for $%i", GarageInfo[GarageID][Price]);
  99. SendClientMessage(playerid, -1, Msg);
  100. }
  101. return 1;
  102. }
  103. forward OnGarage_PlayerIsOwner(playerid, GarageID);
  104. public OnGarage_PlayerIsOwner(playerid, GarageID)// This function returns "1" if the given player is the owner of the given garage
  105.  
  106. {
  107. new Name1[MAX_PLAYER_NAME];
  108. GetPlayerName(playerid, Name1 , MAX_PLAYER_NAME);
  109. if(strcmp(GarageInfo[GarageID][Owner], Name1, false) == 0)
  110. return 1;
  111. return 0;
  112. }
  113. CMD:creategarage(playerid,params[])
  114. {
  115. if(pInfo[playerid][pAdmin] < 5) return SCM(playerid, -1, "Nu poti vedea comenzile de la acest nivel de admin!");
  116. new buyprice, IDD, tip;
  117. if(GetPlayerVehicleID(playerid) != 0) return SendClientMessage(playerid, -1, "You must be on foot to create a garage.");
  118. for (IDD = 1; IDD < MAX_GARAGES; IDD++)
  119. if (!IsValidDynamicPickup(GarageInfo[IDD][PickupID]))
  120. break;
  121. if (IDD == MAX_GARAGES) return SendClientMessage(playerid, -1, "The maximum amount of garages has been reached.");
  122. if (!IsValidDynamicPickup(GarageInfo[IDD][PickupID]))
  123. {
  124. new Float:x, Float:y, Float:z, Msg[259];
  125. GetPlayerPos(playerid, x, y, z);
  126. //edit By Andu
  127.  
  128. if(unformat(params, "ii", tip, buyprice))
  129. {
  130. SendClientMessage(playerid, 0xFF0000AA, "Foloseste: /creategaraj <modelid> <pret>");
  131. return 1;
  132. }
  133. if(!(tip == 1 || tip == 2))
  134. {
  135. SendClientMessage(playerid, 0xFF0000AA, "Model-ul pot fi de la 1 la 2");
  136. return 1;
  137. }
  138. if(tip == 1)
  139. {
  140. GarageInfo[IDD][Owned] = 0;
  141. format(GarageInfo[IDD][Owner], MAX_PLAYER_NAME, "None");
  142. GarageInfo[IDD][eX] = x;
  143. GarageInfo[IDD][eY] = y;
  144. GarageInfo[IDD][eZ] = z;
  145. GarageInfo[IDD][Price] = buyprice;
  146. GarageInfo[IDD][GarajVirtual] = IDD;
  147. GarageInfo[IDD][Iesirex] = 594.2872; //1
  148. GarageInfo[IDD][Iesirey] = 1674.7228; //2
  149. GarageInfo[IDD][Iesirez] = 6.6259; //3
  150. //GarageInfo[IDD][Size] = size;
  151. OnGarage_Update(IDD);
  152. mysql_format(MySQLCon, Msg, sizeof(Msg), "INSERT INTO `garages` (IDD , eX , eY, eZ , Owner, Price, GarajVirtual, Iesirex, Iesirey, Iesirez) VALUES (%i , %f , %f, %f , '%e', %i , %i, %f , %f, %f)" , IDD, x, y, z , GarageInfo[IDD][Owner], buyprice, GarageInfo[IDD][Iesirex], GarageInfo[IDD][Iesirey],GarageInfo[IDD][Iesirez]);
  153. mysql_tquery(MySQLCon, Msg, "","");
  154. format(Msg, sizeof(Msg), "{00FF00}You've succesfully created a garage with ID: {FFFF00}%i", IDD);
  155. SendClientMessage(playerid, -1, Msg);
  156.  
  157.  
  158. }
  159. else if(tip == 2)// mare
  160. {
  161. GarageInfo[IDD][Owned] = 0;
  162. format(GarageInfo[IDD][Owner], MAX_PLAYER_NAME, "None");
  163. GarageInfo[IDD][eX] = x;
  164. GarageInfo[IDD][eY] = y;
  165. GarageInfo[IDD][eZ] = z;
  166. GarageInfo[IDD][Price] = buyprice;
  167. GarageInfo[IDD][GarajVirtual] = IDD;
  168. GarageInfo[IDD][Iesirex] = 582.9892; //1
  169. GarageInfo[IDD][Iesirey] = 1675.9623; //2
  170. GarageInfo[IDD][Iesirez] = 6.6259; //3
  171. //GarageInfo[IDD][Size] = size;
  172. OnGarage_Update(IDD);
  173. mysql_format(MySQLCon, Msg, sizeof(Msg), "INSERT INTO `garages` (IDD , eX , eY, eZ , Owner, Price, GarajVirtual, Iesirex, Iesirey, Iesirez) VALUES (%i , %f , %f, %f , '%e', %i , %i, %f , %f, %f)" , IDD, x, y, z , GarageInfo[IDD][Owner], buyprice, GarageInfo[IDD][Iesirex], GarageInfo[IDD][Iesirey],GarageInfo[IDD][Iesirez]);
  174. mysql_tquery(MySQLCon, Msg, "","");
  175. format(Msg, sizeof(Msg), "{00FF00}You've succesfully created a garage with ID: {FFFF00}%i", IDD);
  176. SendClientMessage(playerid, -1, Msg);
  177.  
  178. }
  179. }
  180. else
  181. SendClientMessage(playerid, -1, "The maximum amount of garages has been reached");
  182.  
  183. return 1;
  184. }
  185. CMD:enter(playerid, params[])
  186. {
  187.  
  188. new vehicleid = GetPlayerVehicleID(playerid);
  189. new GarageID;
  190. for (GarageID = 1; GarageID < MAX_GARAGES; GarageID++)
  191. {
  192. if (IsValidDynamicPickup(GarageInfo[GarageID][PickupID]))
  193. {
  194. if(IsPlayerInRangeOfPoint(playerid, 1.5, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
  195. //(IsPlayerInRangeOfPoint(playerid, 2.5, GarageInfo[GarageID][Intrarex], GarageInfo[GarageID][Intrarey], GarageInfo[GarageID][Intrarez])
  196. {
  197.  
  198. if (OnGarage_PlayerIsOwner(playerid, GarageID) == 0)
  199. {
  200. SendClientMessage(playerid, -1, "You are not the owner of this garage.");
  201. return 1;
  202. }
  203.  
  204. if(IsPlayerInAnyVehicle(playerid))
  205. {
  206. PlayerGarageID[playerid] = GarageInfo[GarageID][GarajVirtual];
  207. SetVehiclePos(vehicleid, GarageInfo[GarageID][Iesirex], GarageInfo[GarageID][Iesirey], GarageInfo[GarageID][Iesirez]);
  208. SetVehicleVirtualWorld(vehicleid, GarageInfo[GarageID][GarajVirtual]); SetPlayerVirtualWorld(playerid, GarageInfo[GarageID][GarajVirtual]);break;
  209. }
  210. else
  211. {
  212. PlayerGarageID[playerid] = GarageInfo[GarageID][GarajVirtual];
  213. SetPlayerPos(playerid, GarageInfo[GarageID][Iesirex], GarageInfo[GarageID][Iesirey], GarageInfo[GarageID][Iesirez]);
  214. SetPlayerVirtualWorld(playerid, GarageInfo[GarageID][GarajVirtual]);break;
  215. }
  216. }
  217. else
  218. {
  219. if(GarageInfo[GarageID][GarajVirtual] == 0)
  220. {
  221. if(IsPlayerInAnyVehicle(playerid))
  222. {
  223. PlayerGarageID[playerid] = GarageInfo[GarageID][GarajVirtual];
  224. SetVehiclePos(vehicleid, GarageInfo[GarageID][Iesirex], GarageInfo[GarageID][Iesirey], GarageInfo[GarageID][Iesirez]);
  225. SetVehicleVirtualWorld(vehicleid, GarageInfo[GarageID][GarajVirtual]);
  226. SetPlayerVirtualWorld(playerid, GarageInfo[GarageID][GarajVirtual]);
  227. break;
  228. }
  229. else
  230. {
  231. PlayerGarageID[playerid] = GarageInfo[GarageID][GarajVirtual];
  232. SetPlayerPos(playerid, GarageInfo[GarageID][Iesirex], GarageInfo[GarageID][Iesirey], GarageInfo[GarageID][Iesirez]);
  233. SetPlayerVirtualWorld(playerid, GarageInfo[GarageID][GarajVirtual]);
  234. break;
  235. }
  236. }
  237. }
  238. }
  239. }
  240. return 0;
  241. }
  242.  
  243. CMD:exitgarage(playerid,params[])
  244. {
  245. new vehicleid = GetPlayerVehicleID(playerid);
  246. new nume1[MAX_PLAYER_NAME];
  247. GetPlayerName(playerid, nume1, sizeof(nume1));
  248. new GarageID = PlayerGarageID[playerid];
  249. if(PlayerGarageID[playerid] != 0)
  250. //if(IsPlayerInRangeOfPoint(playerid, 2.5, GarageInfo[GarageID][Intrarex], GarageInfo[GarageID][Intrarey], GarageInfo[GarageID][Intrarez])
  251. if(IsPlayerInRangeOfPoint(playerid, 1.5, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
  252. {
  253. if(IsPlayerInAnyVehicle(playerid))
  254. {
  255. SetVehiclePos(vehicleid, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]);
  256.  
  257. SetVehicleVirtualWorld(vehicleid, 0);
  258. SetPlayerVirtualWorld(playerid, 0);
  259. PlayerGarageID[playerid] = 0;
  260. SendClientMessage(playerid, -1 , "You exit the garage.");
  261. }
  262. else
  263. {
  264. SetPlayerPos(playerid, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]);
  265. SetPlayerVirtualWorld(playerid, 0);
  266. PlayerGarageID[playerid] = 0;
  267. SendClientMessage(playerid, -1 , "You exit the garage.");
  268. }
  269. }
  270. else
  271. {
  272. SendClientMessage(playerid, 0xFFFFFFFF, "Trebuie sa fii in fata iesirii unui garaj");
  273. }
  274. return 1;
  275. }
  276. /*
  277. CMD:vindegarage(playerid, params[])
  278. {
  279. new string2[256];
  280.  
  281. new nume1[MAX_PLAYER_NAME];
  282. GetPlayerName(playerid, nume1, sizeof(nume1));
  283. for (new GarageID = 1; GarageID < MAX_GARAGES; GarageID++)
  284. {
  285. if (IsPlayerInRangeOfPoint(playerid, 2.5, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
  286. {
  287. if (GarageInfo[GarageID][Owned] == nume1[playerid])
  288. {
  289. GiveMoney(playerid, GarageInfo[GarageID][Price]);
  290. GarageInfo[GarageID][] = 0;
  291.  
  292. OnGarage_SetOwner(GarageID); GarageInfo[playerid][PlayerGarageID] -= 1; GarageInfo[GarageID][Owned] = 0;
  293. SendClientMessage(playerid, 0xFFFFFFFF, "Ti-ai vandut garajul");
  294. DestroyPickup(PickupID[GarageID]);
  295. GarageInfo[GarageID][PickupID] = CreatePickup(19471, 1, GarageInfo[GarageID][Intrarex], GarageInfo[GarageID][Intrarey], GarageInfo[GarageID][Intrarez], -1);
  296. format(string2, sizeof(string2), " Propietar: %s\nValoare: %d\n Virtual: %d ",GarageInfo[GarageID][Owned], GarageInfo[GarageID][Price],GarageInfo[GarageID][GarajVirtual]);
  297. Update3DTextLabelText(gtextlabel[GarageID], 0xFF4500FF, string2);
  298. break;
  299. }
  300. else
  301. {
  302. SendClientMessage(playerid, 0xFFFFFFFF, "Nu este garajul tau");
  303. break;
  304. }
  305. }
  306. else
  307. {
  308. SendClientMessage(playerid, 0xFFFFFFFF, "Trebuie sa fii in fata unui garaj");
  309. break;
  310. }
  311. }
  312. return 1;
  313. }
  314. */
  315. CMD:vindegarage(playerid, params[])
  316. {
  317. new nume1[MAX_PLAYER_NAME];
  318. GetPlayerName(playerid, nume1, sizeof(nume1));
  319. for (new GarageID = 1; GarageID < MAX_GARAGES; GarageID++)
  320. {
  321. if (IsPlayerInRangeOfPoint(playerid, 2.5, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
  322. {
  323. if (strcmp(GarageInfo[GarageID][Owner], nume1, false) == 0)
  324. {
  325. GiveMoney(playerid, GarageInfo[GarageID][Price]);
  326. //GarageInfo[GarageID][Owned] = 0;
  327.  
  328. OnGarage_SetOwner(GarageID);
  329. GarageInfo[playerid][GarageID] = 0;
  330. GarageInfo[GarageID][Owned] = 0;
  331. SendClientMessage(playerid, 0xFFFFFFFF, "Ti-ai vandut garajul");
  332. OnGarage_Update(GarageID);
  333. return 1;
  334. }
  335. else
  336. {
  337. SendClientMessage(playerid, 0xFFFFFFFF, "Nu este garajul tau");
  338. return 1;
  339. }
  340. }
  341. else
  342. {
  343. SendClientMessage(playerid, 0xFFFFFFFF, "Trebuie sa fii in fata unui garaj");
  344. return 1;
  345. }
  346. }
  347. return 1;
  348. }
  349. CMD:buygarage(playerid, params[])
  350. {
  351. if (GetPlayerVehicleSeat(playerid) == -1)
  352. {
  353. for (new GarageID = 1; GarageID < MAX_GARAGES; GarageID++)
  354. {
  355. if (IsValidDynamicPickup(GarageInfo[GarageID][PickupID]))
  356. {
  357. if (IsPlayerInRangeOfPoint(playerid, 2.5, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
  358. {
  359. if (GarageInfo[GarageID][Owned] == 0)
  360. {
  361. if (GetPlayerMoney(playerid) >= GarageInfo[GarageID][Price])
  362. OnGarage_SetOwner(playerid, GarageID);
  363. else
  364. SendClientMessage(playerid, -1, "Nu ai destui bani");
  365. }
  366. else
  367. {
  368. return SendClientMessage(playerid, -1, "Garaju este deja detinut de altcineva.");
  369. }
  370. return 1;
  371. }
  372. }
  373. }
  374. SendClientMessage(playerid, -1, "Ai atins limita de garaje");
  375. }
  376. else
  377. SendClientMessage(playerid, -1, "You can't buy a garage when you're inside a vehicle");
  378. return 1;
  379. }
  380.  
  381. CMD:delgarage(playerid, params[])
  382. {
  383. if(pInfo[playerid][pAdmin] < 5) return SCM(playerid, -1, "Nu poti vedea comenzile de la acest nivel de admin!");
  384. new Msg[148], Name1[24];
  385. if (GetPlayerVehicleSeat(playerid) == -1)
  386. {
  387. for (new GarageID = 1; GarageID < MAX_GARAGES; GarageID++)
  388. {
  389. if (IsValidDynamicPickup(GarageInfo[GarageID][PickupID]))
  390. {
  391. if (IsPlayerInRangeOfPoint(playerid, 2.5, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
  392. {
  393. if (GarageInfo[GarageID][Owned] == 1)
  394. {
  395. for (new pid = 0 , j = GetPlayerPoolSize(); pid <= j; pid++)
  396. {
  397. if (IsPlayerConnected(pid))
  398. {
  399. GetPlayerName(pid, Name1, sizeof(Name1));
  400. if (strcmp(GarageInfo[GarageID][Owner], Name1, false) == 0)
  401. {
  402. SendClientMessage(pid, -1, "Your garage is being deleted.");
  403. }
  404. }
  405. }
  406. }
  407. GarageInfo[GarageID][Owned] = 0;
  408. format(GarageInfo[GarageID][Owned] , MAX_PLAYER_NAME , "None");
  409. GarageInfo[GarageID][eX] = 0.0;
  410. GarageInfo[GarageID][eY] = 0.0;
  411. GarageInfo[GarageID][eZ] = 0.0;
  412. GarageInfo[GarageID][Price] = 0;
  413. GarageInfo[GarageID][GarajVirtual] = 0;
  414. GarageInfo[GarageID][Iesirex] = 0; //1
  415. GarageInfo[GarageID][Iesirey] = 0; //2
  416. GarageInfo[GarageID][Iesirez] = 0; //3
  417. DestroyDynamicPickup(GarageInfo[GarageID][PickupID]);
  418. DestroyDynamicMapIcon(GarageInfo[GarageID][MapiconID]);
  419. DestroyDynamic3DTextLabel(GarageInfo[GarageID][Label]);
  420. GarageInfo[GarageID][PickupID] = 0;
  421. GarageInfo[GarageID][MapiconID] = 0;
  422.  
  423. mysql_format(MySQLCon, Msg, sizeof(Msg), "DELETE FROM `garages` WHERE `IDD` = %i LIMIT 1" , GarageID);
  424. mysql_tquery(MySQLCon, Msg, "","");
  425. format(Msg, 128, "{00FF00}You have deleted the garage with ID: {FFFF00}%i", GarageID);
  426. SendClientMessage(playerid, -1, Msg);
  427. return 1;
  428. }
  429. }
  430. }
  431. SendClientMessage(playerid, -1, "No garage in range to delete");
  432. }
  433. else
  434. SendClientMessage(playerid, -1, "You must be on foot to delete a garage");
  435. return 1;
  436. }
Advertisement
Add Comment
Please, Sign In to add comment