erewefrfwfrewq

Untitled

Oct 30th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.43 KB | None | 0 0
  1. forward OnLoadGarages();
  2. public OnLoadGarages()
  3. {
  4. new Cache: result, ID1, rows,countsuccess, countfailed;
  5. result = mysql_query(MySQLCon,"SELECT * FROM `garages` ORDER BY `ID1` ASC", true);
  6.  
  7. rows = cache_num_rows();
  8. if(rows >= 1)
  9. {
  10. for (new row; row < rows; row++)
  11. {
  12. ID1 = cache_get_field_content_int(row, "ID1");
  13. if ((ID1 < 1) || (ID1 >= MAX_GARAGES))
  14. {
  15. countfailed++;
  16. printf("*** ERROR: Invalid ID found in table \"garages\": %i", ID1);
  17. continue;
  18. }
  19.  
  20. cache_get_field_content(row, "Owner", GarageInfo[ID1][Owner], MAX_PLAYER_NAME);
  21. GarageInfo[ID1][Owned] = cache_get_field_content_int(row, "Owned");
  22. //GarageInfo[ID1][Size] = cache_get_field_content_int(row, "Size");
  23. GarageInfo[ID1][Price] = cache_get_field_content_int(row, "Price");
  24. GarageInfo[ID1][eX] = cache_get_field_content_float(row, "eX");
  25. GarageInfo[ID1][eY] = cache_get_field_content_float(row, "eY");
  26. GarageInfo[ID1][eZ] = cache_get_field_content_float(row, "eZ");
  27. //edit
  28. GarageInfo[ID1][GarajVirtual] = cache_get_field_content_int(row, "GarajVirtual");
  29. GarageInfo[ID1][Iesirex] = cache_get_field_content_float(row, "Iesirex");
  30. GarageInfo[ID1][Iesirey] = cache_get_field_content_float(row, "Iesirey");
  31. GarageInfo[ID1][Iesirez] = cache_get_field_content_float(row, "Iesirez");
  32. OnGarage_Update(ID1);
  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 `ID1` = %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 `ID1` = %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, ID1, tip;
  117. if(GetPlayerVehicleID(playerid) != 0) return SendClientMessage(playerid, -1, "You must be on foot to create a garage.");
  118. for (ID1 = 1; ID1 < MAX_GARAGES; ID1++)
  119. if (!IsValidDynamicPickup(GarageInfo[ID1][PickupID]))
  120. break;
  121. if (ID1 == MAX_GARAGES) return SendClientMessage(playerid, -1, "The maximum amount of garages has been reached.");
  122. if (!IsValidDynamicPickup(GarageInfo[ID1][PickupID]))
  123. {
  124. new Float:x, Float:y, Float:z, Msg[128];
  125. GetPlayerPos(playerid, x, y, z);
  126. //edit
  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[ID1][Owned] = 0;
  141. format(GarageInfo[ID1][Owner], MAX_PLAYER_NAME, "None");
  142. GarageInfo[ID1][eX] = x;
  143. GarageInfo[ID1][eY] = y;
  144. GarageInfo[ID1][eZ] = z;
  145. GarageInfo[ID1][Price] = buyprice;
  146. //GarageInfo[ID1][Size] = size; Size,
  147. GarageInfo[ID1][GarajVirtual] = ID1;
  148. GarageInfo[ID1][Iesirex] = 594.2872; //1
  149. GarageInfo[ID1][Iesirey] = 1674.7228; //2
  150. GarageInfo[ID1][Iesirez] = 6.6259; //3
  151. OnGarage_Update(ID1);
  152. mysql_format(MySQLCon, Msg, sizeof(Msg), "INSERT INTO `garages` (ID1 , eX , eY, eZ , Owner, Price, GarajVirtual, Iesirex, Iesirey, Iesirez) VALUES (%i , %f , %f, %f , '%e', %i , %i, %f , %f, %f)" , ID1, x, y, z , GarageInfo[ID1][Owner], buyprice);
  153. mysql_tquery(MySQLCon, Msg, "","");
  154. format(Msg, sizeof(Msg), "{00FF00}You've succesfully created a garage with ID: {FFFF00}%i", ID1);
  155. SendClientMessage(playerid, -1, Msg);
  156.  
  157.  
  158. }
  159. else if(tip == 2)// mare
  160. {
  161. GarageInfo[ID1][Owned] = 0;
  162. format(GarageInfo[ID1][Owner], MAX_PLAYER_NAME, "None");
  163. GarageInfo[ID1][eX] = x;
  164. GarageInfo[ID1][eY] = y;
  165. GarageInfo[ID1][eZ] = z;
  166. GarageInfo[ID1][Price] = buyprice;
  167. //GarageInfo[ID1][Size] = size;
  168. GarageInfo[ID1][GarajVirtual] = ID1;
  169. GarageInfo[ID1][Iesirex] = 582.9892; //1
  170. GarageInfo[ID1][Iesirey] = 1675.9623; //2
  171. GarageInfo[ID1][Iesirez] = 6.6259; //3
  172. OnGarage_Update(ID1);
  173. mysql_format(MySQLCon, Msg, sizeof(Msg), "INSERT INTO `garages` (ID1 , eX , eY, eZ , Owner, Price, Iesirex, Iesirey, Iesirez) VALUES (%i , %f , %f, %f , '%e', %i , %i)" , ID1, x, y, z , GarageInfo[ID1][Owner], buyprice);
  174. mysql_tquery(MySQLCon, Msg, "","");
  175. format(Msg, sizeof(Msg), "{00FF00}You've succesfully created a garage with ID: {FFFF00}%i", ID1);
  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. if (IsValidDynamicPickup(GarageInfo[GarageID][PickupID]))
  192. {
  193. if(IsPlayerInRangeOfPoint(playerid, 1.5, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
  194. {
  195.  
  196. if (OnGarage_PlayerIsOwner(playerid, GarageID) == 0)
  197. {
  198. SendClientMessage(playerid, -1, "You are not the owner of this garage.");
  199. return 1;
  200. }
  201.  
  202. if(IsPlayerInAnyVehicle(playerid))
  203. {
  204. PlayerGarageID[playerid] = GarageInfo[GarageID][GarajVirtual];
  205. SetVehiclePos(vehicleid, GarageInfo[GarageID][Iesirex], GarageInfo[GarageID][Iesirey], GarageInfo[GarageID][Iesirez]);
  206. SetVehicleVirtualWorld(vehicleid, GarageInfo[GarageID][GarajVirtual]); SetPlayerVirtualWorld(playerid, GarageInfo[GarageID][GarajVirtual]);break;
  207. }
  208. else
  209. {
  210. PlayerGarageID[playerid] = GarageInfo[GarageID][GarajVirtual];
  211. SetPlayerPos(playerid, GarageInfo[GarageID][Iesirex], GarageInfo[GarageID][Iesirey], GarageInfo[GarageID][Iesirez]);
  212. SetPlayerVirtualWorld(playerid, GarageInfo[GarageID][GarajVirtual]);break;
  213. }
  214. }
  215. else
  216. {
  217. if(GarageInfo[GarageID][GarajVirtual] == 0)
  218. {
  219. if(IsPlayerInAnyVehicle(playerid))
  220. {
  221. PlayerGarageID[playerid] = GarageInfo[GarageID][GarajVirtual];
  222. SetVehiclePos(vehicleid, GarageInfo[GarageID][Iesirex], GarageInfo[GarageID][Iesirey], GarageInfo[GarageID][Iesirez]);
  223. SetVehicleVirtualWorld(vehicleid, GarageInfo[GarageID][GarajVirtual]); SetPlayerVirtualWorld(playerid, GarageInfo[GarageID][GarajVirtual]);
  224. break;
  225. }
  226. else
  227. {
  228. PlayerGarageID[playerid] = GarageInfo[GarageID][GarajVirtual];
  229. SetPlayerPos(playerid, GarageInfo[GarageID][Iesirex], GarageInfo[GarageID][Iesirey], GarageInfo[GarageID][Iesirez]);
  230. SetPlayerVirtualWorld(playerid, GarageInfo[GarageID][GarajVirtual]);
  231. break;
  232. }
  233. }
  234. }
  235. }
  236. }
  237.  
  238. return 0;
  239. }
  240.  
  241. CMD:exitgarage(playerid,params[])
  242. {
  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, 1.5, GarageInfo[GarageID][eX] , GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
  250. {
  251. if(IsPlayerInAnyVehicle(playerid))
  252. {
  253. PlayerGarageID[playerid] = 0; SetVehicleVirtualWorld(vehicleid, 0);
  254. SetVehiclePos(vehicleid, GarageInfo[GarageID][Intrarex], GarageInfo[GarageID][Intrarey], GarageInfo[GarageID][Intrarez]); SetPlayerVirtualWorld(playerid, 0);
  255. SendClientMessage(playerid, -1 , "You exit the garage.");
  256. }
  257. else
  258. {
  259. SetPlayerPos(playerid, GarageInfo[GarageID][Intrarex], GarageInfo[GarageID][Intrarey], GarageInfo[GarageID][Intrarez]);
  260. SetPlayerVirtualWorld(playerid, 0); PlayerGarageID[playerid] = 0;
  261. SendClientMessage(playerid, -1 , "You exit the garage.");
  262. }
  263. }
  264. else
  265. {
  266. SendClientMessage(playerid, 0xFFFFFFFF, "Trebuie sa fii in fata iesirii unui garaj");
  267. }
  268. return 1;
  269. }
  270.  
  271. CMD:buygarage(playerid, params[])
  272. {
  273. if (GetPlayerVehicleSeat(playerid) == -1)
  274. {
  275. for (new GarageID = 1; GarageID < MAX_GARAGES; GarageID++)
  276. {
  277. if (IsValidDynamicPickup(GarageInfo[GarageID][PickupID]))
  278. {
  279. if (IsPlayerInRangeOfPoint(playerid, 2.5, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
  280. {
  281. if (GarageInfo[GarageID][Owned] == 0)
  282. {
  283. if (GetPlayerMoney(playerid) >= GarageInfo[GarageID][Price])
  284. OnGarage_SetOwner(playerid, GarageID);
  285. else
  286. SendClientMessage(playerid, -1, "You cannot afford this garage");
  287. }
  288. else
  289. {
  290. new Msg[128];
  291. format(Msg, sizeof(Msg), "This garage is already owned by {FFFF00}%s", GarageInfo[GarageID][Owner]);
  292. SendClientMessage(playerid, -1, Msg);
  293. }
  294. return 1;
  295. }
  296. }
  297. }
  298. SendClientMessage(playerid, -1, "To buy a garage, you have to be near a garage-pickup");
  299. }
  300. else
  301. SendClientMessage(playerid, -1, "You can't buy a garage when you're inside a vehicle");
  302. return 1;
  303. }
  304.  
  305. CMD:delgarage(playerid, params[])
  306. {
  307. if(pInfo[playerid][pAdmin] < 5) return SCM(playerid, -1, "Nu poti vedea comenzile de la acest nivel de admin!");
  308. new Msg[128], Name1[24];
  309. if (GetPlayerVehicleSeat(playerid) == -1)
  310. {
  311. for (new GarageID = 1; GarageID < MAX_GARAGES; GarageID++)
  312. {
  313. if (IsValidDynamicPickup(GarageInfo[GarageID][PickupID]))
  314. {
  315. if (IsPlayerInRangeOfPoint(playerid, 2.5, GarageInfo[GarageID][eX], GarageInfo[GarageID][eY], GarageInfo[GarageID][eZ]))
  316. {
  317. if (GarageInfo[GarageID][Owned] == 1)
  318. {
  319. for (new pid = 0 , j = GetPlayerPoolSize(); pid <= j; pid++)
  320. {
  321. if (IsPlayerConnected(pid))
  322. {
  323. GetPlayerName(pid, Name1, sizeof(Name1));
  324. if (strcmp(GarageInfo[GarageID][Owner], Name1, false) == 0)
  325. {
  326. SendClientMessage(pid, -1, "Your garage is being deleted.");
  327. }
  328. }
  329. }
  330. }
  331. GarageInfo[GarageID][Owned] = 0;
  332. format(GarageInfo[GarageID][Owned] , MAX_PLAYER_NAME , "None");
  333. GarageInfo[GarageID][eX] = 0.0;
  334. GarageInfo[GarageID][eY] = 0.0;
  335. GarageInfo[GarageID][eZ] = 0.0;
  336. GarageInfo[GarageID][Price] = 0;
  337. GarageInfo[GarageID][Size] = 0;
  338. GarajInfo[GarageID][GarajVirtual] = 0;
  339. GarajInfo[GarageID][Iesirex] = 0; //1
  340. GarajInfo[GarageID][Iesirey] = 0; //2
  341. GarajInfo[GarageID][Iesirez] = 0; //3
  342. DestroyDynamicPickup(GarageInfo[GarageID][PickupID]);
  343. DestroyDynamicMapIcon(GarageInfo[GarageID][MapiconID]);
  344. DestroyDynamic3DTextLabel(GarageInfo[GarageID][Label]);
  345. GarageInfo[GarageID][PickupID] = 0;
  346. GarageInfo[GarageID][MapiconID] = 0;
  347.  
  348. mysql_format(MySQLCon, Msg, sizeof(Msg), "DELETE FROM `garages` WHERE `ID1` = %i LIMIT 1" , GarageID);
  349. mysql_tquery(MySQLCon, Msg, "","");
  350. format(Msg, 128, "{00FF00}You have deleted the garage with ID: {FFFF00}%i", GarageID);
  351. SendClientMessage(playerid, -1, Msg);
  352. return 1;
  353. }
  354. }
  355. }
  356. SendClientMessage(playerid, -1, "No garage in range to delete");
  357. }
  358. else
  359. SendClientMessage(playerid, -1, "You must be on foot to delete a garage");
  360. return 1;
  361. }
Advertisement
Add Comment
Please, Sign In to add comment