erewefrfwfrewq

Untitled

Nov 2nd, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.89 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][GarajVirtual] ,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] = 1;
  168. GarageInfo[IDD][Iesirex] = 582.9892; //1
  169. GarageInfo[IDD][Iesirey] = 1675.9623; //2
  170. GarageInfo[IDD][Iesirez] = 6.6259; //3
  171. OnGarage_Update(IDD);
  172. 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][GarajVirtual] ,GarageInfo[IDD][Iesirex], GarageInfo[IDD][Iesirey],GarageInfo[IDD][Iesirez]);
  173. mysql_tquery(MySQLCon, Msg, "","");
  174. format(Msg, sizeof(Msg), "{00FF00}You've succesfully created a garage with ID: {FFFF00}%i", IDD);
  175. SendClientMessage(playerid, -1, Msg);
  176.  
  177. }
  178. }
  179. else
  180. SendClientMessage(playerid, -1, "The maximum amount of garages has been reached");
  181.  
  182. return 1;
  183. }
  184. CMD:enter(playerid, params[])
  185. {
  186.  
  187. new vehicleid = GetPlayerVehicleID(playerid);
  188. new GarageID;
  189. for (GarageID = 1; GarageID < MAX_GARAGES; GarageID++)
  190. {
  191. if (IsValidDynamicPickup(GarageInfo[GarageID][PickupID]))
  192. {
  193. if(IsPlayerInRangeOfPoint(playerid, 1.5, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
  194. //(IsPlayerInRangeOfPoint(playerid, 2.5, GarageInfo[GarageID][Intrarex], GarageInfo[GarageID][Intrarey], GarageInfo[GarageID][Intrarez])
  195. {
  196.  
  197. if (OnGarage_PlayerIsOwner(playerid, GarageID) == 0)
  198. {
  199. SendClientMessage(playerid, -1, "You are not the owner of this garage.");
  200. return 1;
  201. }
  202.  
  203. if(IsPlayerInAnyVehicle(playerid))
  204. {
  205. PlayerGarageID[playerid] = GarageInfo[GarageID][GarajVirtual];
  206. SetVehiclePos(vehicleid, GarageInfo[GarageID][Iesirex], GarageInfo[GarageID][Iesirey], GarageInfo[GarageID][Iesirez]);
  207. SetVehicleVirtualWorld(vehicleid, GarageInfo[GarageID][GarajVirtual]); SetPlayerVirtualWorld(playerid, GarageInfo[GarageID][GarajVirtual]);break;
  208. }
  209. else
  210. {
  211. PlayerGarageID[playerid] = GarageInfo[GarageID][GarajVirtual];
  212. SetPlayerPos(playerid, GarageInfo[GarageID][Iesirex], GarageInfo[GarageID][Iesirey], GarageInfo[GarageID][Iesirez]);
  213. SetPlayerVirtualWorld(playerid, GarageInfo[GarageID][GarajVirtual]);break;
  214. }
  215. }
  216. else
  217. {
  218. if(GarageInfo[GarageID][GarajVirtual] == 0)
  219. {
  220. if(IsPlayerInAnyVehicle(playerid))
  221. {
  222. PlayerGarageID[playerid] = GarageInfo[GarageID][GarajVirtual];
  223. SetVehiclePos(vehicleid, GarageInfo[GarageID][Iesirex], GarageInfo[GarageID][Iesirey], GarageInfo[GarageID][Iesirez]);
  224. SetVehicleVirtualWorld(vehicleid, GarageInfo[GarageID][GarajVirtual]);
  225. SetPlayerVirtualWorld(playerid, GarageInfo[GarageID][GarajVirtual]);
  226. break;
  227. }
  228. else
  229. {
  230. PlayerGarageID[playerid] = GarageInfo[GarageID][GarajVirtual];
  231. SetPlayerPos(playerid, GarageInfo[GarageID][Iesirex], GarageInfo[GarageID][Iesirey], GarageInfo[GarageID][Iesirez]);
  232. SetPlayerVirtualWorld(playerid, GarageInfo[GarageID][GarajVirtual]);
  233. break;
  234. }
  235. }
  236. }
  237. }
  238. }
  239. return 0;
  240. }
  241.  
  242. CMD:exitgarage(playerid,params[])
  243. {
  244. new vehicleid = GetPlayerVehicleID(playerid);
  245. new nume1[MAX_PLAYER_NAME];
  246. GetPlayerName(playerid, nume1, sizeof(nume1));
  247. new GarageID = PlayerGarageID[playerid];
  248. if(PlayerGarageID[playerid] != 0)
  249. //if(IsPlayerInRangeOfPoint(playerid, 2.5, GarageInfo[GarageID][Intrarex], GarageInfo[GarageID][Intrarey], GarageInfo[GarageID][Intrarez])
  250. if(IsPlayerInRangeOfPoint(playerid, 1.5, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
  251. {
  252. if(IsPlayerInAnyVehicle(playerid))
  253. {
  254. SetVehiclePos(vehicleid, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]);
  255.  
  256. SetVehicleVirtualWorld(vehicleid, 0);
  257. SetPlayerVirtualWorld(playerid, 0);
  258. PlayerGarageID[playerid] = 0;
  259. SendClientMessage(playerid, -1 , "You exit the garage.");
  260. }
  261. else
  262. {
  263. SetPlayerPos(playerid, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]);
  264. SetPlayerVirtualWorld(playerid, 0);
  265. PlayerGarageID[playerid] = 0;
  266. SendClientMessage(playerid, -1 , "You exit the garage.");
  267. }
  268. }
  269. else
  270. {
  271. SendClientMessage(playerid, 0xFFFFFFFF, "Trebuie sa fii in fata iesirii unui garaj");
  272. }
  273. return 1;
  274. }
  275. /*
  276. CMD:vindegarage(playerid, params[])
  277. {
  278. new string2[256];
  279.  
  280. new nume1[MAX_PLAYER_NAME];
  281. GetPlayerName(playerid, nume1, sizeof(nume1));
  282. for (new GarageID = 1; GarageID < MAX_GARAGES; GarageID++)
  283. {
  284. if (IsPlayerInRangeOfPoint(playerid, 2.5, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
  285. {
  286. if (GarageInfo[GarageID][Owned] == nume1[playerid])
  287. {
  288. GiveMoney(playerid, GarageInfo[GarageID][Price]);
  289. GarageInfo[GarageID][] = 0;
  290.  
  291. OnGarage_SetOwner(GarageID); GarageInfo[playerid][PlayerGarageID] -= 1; GarageInfo[GarageID][Owned] = 0;
  292. SendClientMessage(playerid, 0xFFFFFFFF, "Ti-ai vandut garajul");
  293. DestroyPickup(PickupID[GarageID]);
  294. GarageInfo[GarageID][PickupID] = CreatePickup(19471, 1, GarageInfo[GarageID][Intrarex], GarageInfo[GarageID][Intrarey], GarageInfo[GarageID][Intrarez], -1);
  295. format(string2, sizeof(string2), " Propietar: %s\nValoare: %d\n Virtual: %d ",GarageInfo[GarageID][Owned], GarageInfo[GarageID][Price],GarageInfo[GarageID][GarajVirtual]);
  296. Update3DTextLabelText(gtextlabel[GarageID], 0xFF4500FF, string2);
  297. break;
  298. }
  299. else
  300. {
  301. SendClientMessage(playerid, 0xFFFFFFFF, "Nu este garajul tau");
  302. break;
  303. }
  304. }
  305. else
  306. {
  307. SendClientMessage(playerid, 0xFFFFFFFF, "Trebuie sa fii in fata unui garaj");
  308. break;
  309. }
  310. }
  311. return 1;
  312. }
  313. */
  314. CMD:vindegarage(playerid, params[])
  315. {
  316. new nume1[MAX_PLAYER_NAME];
  317. GetPlayerName(playerid, nume1, sizeof(nume1));
  318. for (new GarageID = 1; GarageID < MAX_GARAGES; GarageID++)
  319. {
  320. if (IsPlayerInRangeOfPoint(playerid, 2.5, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
  321. {
  322. if (strcmp(GarageInfo[GarageID][Owner], nume1, false) == 0)
  323. {
  324. GiveMoney(playerid, GarageInfo[GarageID][Price]);
  325. //GarageInfo[GarageID][Owned] = 0;
  326.  
  327. //OnGarage_SetOwner(playerid, GarageID);
  328. GarageInfo[playerid][GarageID] = 0;
  329. GarageInfo[GarageID][Owned] = 0;
  330. SendClientMessage(playerid, 0xFFFFFFFF, "Ti-ai vandut garajul");
  331. OnGarage_Update(GarageID);
  332. return 1;
  333. }
  334. else
  335. {
  336. SendClientMessage(playerid, 0xFFFFFFFF, "Nu este garajul tau");
  337. return 1;
  338. }
  339. }
  340. else
  341. {
  342. SendClientMessage(playerid, 0xFFFFFFFF, "Trebuie sa fii in fata unui garaj");
  343. return 1;
  344. }
  345. }
  346. return 1;
  347. }
  348. CMD:buygarage(playerid, params[])
  349. {
  350. if (GetPlayerVehicleSeat(playerid) == -1)
  351. {
  352. for (new GarageID = 1; GarageID < MAX_GARAGES; GarageID++)
  353. {
  354. if (IsValidDynamicPickup(GarageInfo[GarageID][PickupID]))
  355. {
  356. if (IsPlayerInRangeOfPoint(playerid, 2.5, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
  357. {
  358. if (GarageInfo[GarageID][Owned] == 0)
  359. {
  360. if (GetPlayerMoney(playerid) >= GarageInfo[GarageID][Price])
  361. OnGarage_SetOwner(playerid, GarageID);
  362. else
  363. SendClientMessage(playerid, -1, "Nu ai destui bani");
  364. }
  365. else
  366. {
  367. return SendClientMessage(playerid, -1, "Garaju este deja detinut de altcineva.");
  368. }
  369. return 1;
  370. }
  371. }
  372. }
  373. SendClientMessage(playerid, -1, "Ai atins limita de garaje");
  374. }
  375. else
  376. SendClientMessage(playerid, -1, "You can't buy a garage when you're inside a vehicle");
  377. return 1;
  378. }
  379.  
  380. CMD:delgarage(playerid, params[])
  381. {
  382. if(pInfo[playerid][pAdmin] < 5) return SCM(playerid, -1, "Nu poti vedea comenzile de la acest nivel de admin!");
  383. new Msg[148], Name1[24];
  384. if (GetPlayerVehicleSeat(playerid) == -1)
  385. {
  386. for (new GarageID = 1; GarageID < MAX_GARAGES; GarageID++)
  387. {
  388. if (IsValidDynamicPickup(GarageInfo[GarageID][PickupID]))
  389. {
  390. if (IsPlayerInRangeOfPoint(playerid, 2.5, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
  391. {
  392. if (GarageInfo[GarageID][Owned] == 1)
  393. {
  394. for (new pid = 0 , j = GetPlayerPoolSize(); pid <= j; pid++)
  395. {
  396. if (IsPlayerConnected(pid))
  397. {
  398. GetPlayerName(pid, Name1, sizeof(Name1));
  399. if (strcmp(GarageInfo[GarageID][Owner], Name1, false) == 0)
  400. {
  401. SendClientMessage(pid, -1, "Your garage is being deleted.");
  402. }
  403. }
  404. }
  405. }
  406. GarageInfo[GarageID][Owned] = 0;
  407. format(GarageInfo[GarageID][Owned] , MAX_PLAYER_NAME , "None");
  408. GarageInfo[GarageID][eX] = 0.0;
  409. GarageInfo[GarageID][eY] = 0.0;
  410. GarageInfo[GarageID][eZ] = 0.0;
  411. GarageInfo[GarageID][Price] = 0;
  412. GarageInfo[GarageID][GarajVirtual] = 0;
  413. GarageInfo[GarageID][Iesirex] = 0; //1
  414. GarageInfo[GarageID][Iesirey] = 0; //2
  415. GarageInfo[GarageID][Iesirez] = 0; //3
  416. DestroyDynamicPickup(GarageInfo[GarageID][PickupID]);
  417. DestroyDynamicMapIcon(GarageInfo[GarageID][MapiconID]);
  418. DestroyDynamic3DTextLabel(GarageInfo[GarageID][Label]);
  419. GarageInfo[GarageID][PickupID] = 0;
  420. GarageInfo[GarageID][MapiconID] = 0;
  421.  
  422. mysql_format(MySQLCon, Msg, sizeof(Msg), "DELETE FROM `garages` WHERE `IDD` = %i LIMIT 1" , GarageID);
  423. mysql_tquery(MySQLCon, Msg, "","");
  424. format(Msg, 128, "{00FF00}You have deleted the garage with ID: {FFFF00}%i", GarageID);
  425. SendClientMessage(playerid, -1, Msg);
  426. return 1;
  427. }
  428. }
  429. }
  430. SendClientMessage(playerid, -1, "No garage in range to delete");
  431. }
  432. else
  433. SendClientMessage(playerid, -1, "You must be on foot to delete a garage");
  434. return 1;
  435. }
Advertisement
Add Comment
Please, Sign In to add comment