Advertisement
Guest User

Yet Another Drug System

a guest
Jun 16th, 2016
2,839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.23 KB | None | 0 0
  1. #define FILTERSCRIPT
  2. #include <a_samp>
  3. #include <izcmd> // by Yashas - http://forum.sa-mp.com/showthread.php?t=576114
  4. #include <sqlitei> // by Slice - http://forum.sa-mp.com/showthread.php?t=303682
  5. #include <sscanf2> // by Y_Less - http://forum.sa-mp.com/showthread.php?t=602923
  6. #include <streamer> // by Incognito - http://forum.sa-mp.com/showthread.php?t=102865
  7. #include <YSI\y_iterate> // by Y_Less - http://forum.sa-mp.com/showthread.php?t=570884
  8.  
  9. #define MAX_PLANTS (250) // limit of drug plants
  10. #define MAX_DEALERS (15) // limit of drug dealers
  11.  
  12. #define USE_DRUNKLEVEL // remove this line if you don't want SetPlayerDrunkLevel to be used while on drugs
  13. #define PLAYER_LIMIT (5) // a player can plant up to x drug plants (Default: 5)
  14. #define PLANT_MAX_GROWTH (75) // a plant will grow up to x grams of drugs (Default: 75)
  15. #define GROWTH_INTERVAL (45) // a plant will grow up every x seconds (Default: 45)
  16. #define ROT_INTERVAL (300) // a plant will rot after x seconds of fully growing (Default: 300)
  17. #define CARRY_LIMIT (150) // a player can carry up to x grams of drugs (Default: 150)
  18. #define SEED_LIMIT (25) // a player can carry up to x drug plant seeds (Default: 25)
  19. #define SEED_PRICE (50) // price players will pay for a drug plant seed (Default: 50)
  20. #define DRUG_BUY_PRICE (20) // price players will pay a dealer for a gram of drugs (Default: 20)
  21. #define DRUG_SELL_PRICE (16) // price dealers will pay a player for a gram of drugs (Default: 16)
  22. #define OFFER_COOLDOWN (30) // how many seconds does a player wait to send an another offer to someone (Default: 30)
  23.  
  24. enum _:E_DIALOG
  25. {
  26. DIALOG_DRUG_STATS = 8620,
  27. DIALOG_CONFIRM_RESET,
  28. DIALOG_DRUG_DEALER,
  29. DIALOG_DRUG_DEALER_BUY_SEEDS,
  30. DIALOG_DRUG_DEALER_BUY_DRUGS,
  31. DIALOG_DRUG_DEALER_SELL,
  32. DIALOG_DRUG_OFFER
  33. }
  34.  
  35. enum E_PLANT
  36. {
  37. plantedBy[MAX_PLAYER_NAME],
  38. Float: plantX,
  39. Float: plantY,
  40. Float: plantZ,
  41. plantGrowth,
  42. plantObj,
  43. plantTimer,
  44. Text3D: plantLabel,
  45. bool: gotLeaves
  46. }
  47.  
  48. enum E_PLAYER
  49. {
  50. // saved
  51. Drugs,
  52. Seeds,
  53. TotalUsed,
  54. TotalPlanted,
  55. TotalHarvestedPlants,
  56. TotalHarvestedGrams,
  57. TotalGiven,
  58. TotalReceived,
  59. TotalBought,
  60. TotalBoughtPrice,
  61. TotalSold,
  62. TotalSoldPrice,
  63. // temp
  64. DrugsCooldown,
  65. DealerID,
  66. DrugsOfferedBy,
  67. DrugsOfferedPrice,
  68. DrugsOfferCooldown
  69. }
  70.  
  71. enum E_DEALER
  72. {
  73. // loaded from db
  74. dealerSkin,
  75. dealerDrugs,
  76. Float: dealerX,
  77. Float: dealerY,
  78. Float: dealerZ,
  79. Float: dealerA,
  80. // temp
  81. dealerActorID,
  82. Text3D: dealerLabel
  83. }
  84.  
  85. new
  86. PlantData[MAX_PLANTS][E_PLANT],
  87. Iterator: Plants<MAX_PLANTS>;
  88.  
  89. new
  90. PlayerDrugData[MAX_PLAYERS][E_PLAYER],
  91. RegenTimer[MAX_PLAYERS] = {-1, ...},
  92. EffectTimer[MAX_PLAYERS] = {-1, ...};
  93.  
  94. new
  95. DealerData[MAX_DEALERS][E_DEALER],
  96. Iterator: Dealers<MAX_DEALERS>;
  97.  
  98. new
  99. DB: DrugDB;
  100.  
  101. new
  102. DBStatement: LoadPlayer,
  103. DBStatement: InsertPlayer,
  104. DBStatement: SavePlayer;
  105.  
  106. new
  107. DBStatement: LoadDealers,
  108. DBStatement: AddDealer,
  109. DBStatement: UpdateDealer,
  110. DBStatement: UpdateDealerDrugs,
  111. DBStatement: RemoveDealer;
  112.  
  113. RandomEx(min, max) //Y_Less
  114. return random(max - min) + min;
  115.  
  116. formatInt(intVariable, iThousandSeparator = ',', iCurrencyChar = '$')
  117. {
  118. /*
  119. By Kar
  120. https://gist.github.com/Kar2k/bfb0eafb2caf71a1237b349684e091b9/8849dad7baa863afb1048f40badd103567c005a5#file-formatint-function
  121. */
  122. static
  123. s_szReturn[ 32 ],
  124. s_szThousandSeparator[ 2 ] = { ' ', EOS },
  125. s_szCurrencyChar[ 2 ] = { ' ', EOS },
  126. s_iVariableLen,
  127. s_iChar,
  128. s_iSepPos,
  129. bool:s_isNegative
  130. ;
  131.  
  132. format( s_szReturn, sizeof( s_szReturn ), "%d", intVariable );
  133.  
  134. if(s_szReturn[0] == '-')
  135. s_isNegative = true;
  136. else
  137. s_isNegative = false;
  138.  
  139. s_iVariableLen = strlen( s_szReturn );
  140.  
  141. if ( s_iVariableLen >= 4 && iThousandSeparator)
  142. {
  143. s_szThousandSeparator[ 0 ] = iThousandSeparator;
  144.  
  145. s_iChar = s_iVariableLen;
  146. s_iSepPos = 0;
  147.  
  148. while ( --s_iChar > _:s_isNegative )
  149. {
  150. if ( ++s_iSepPos == 3 )
  151. {
  152. strins( s_szReturn, s_szThousandSeparator, s_iChar );
  153.  
  154. s_iSepPos = 0;
  155. }
  156. }
  157. }
  158. if(iCurrencyChar) {
  159. s_szCurrencyChar[ 0 ] = iCurrencyChar;
  160. strins( s_szReturn, s_szCurrencyChar, _:s_isNegative );
  161. }
  162. return s_szReturn;
  163. }
  164.  
  165. Float: DistanceBetweenPlayers(player1, player2)
  166. {
  167. new Float: x, Float: y, Float: z;
  168. GetPlayerPos(player2, x, y, z);
  169. return GetPlayerDistanceFromPoint(player1, x, y, z);
  170. }
  171.  
  172. GetClosestPlant(playerid, Float: range = 1.5)
  173. {
  174. new id = -1, Float: dist = range, Float: tempdist;
  175. foreach(new i : Plants)
  176. {
  177. tempdist = GetPlayerDistanceFromPoint(playerid, PlantData[i][plantX], PlantData[i][plantY], PlantData[i][plantZ]);
  178.  
  179. if(tempdist > range) continue;
  180. if(tempdist <= dist)
  181. {
  182. dist = tempdist;
  183. id = i;
  184. }
  185. }
  186.  
  187. return id;
  188. }
  189.  
  190. GetClosestDealer(playerid, Float: range = 2.0)
  191. {
  192. new id = -1, Float: dist = range, Float: tempdist;
  193. foreach(new i : Dealers)
  194. {
  195. tempdist = GetPlayerDistanceFromPoint(playerid, DealerData[i][dealerX], DealerData[i][dealerY], DealerData[i][dealerZ]);
  196.  
  197. if(tempdist > range) continue;
  198. if(tempdist <= dist)
  199. {
  200. dist = tempdist;
  201. id = i;
  202. }
  203. }
  204.  
  205. return id;
  206. }
  207.  
  208. ShowDrugStats(playerid)
  209. {
  210. new dialog[350];
  211. format(
  212. dialog,
  213. sizeof(dialog),
  214. "Drugs\t%s grams\n\
  215. Seeds\t%s\n\
  216. Used Drugs\t%s grams\n\
  217. Planted Drugs\t%s\n\
  218. Harvested Plants\t%s (%s grams)\n\
  219. Drugs Given\t%s grams\n\
  220. Drugs Received\t%s grams\n\
  221. Drugs Bought\t%s grams {2ECC71}(%s)\n\
  222. Drugs Sold\t%s grams {2ECC71}(%s)\n\
  223. {FF0000}Reset Stats",
  224. formatInt(PlayerDrugData[playerid][Drugs], .iCurrencyChar = '\0'),
  225. formatInt(PlayerDrugData[playerid][Seeds], .iCurrencyChar = '\0'),
  226. formatInt(PlayerDrugData[playerid][TotalUsed], .iCurrencyChar = '\0'),
  227. formatInt(PlayerDrugData[playerid][TotalPlanted], .iCurrencyChar = '\0'),
  228. formatInt(PlayerDrugData[playerid][TotalHarvestedPlants], .iCurrencyChar = '\0'), formatInt(PlayerDrugData[playerid][TotalHarvestedGrams], .iCurrencyChar = '\0'),
  229. formatInt(PlayerDrugData[playerid][TotalGiven], .iCurrencyChar = '\0'),
  230. formatInt(PlayerDrugData[playerid][TotalReceived], .iCurrencyChar = '\0'),
  231. formatInt(PlayerDrugData[playerid][TotalBought], .iCurrencyChar = '\0'), formatInt(PlayerDrugData[playerid][TotalBoughtPrice]),
  232. formatInt(PlayerDrugData[playerid][TotalSold], .iCurrencyChar = '\0'), formatInt(PlayerDrugData[playerid][TotalSoldPrice])
  233. );
  234.  
  235. ShowPlayerDialog(playerid, DIALOG_DRUG_STATS, DIALOG_STYLE_TABLIST, "Drug Stats", dialog, "Choose", "Close");
  236. return 1;
  237. }
  238.  
  239. ShowDealerMenu(playerid)
  240. {
  241. new dialog[300], id = PlayerDrugData[playerid][DealerID];
  242. format(
  243. dialog,
  244. sizeof(dialog),
  245. "Option\tPrice\tYou Have\n\
  246. {%06x}Buy Drug Plant Seed\t{2ECC71}%s\t%s\n\
  247. {%06x}Buy Drugs (%s grams on dealer)\t{2ECC71}%s x gram\t%s grams\n\
  248. {%06x}Sell Drugs\t{2ECC71}%s x gram\t%s grams",
  249. (PlayerDrugData[playerid][Seeds] < SEED_LIMIT) ? 0xFFFFFFFF >>> 8 : 0xE74C3CFF >>> 8, formatInt(SEED_PRICE), formatInt(PlayerDrugData[playerid][Seeds], .iCurrencyChar = '\0'),
  250. (PlayerDrugData[playerid][Drugs] >= CARRY_LIMIT || DealerData[id][dealerDrugs] < 1) ? 0xE74C3CFF >>> 8 : 0xFFFFFFFF >>> 8, formatInt(DealerData[id][dealerDrugs], .iCurrencyChar = '\0'), formatInt(DRUG_BUY_PRICE), formatInt(PlayerDrugData[playerid][Drugs], .iCurrencyChar = '\0'),
  251. (PlayerDrugData[playerid][Drugs] > 0) ? 0xFFFFFFFF >>> 8 : 0xE74C3CFF >>> 8, formatInt(DRUG_SELL_PRICE), formatInt(PlayerDrugData[playerid][Drugs], .iCurrencyChar = '\0')
  252. );
  253.  
  254. ShowPlayerDialog(playerid, DIALOG_DRUG_DEALER, DIALOG_STYLE_TABLIST_HEADERS, "Drug Dealer", dialog, "Choose", "Close");
  255. return 1;
  256. }
  257.  
  258. Player_GetName(playerid)
  259. {
  260. new name[MAX_PLAYER_NAME];
  261. GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  262. return name;
  263. }
  264.  
  265. Player_PlantCount(playerid)
  266. {
  267. new count = 0, name[MAX_PLAYER_NAME];
  268. GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  269. foreach(new i : Plants) if(!strcmp(PlantData[i][plantedBy], name, true)) count++;
  270. return count;
  271. }
  272.  
  273. Player_Init(playerid)
  274. {
  275. new emptydata[E_PLAYER];
  276. PlayerDrugData[playerid] = emptydata;
  277. PlayerDrugData[playerid][DrugsOfferedBy] = INVALID_PLAYER_ID;
  278. RegenTimer[playerid] = EffectTimer[playerid] = -1;
  279.  
  280. // load player
  281. new drugs, seeds, totalused, totalplanted, harvested[2], given, received, bought[2], sold[2];
  282. stmt_bind_value(LoadPlayer, 0, DB::TYPE_STRING, Player_GetName(playerid));
  283. stmt_bind_result_field(LoadPlayer, 0, DB::TYPE_INTEGER, drugs);
  284. stmt_bind_result_field(LoadPlayer, 1, DB::TYPE_INTEGER, seeds);
  285. stmt_bind_result_field(LoadPlayer, 2, DB::TYPE_INTEGER, totalused);
  286. stmt_bind_result_field(LoadPlayer, 3, DB::TYPE_INTEGER, totalplanted);
  287. stmt_bind_result_field(LoadPlayer, 4, DB::TYPE_INTEGER, harvested[0]);
  288. stmt_bind_result_field(LoadPlayer, 5, DB::TYPE_INTEGER, harvested[1]);
  289. stmt_bind_result_field(LoadPlayer, 6, DB::TYPE_INTEGER, given);
  290. stmt_bind_result_field(LoadPlayer, 7, DB::TYPE_INTEGER, received);
  291. stmt_bind_result_field(LoadPlayer, 8, DB::TYPE_INTEGER, bought[0]);
  292. stmt_bind_result_field(LoadPlayer, 9, DB::TYPE_INTEGER, bought[1]);
  293. stmt_bind_result_field(LoadPlayer, 10, DB::TYPE_INTEGER, sold[0]);
  294. stmt_bind_result_field(LoadPlayer, 11, DB::TYPE_INTEGER, sold[1]);
  295.  
  296. if(stmt_execute(LoadPlayer))
  297. {
  298. if(stmt_rows_left(LoadPlayer) > 0) {
  299. stmt_fetch_row(LoadPlayer);
  300.  
  301. PlayerDrugData[playerid][Drugs] = drugs;
  302. PlayerDrugData[playerid][Seeds] = seeds;
  303. PlayerDrugData[playerid][TotalUsed] = totalused;
  304. PlayerDrugData[playerid][TotalPlanted] = totalplanted;
  305. PlayerDrugData[playerid][TotalHarvestedPlants] = harvested[0];
  306. PlayerDrugData[playerid][TotalHarvestedGrams] = harvested[1];
  307. PlayerDrugData[playerid][TotalGiven] = given;
  308. PlayerDrugData[playerid][TotalReceived] = received;
  309. PlayerDrugData[playerid][TotalBought] = bought[0];
  310. PlayerDrugData[playerid][TotalBoughtPrice] = bought[1];
  311. PlayerDrugData[playerid][TotalSold] = sold[0];
  312. PlayerDrugData[playerid][TotalSoldPrice] = sold[1];
  313. }else{
  314. stmt_bind_value(InsertPlayer, 0, DB::TYPE_STRING, Player_GetName(playerid));
  315. stmt_execute(InsertPlayer);
  316. }
  317. }
  318.  
  319. return 1;
  320. }
  321.  
  322. Player_SaveDrugs(playerid)
  323. {
  324. stmt_bind_value(SavePlayer, 0, DB::TYPE_INTEGER, PlayerDrugData[playerid][Drugs]);
  325. stmt_bind_value(SavePlayer, 1, DB::TYPE_INTEGER, PlayerDrugData[playerid][Seeds]);
  326. stmt_bind_value(SavePlayer, 2, DB::TYPE_INTEGER, PlayerDrugData[playerid][TotalUsed]);
  327. stmt_bind_value(SavePlayer, 3, DB::TYPE_INTEGER, PlayerDrugData[playerid][TotalPlanted]);
  328. stmt_bind_value(SavePlayer, 4, DB::TYPE_INTEGER, PlayerDrugData[playerid][TotalHarvestedPlants]);
  329. stmt_bind_value(SavePlayer, 5, DB::TYPE_INTEGER, PlayerDrugData[playerid][TotalHarvestedGrams]);
  330. stmt_bind_value(SavePlayer, 6, DB::TYPE_INTEGER, PlayerDrugData[playerid][TotalGiven]);
  331. stmt_bind_value(SavePlayer, 7, DB::TYPE_INTEGER, PlayerDrugData[playerid][TotalReceived]);
  332. stmt_bind_value(SavePlayer, 8, DB::TYPE_INTEGER, PlayerDrugData[playerid][TotalBought]);
  333. stmt_bind_value(SavePlayer, 9, DB::TYPE_INTEGER, PlayerDrugData[playerid][TotalBoughtPrice]);
  334. stmt_bind_value(SavePlayer, 10, DB::TYPE_INTEGER, PlayerDrugData[playerid][TotalSold]);
  335. stmt_bind_value(SavePlayer, 11, DB::TYPE_INTEGER, PlayerDrugData[playerid][TotalSoldPrice]);
  336. stmt_bind_value(SavePlayer, 12, DB::TYPE_STRING, Player_GetName(playerid));
  337. return stmt_execute(SavePlayer);
  338. }
  339.  
  340. Plant_GrowthPercentage(id)
  341. {
  342. if(!Iter_Contains(Plants, id)) return 0;
  343. return (PlantData[id][plantGrowth] * 100) / PLANT_MAX_GROWTH;
  344. }
  345.  
  346. Plant_GetOwnerID(id)
  347. {
  348. if(!Iter_Contains(Plants, id)) return INVALID_PLAYER_ID;
  349. foreach(new i : Player) if(!strcmp(PlantData[id][plantedBy], Player_GetName(i), true)) return i;
  350. return INVALID_PLAYER_ID;
  351. }
  352.  
  353. Plant_Destroy(id)
  354. {
  355. if(!Iter_Contains(Plants, id)) return 0;
  356. KillTimer(PlantData[id][plantTimer]);
  357. DestroyDynamicObject(PlantData[id][plantObj]);
  358. DestroyDynamic3DTextLabel(PlantData[id][plantLabel]);
  359.  
  360. PlantData[id][plantObj] = PlantData[id][plantTimer] = -1;
  361. PlantData[id][plantLabel] = Text3D: -1;
  362. PlantData[id][gotLeaves] = false;
  363.  
  364. Iter_Remove(Plants, id);
  365. return 1;
  366. }
  367.  
  368. public OnFilterScriptInit()
  369. {
  370. for(new i; i < MAX_PLANTS; i++)
  371. {
  372. PlantData[i][plantObj] = PlantData[i][plantTimer] = -1;
  373. PlantData[i][plantLabel] = Text3D: -1;
  374. }
  375.  
  376. for(new i; i < MAX_DEALERS; i++)
  377. {
  378. DealerData[i][dealerActorID] = -1;
  379. DealerData[i][dealerLabel] = Text3D: -1;
  380. }
  381.  
  382. // database
  383. DrugDB = db_open("drugs.db");
  384. db_query(DrugDB, "CREATE TABLE IF NOT EXISTS playerdrugs (Name TEXT, Drugs INTEGER, Seeds INTEGER, TotalUsed INTEGER, TotalPlanted INTEGER, TotalHarvestedPlants INTEGER, TotalHarvestedGrams INTEGER, TotalGiven INTEGER, TotalReceived INTEGER, TotalBought INTEGER, TotalBoughtPrice INTEGER, TotalSold INTEGER, TotalSoldPrice INTEGER)");
  385. db_query(DrugDB, "CREATE TABLE IF NOT EXISTS dealers (ID INTEGER, Skin INTEGER, Drugs INTEGER, PosX FLOAT, PosY FLOAT, PosZ FLOAT, PosA FLOAT)");
  386.  
  387. // prepare player queries
  388. LoadPlayer = db_prepare(DrugDB, "SELECT Drugs, Seeds, TotalUsed, TotalPlanted, TotalHarvestedPlants, TotalHarvestedGrams, TotalGiven, TotalReceived, TotalBought, TotalBoughtPrice, TotalSold, TotalSoldPrice FROM playerdrugs WHERE Name=?");
  389. InsertPlayer = db_prepare(DrugDB, "INSERT INTO playerdrugs (Name) VALUES (?)");
  390. SavePlayer = db_prepare(DrugDB, "UPDATE playerdrugs SET Drugs=?, Seeds=?, TotalUsed=?, TotalPlanted=?, TotalHarvestedPlants=?, TotalHarvestedGrams=?, TotalGiven=?, TotalReceived=?, TotalBought=?, TotalBoughtPrice=?, TotalSold=?, TotalSoldPrice=? WHERE Name=?");
  391.  
  392. // prepare dealer queries
  393. LoadDealers = db_prepare(DrugDB, "SELECT * FROM dealers");
  394. AddDealer = db_prepare(DrugDB, "INSERT INTO dealers (ID, Skin, PosX, PosY, PosZ, PosA) VALUES (?, ?, ?, ?, ?, ?)");
  395. UpdateDealer = db_prepare(DrugDB, "UPDATE dealers SET Skin=?, PosX=?, PosY=?, PosZ=?, PosA=? WHERE ID=?");
  396. UpdateDealerDrugs = db_prepare(DrugDB, "UPDATE dealers SET Drugs=? WHERE ID=?");
  397. RemoveDealer = db_prepare(DrugDB, "DELETE FROM dealers WHERE ID=?");
  398.  
  399. // initialize connected players
  400. foreach(new i : Player) Player_Init(i);
  401.  
  402. // load dealers
  403. new id, skin, drugs, Float: pos[4];
  404. stmt_bind_result_field(LoadDealers, 0, DB::TYPE_INTEGER, id);
  405. stmt_bind_result_field(LoadDealers, 1, DB::TYPE_INTEGER, skin);
  406. stmt_bind_result_field(LoadDealers, 2, DB::TYPE_INTEGER, drugs);
  407. stmt_bind_result_field(LoadDealers, 3, DB::TYPE_FLOAT, pos[0]);
  408. stmt_bind_result_field(LoadDealers, 4, DB::TYPE_FLOAT, pos[1]);
  409. stmt_bind_result_field(LoadDealers, 5, DB::TYPE_FLOAT, pos[2]);
  410. stmt_bind_result_field(LoadDealers, 6, DB::TYPE_FLOAT, pos[3]);
  411.  
  412. if(stmt_execute(LoadDealers))
  413. {
  414. new label[128];
  415. while(stmt_fetch_row(LoadDealers))
  416. {
  417. DealerData[id][dealerSkin] = skin;
  418. DealerData[id][dealerDrugs] = drugs;
  419. DealerData[id][dealerX] = pos[0];
  420. DealerData[id][dealerY] = pos[1];
  421. DealerData[id][dealerZ] = pos[2];
  422. DealerData[id][dealerA] = pos[3];
  423.  
  424. DealerData[id][dealerActorID] = CreateActor(DealerData[id][dealerSkin], DealerData[id][dealerX], DealerData[id][dealerY], DealerData[id][dealerZ], DealerData[id][dealerA]);
  425. SetActorInvulnerable(DealerData[id][dealerActorID], 1);
  426.  
  427. format(label, sizeof(label), "Drug Dealer (%d)\n\n{FFFFFF}Use {F1C40F}/dealer {FFFFFF}to open dealer menu.", id);
  428. DealerData[id][dealerLabel] = CreateDynamic3DTextLabel(label, 0xF1C40FFF, DealerData[id][dealerX], DealerData[id][dealerY], DealerData[id][dealerZ] + 0.25, 5.0, .testlos = 1);
  429.  
  430. Iter_Add(Dealers, id);
  431. }
  432. }
  433.  
  434. return 1;
  435. }
  436.  
  437. public OnFilterScriptExit()
  438. {
  439. foreach(new i : Player) Player_SaveDrugs(i);
  440. foreach(new i : Dealers) DestroyActor(DealerData[i][dealerActorID]);
  441.  
  442. db_close(DrugDB);
  443. return 1;
  444. }
  445.  
  446. public OnPlayerConnect(playerid)
  447. {
  448. Player_Init(playerid);
  449. return 1;
  450. }
  451.  
  452. public OnPlayerDeath(playerid, killerid, reason)
  453. {
  454. PlayerDrugData[playerid][DrugsCooldown] = 0;
  455.  
  456. if(RegenTimer[playerid] != -1)
  457. {
  458. KillTimer(RegenTimer[playerid]);
  459. RegenTimer[playerid] = -1;
  460. }
  461.  
  462. if(EffectTimer[playerid] != -1)
  463. {
  464. KillTimer(EffectTimer[playerid]);
  465. EffectTimer[playerid] = -1;
  466. }
  467.  
  468. foreach(new i : Player)
  469. {
  470. if(PlayerDrugData[i][DrugsOfferedBy] == playerid)
  471. {
  472. PlayerDrugData[i][DrugsOfferedBy] = INVALID_PLAYER_ID;
  473. ShowPlayerDialog(i, -1, DIALOG_STYLE_MSGBOX, "Title", "Content", "Button1", "Button2");
  474.  
  475. SendClientMessage(i, 0x3498DBFF, "DRUGS: {FFFFFF}The player who sent you an offer died.");
  476. }
  477. }
  478.  
  479. return 1;
  480. }
  481.  
  482. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  483. {
  484. switch(dialogid)
  485. {
  486. ////////////////////////////////////////////////////////////////
  487. case DIALOG_DRUG_STATS:
  488. {
  489. if(!response) return 1;
  490. if(listitem < 9) {
  491. ShowDrugStats(playerid);
  492. }else{
  493. ShowPlayerDialog(playerid, DIALOG_CONFIRM_RESET, DIALOG_STYLE_MSGBOX, "Drug Stats: Reset", "Do you want to reset your drug stats?", "Yes", "No");
  494. }
  495.  
  496. return 1;
  497. }
  498. ////////////////////////////////////////////////////////////////
  499. case DIALOG_CONFIRM_RESET:
  500. {
  501. if(!response) return ShowDrugStats(playerid);
  502. PlayerDrugData[playerid][TotalUsed] = PlayerDrugData[playerid][TotalPlanted] = PlayerDrugData[playerid][TotalHarvestedPlants] = PlayerDrugData[playerid][TotalHarvestedGrams] =
  503. PlayerDrugData[playerid][TotalGiven] = PlayerDrugData[playerid][TotalReceived] = PlayerDrugData[playerid][TotalBought] = PlayerDrugData[playerid][TotalBoughtPrice] =
  504. PlayerDrugData[playerid][TotalSold] = PlayerDrugData[playerid][TotalSoldPrice] = 0;
  505.  
  506. Player_SaveDrugs(playerid);
  507. ShowDrugStats(playerid);
  508. return 1;
  509. }
  510. ////////////////////////////////////////////////////////////////
  511. case DIALOG_DRUG_DEALER:
  512. {
  513. if(response)
  514. {
  515. if(listitem == 0)
  516. {
  517. if(PlayerDrugData[playerid][Seeds] >= SEED_LIMIT)
  518. {
  519. SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't buy any more seeds.");
  520. return ShowDealerMenu(playerid);
  521. }
  522.  
  523. ShowPlayerDialog(playerid, DIALOG_DRUG_DEALER_BUY_SEEDS, DIALOG_STYLE_INPUT, "Drug Dealer: Buying Seeds", "How many seeds would you like to buy?", "Buy", "Back");
  524. }
  525.  
  526. if(listitem == 1)
  527. {
  528. if(PlayerDrugData[playerid][Drugs] >= CARRY_LIMIT)
  529. {
  530. SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't buy any more drugs.");
  531. return ShowDealerMenu(playerid);
  532. }
  533.  
  534. if(DealerData[ PlayerDrugData[playerid][DealerID] ][dealerDrugs] < 1)
  535. {
  536. SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}This dealer has no drugs.");
  537. return ShowDealerMenu(playerid);
  538. }
  539.  
  540. ShowPlayerDialog(playerid, DIALOG_DRUG_DEALER_BUY_DRUGS, DIALOG_STYLE_INPUT, "Drug Dealer: Buying Drugs", "How many grams would you like to buy?", "Buy", "Back");
  541. }
  542.  
  543. if(listitem == 2)
  544. {
  545. if(PlayerDrugData[playerid][Drugs] < 1)
  546. {
  547. SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't have any drugs.");
  548. return ShowDealerMenu(playerid);
  549. }
  550.  
  551. ShowPlayerDialog(playerid, DIALOG_DRUG_DEALER_SELL, DIALOG_STYLE_INPUT, "Drug Dealer: Selling Drugs", "How many grams would you like to sell?", "Sell", "Back");
  552. }
  553. }
  554.  
  555. return 1;
  556. }
  557. ////////////////////////////////////////////////////////////////
  558. case DIALOG_DRUG_DEALER_BUY_SEEDS:
  559. {
  560. if(!response) return ShowDealerMenu(playerid);
  561. if(isnull(inputtext)) return ShowPlayerDialog(playerid, DIALOG_DRUG_DEALER_BUY_SEEDS, DIALOG_STYLE_INPUT, "Drug Dealer: Buying Seeds", "{E74C3C}Input can't be empty.\n\n{FFFFFF}How many seeds would you like to buy?", "Buy", "Back");
  562. new amount = strval(inputtext);
  563. if(!(0 < amount <= SEED_LIMIT)) return ShowPlayerDialog(playerid, DIALOG_DRUG_DEALER_BUY_SEEDS, DIALOG_STYLE_INPUT, "Drug Dealer: Buying Seeds", "{E74C3C}Invalid amount.\n\n{FFFFFF}How many seeds would you like to buy?", "Buy", "Back");
  564. if(PlayerDrugData[playerid][Seeds] + amount > SEED_LIMIT) amount = SEED_LIMIT - PlayerDrugData[playerid][Seeds];
  565. new price = amount * SEED_PRICE;
  566. if(price > GetPlayerMoney(playerid)) return ShowPlayerDialog(playerid, DIALOG_DRUG_DEALER_BUY_SEEDS, DIALOG_STYLE_INPUT, "Drug Dealer: Buying Seeds", "{E74C3C}You don't have enough money.\n\n{FFFFFF}How many seeds would you like to buy?", "Buy", "Back");
  567. PlayerDrugData[playerid][Seeds] += amount;
  568. GivePlayerMoney(playerid, -price);
  569.  
  570. new string[96];
  571. format(string, sizeof(string), "DRUG DEALER: {FFFFFF}Bought %s seeds for {2ECC71}%s.", formatInt(amount, .iCurrencyChar = '\0'), formatInt(price));
  572. SendClientMessage(playerid, 0x3498DBFF, string);
  573. return 1;
  574. }
  575. ////////////////////////////////////////////////////////////////
  576. case DIALOG_DRUG_DEALER_BUY_DRUGS:
  577. {
  578. if(!response) return ShowDealerMenu(playerid);
  579. if(isnull(inputtext)) return ShowPlayerDialog(playerid, DIALOG_DRUG_DEALER_BUY_DRUGS, DIALOG_STYLE_INPUT, "Drug Dealer: Buying Drugs", "{E74C3C}Input can't be empty.\n\n{FFFFFF}How many grams would you like to buy?", "Buy", "Back");
  580. new amount = strval(inputtext), id = PlayerDrugData[playerid][DealerID];
  581. if(!(0 < amount <= CARRY_LIMIT)) return ShowPlayerDialog(playerid, DIALOG_DRUG_DEALER_BUY_DRUGS, DIALOG_STYLE_INPUT, "Drug Dealer: Buying Drugs", "{E74C3C}Invalid amount.\n\n{FFFFFF}How many grams would you like to buy?", "Buy", "Back");
  582. if(amount > DealerData[id][dealerDrugs])
  583. {
  584. SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Dealer doesn't have that much drugs.");
  585. return ShowDealerMenu(playerid);
  586. }
  587.  
  588. if(PlayerDrugData[playerid][Drugs] + amount > CARRY_LIMIT) amount = CARRY_LIMIT - PlayerDrugData[playerid][Drugs];
  589. new price = amount * DRUG_BUY_PRICE;
  590. if(price > GetPlayerMoney(playerid)) return ShowPlayerDialog(playerid, DIALOG_DRUG_DEALER_BUY_DRUGS, DIALOG_STYLE_INPUT, "Drug Dealer: Buying Drugs", "{E74C3C}You don't have enough money.\n\n{FFFFFF}How many grams would you like to buy?", "Buy", "Back");
  591. DealerData[id][dealerDrugs] -= amount;
  592. PlayerDrugData[playerid][Drugs] += amount;
  593. PlayerDrugData[playerid][TotalBought] += amount;
  594. PlayerDrugData[playerid][TotalBoughtPrice] += price;
  595. GivePlayerMoney(playerid, -price);
  596.  
  597. new string[96];
  598. format(string, sizeof(string), "DRUG DEALER: {FFFFFF}Bought %s grams of drugs for {2ECC71}%s.", formatInt(amount, .iCurrencyChar = '\0'), formatInt(price));
  599. SendClientMessage(playerid, 0x3498DBFF, string);
  600.  
  601. stmt_bind_value(UpdateDealerDrugs, 0, DB::TYPE_INTEGER, DealerData[id][dealerDrugs]);
  602. stmt_bind_value(UpdateDealerDrugs, 1, DB::TYPE_INTEGER, id);
  603. stmt_execute(UpdateDealerDrugs);
  604. return 1;
  605. }
  606. ////////////////////////////////////////////////////////////////
  607. case DIALOG_DRUG_DEALER_SELL:
  608. {
  609. if(!response) return ShowDealerMenu(playerid);
  610. if(isnull(inputtext)) return ShowPlayerDialog(playerid, DIALOG_DRUG_DEALER_SELL, DIALOG_STYLE_INPUT, "Drug Dealer: Selling Drugs", "{E74C3C}Input can't be empty.\n\n{FFFFFF}How many grams would you like to sell?", "Sell", "Back");
  611. new amount = strval(inputtext), id = PlayerDrugData[playerid][DealerID];
  612. if(!(0 < amount <= CARRY_LIMIT)) return ShowPlayerDialog(playerid, DIALOG_DRUG_DEALER_SELL, DIALOG_STYLE_INPUT, "Drug Dealer: Selling Drugs", "{E74C3C}Invalid amount.\n\n{FFFFFF}How many grams would you like to sell?", "Sell", "Back");
  613. if(amount > PlayerDrugData[playerid][Drugs]) return ShowPlayerDialog(playerid, DIALOG_DRUG_DEALER_SELL, DIALOG_STYLE_INPUT, "Drug Dealer: Selling Drugs", "{E74C3C}You don't have that much drugs.\n\n{FFFFFF}How many grams would you like to sell?", "Sell", "Back");
  614. new price = amount * DRUG_SELL_PRICE;
  615. DealerData[id][dealerDrugs] += amount;
  616. PlayerDrugData[playerid][Drugs] -= amount;
  617. PlayerDrugData[playerid][TotalSold] += amount;
  618. PlayerDrugData[playerid][TotalSoldPrice] += price;
  619. GivePlayerMoney(playerid, price);
  620.  
  621. new string[96];
  622. format(string, sizeof(string), "DRUG DEALER: {FFFFFF}Sold %s grams of drugs for {2ECC71}%s.", formatInt(amount, .iCurrencyChar = '\0'), formatInt(price));
  623. SendClientMessage(playerid, 0x3498DBFF, string);
  624.  
  625. stmt_bind_value(UpdateDealerDrugs, 0, DB::TYPE_INTEGER, DealerData[id][dealerDrugs]);
  626. stmt_bind_value(UpdateDealerDrugs, 1, DB::TYPE_INTEGER, id);
  627. stmt_execute(UpdateDealerDrugs);
  628. return 1;
  629. }
  630. ////////////////////////////////////////////////////////////////
  631. case DIALOG_DRUG_OFFER:
  632. {
  633. if(!response)
  634. {
  635. new string[96];
  636. format(string, sizeof(string), "DRUGS: {FFFFFF}Your offer got rejected by %s(%d).", Player_GetName(playerid), playerid);
  637. SendClientMessage(PlayerDrugData[playerid][DrugsOfferedBy], 0x3498DBFF, string);
  638.  
  639. PlayerDrugData[playerid][DrugsOfferedBy] = INVALID_PLAYER_ID;
  640. return 1;
  641. }
  642.  
  643. new id = PlayerDrugData[playerid][DrugsOfferedBy], offeredp = PlayerDrugData[playerid][DrugsOfferedPrice], amount = strval(inputtext);
  644. PlayerDrugData[playerid][DrugsOfferedBy] = INVALID_PLAYER_ID;
  645. if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Dealer is offline.");
  646. if(DistanceBetweenPlayers(playerid, id) > 5.0) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You must be near to the dealer you want to buy drugs from.");
  647. if(!(0 < amount <= CARRY_LIMIT)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Invalid amount.");
  648. if(amount > PlayerDrugData[id][Drugs]) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Dealer doesn't have that much drugs.");
  649. if(PlayerDrugData[playerid][Drugs] + amount > CARRY_LIMIT) amount = CARRY_LIMIT - PlayerDrugData[playerid][Drugs];
  650. new price = amount * offeredp;
  651. if(price > GetPlayerMoney(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't have enough money.");
  652. PlayerDrugData[playerid][Drugs] += amount;
  653. PlayerDrugData[id][Drugs] -= amount;
  654. GivePlayerMoney(playerid, -price);
  655. GivePlayerMoney(id, price);
  656.  
  657. new string[128];
  658. format(string, sizeof(string), "DRUGS: {FFFFFF}Sold %s grams of drugs to %s(%d) for {2ECC71}%s.", formatInt(amount, .iCurrencyChar = '\0'), Player_GetName(playerid), playerid, formatInt(price));
  659. SendClientMessage(id, 0x3498DBFF, string);
  660.  
  661. format(string, sizeof(string), "DRUGS: {FFFFFF}Bought %s grams of drugs from %s(%d) for {2ECC71}%s.", formatInt(amount, .iCurrencyChar = '\0'), Player_GetName(id), id, formatInt(price));
  662. SendClientMessage(playerid, 0x3498DBFF, string);
  663. return 1;
  664. }
  665. ////////////////////////////////////////////////////////////////
  666. }
  667.  
  668. return 0;
  669. }
  670.  
  671. public OnPlayerDisconnect(playerid, reason)
  672. {
  673. if(RegenTimer[playerid] != -1)
  674. {
  675. KillTimer(RegenTimer[playerid]);
  676. RegenTimer[playerid] = -1;
  677. }
  678.  
  679. foreach(new i : Player)
  680. {
  681. if(PlayerDrugData[i][DrugsOfferedBy] == playerid)
  682. {
  683. PlayerDrugData[i][DrugsOfferedBy] = INVALID_PLAYER_ID;
  684. ShowPlayerDialog(i, -1, DIALOG_STYLE_MSGBOX, "Title", "Content", "Button1", "Button2");
  685.  
  686. SendClientMessage(i, 0x3498DBFF, "DRUGS: {FFFFFF}The player who sent you an offer disconnected.");
  687. }
  688. }
  689.  
  690. RemoveEffects(playerid);
  691. Player_SaveDrugs(playerid);
  692. return 1;
  693. }
  694.  
  695. forward PlantGrowth(id);
  696. public PlantGrowth(id)
  697. {
  698. new label_string[128];
  699. PlantData[id][plantGrowth] += RandomEx(3, 7);
  700.  
  701. if(PlantData[id][plantGrowth] >= PLANT_MAX_GROWTH) {
  702. PlantData[id][plantGrowth] = PLANT_MAX_GROWTH;
  703. KillTimer(PlantData[id][plantTimer]);
  704. PlantData[id][plantTimer] = SetTimerEx("PlantRot", ROT_INTERVAL * 1000, false, "i", id);
  705.  
  706. new percentage = Plant_GrowthPercentage(id);
  707. format(label_string, sizeof(label_string), "Rotting Drug Plant (%d)\n\n{FFFFFF}Placed by %s\nGrowth: {%06x}%d%%\n\n{FFFFFF}/plant harvest", id, PlantData[id][plantedBy], (percentage < 25) ? 0xE74C3CFF >>> 8 : 0x2ECC71FF >>> 8, percentage);
  708. UpdateDynamic3DTextLabelText(PlantData[id][plantLabel], 0xF1C40FFF, label_string);
  709.  
  710. SetDynamicObjectMaterial(PlantData[id][plantObj], 2, 2, "plants_TABLETOP", "CJ_PLANT", 0xFFD35400);
  711.  
  712. new owner_id = Plant_GetOwnerID(id);
  713. if(IsPlayerConnected(owner_id)) SendClientMessage(owner_id, 0x3498DBFF, "DRUG PLANT: {FFFFFF}One of your drug plants growed, harvest it before it rots!");
  714. }else{
  715. new percentage = Plant_GrowthPercentage(id);
  716. if(!PlantData[id][gotLeaves] && percentage >= 25)
  717. {
  718. SetDynamicObjectMaterial(PlantData[id][plantObj], 2, 2, "plants_TABLETOP", "CJ_PLANT", 0xFF2ECC71);
  719. PlantData[id][gotLeaves] = true;
  720. }
  721.  
  722. format(label_string, sizeof(label_string), "Drug Plant (%d)\n\n{FFFFFF}Placed by %s\nGrowth: {%06x}%d%%\n\n{FFFFFF}/plant harvest", id, PlantData[id][plantedBy], (percentage < 25) ? 0xE74C3CFF >>> 8 : 0x2ECC71FF >>> 8, percentage);
  723. UpdateDynamic3DTextLabelText(PlantData[id][plantLabel], 0xF1C40FFF, label_string);
  724. }
  725.  
  726. return 1;
  727. }
  728.  
  729. forward PlantRot(id);
  730. public PlantRot(id)
  731. {
  732. new owner_id = Plant_GetOwnerID(id);
  733. if(IsPlayerConnected(owner_id)) SendClientMessage(owner_id, 0x3498DBFF, "DRUG PLANT: {FFFFFF}One of your drug plants rotted!");
  734.  
  735. Plant_Destroy(id);
  736. return 1;
  737. }
  738.  
  739. forward RegenHealth(playerid, amount);
  740. public RegenHealth(playerid, amount)
  741. {
  742. amount--;
  743.  
  744. new Float: health;
  745. GetPlayerHealth(playerid, health);
  746.  
  747. if(health + 2.5 < 95.0) SetPlayerHealth(playerid, health + 2.5);
  748. if(amount > 0) {
  749. #if defined USE_DRUNKLEVEL
  750. SetPlayerDrunkLevel(playerid, 4999);
  751. #endif
  752.  
  753. RegenTimer[playerid] = SetTimerEx("RegenHealth", 500, false, "ii", playerid, amount);
  754. }else{
  755. #if defined USE_DRUNKLEVEL
  756. SetPlayerDrunkLevel(playerid, 0);
  757. #endif
  758.  
  759. if(RegenTimer[playerid] != -1)
  760. {
  761. KillTimer(RegenTimer[playerid]);
  762. RegenTimer[playerid] = -1;
  763. }
  764. }
  765.  
  766. return 1;
  767. }
  768.  
  769. forward RemoveEffects(playerid);
  770. public RemoveEffects(playerid)
  771. {
  772. #if defined USE_DRUNKLEVEL
  773. SetPlayerDrunkLevel(playerid, 0);
  774. #endif
  775.  
  776. SetPlayerWeather(playerid, 10);
  777.  
  778. if(EffectTimer[playerid] != -1)
  779. {
  780. KillTimer(EffectTimer[playerid]);
  781. EffectTimer[playerid] = -1;
  782. }
  783.  
  784. return 1;
  785. }
  786.  
  787. // Player Commands
  788. CMD:usedrugs(playerid, params[])
  789. {
  790. if(PlayerDrugData[playerid][DrugsCooldown] > gettime()) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't use drugs right now.");
  791. new amount;
  792. if(sscanf(params, "i", amount)) return SendClientMessage(playerid, 0xE88732FF, "SYNTAX: {FFFFFF}/usedrugs [grams]");
  793. if(!(0 < amount <= 10)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't use less than 1 or more than 10 grams at once.");
  794. if(amount > PlayerDrugData[playerid][Drugs]) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't have enough drugs.");
  795. PlayerDrugData[playerid][DrugsCooldown] = gettime() + (10 * amount);
  796. PlayerDrugData[playerid][Drugs] -= amount;
  797. PlayerDrugData[playerid][TotalUsed] += amount;
  798.  
  799. SetPlayerWeather(playerid, 234);
  800. RegenTimer[playerid] = SetTimerEx("RegenHealth", 500, false, "ii", playerid, (3 * amount));
  801. EffectTimer[playerid] = SetTimerEx("RemoveEffects", (2 * amount) * 1000, false, "i", playerid);
  802.  
  803. new string[48];
  804. format(string, sizeof(string), "DRUGS: {FFFFFF}Used %d grams of drugs.", amount);
  805. SendClientMessage(playerid, 0x3498DBFF, string);
  806. return 1;
  807. }
  808.  
  809. CMD:givedrugs(playerid, params[])
  810. {
  811. new id, amount;
  812. if(sscanf(params, "ui", id, amount)) return SendClientMessage(playerid, 0xE88732FF, "SYNTAX: {FFFFFF}/givedrugs [player id] [grams]");
  813. if(id == playerid) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Um... why? You can't just give yourself drugs!");
  814. if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Invalid ID.");
  815. if(DistanceBetweenPlayers(playerid, id) > 5.0) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You must be near to the player you want to give drugs.");
  816. if(!(0 < amount <= 50)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't give than 1 or more than 50 grams at once.");
  817. if(amount > PlayerDrugData[playerid][Drugs]) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't have enough drugs.");
  818. if(PlayerDrugData[id][Drugs] + amount > CARRY_LIMIT) amount = CARRY_LIMIT - PlayerDrugData[id][Drugs];
  819. PlayerDrugData[playerid][Drugs] -= amount;
  820. PlayerDrugData[playerid][TotalGiven] += amount;
  821.  
  822. PlayerDrugData[id][Drugs] += amount;
  823. PlayerDrugData[id][TotalReceived] += amount;
  824.  
  825. new string[96];
  826. format(string, sizeof(string), "DRUGS: {FFFFFF}%s(%d) gave you %d grams of drugs.", Player_GetName(playerid), playerid, amount);
  827. SendClientMessage(id, 0x3498DBFF, string);
  828. format(string, sizeof(string), "DRUGS: {FFFFFF}%d grams of drugs given to %s(%d).", amount, Player_GetName(id), id);
  829. SendClientMessage(playerid, 0x3498DBFF, string);
  830. return 1;
  831. }
  832.  
  833. CMD:selldrugs(playerid, params[])
  834. {
  835. if(PlayerDrugData[playerid][Drugs] < 1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't have drugs.");
  836. new id, price;
  837. if(sscanf(params, "ui", id, price)) return SendClientMessage(playerid, 0xE88732FF, "SYNTAX: {FFFFFF}/selldrugs [player id] [price per gram]");
  838. if(id == playerid) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Um... why? You can't just sell yourself drugs!");
  839. if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Invalid ID.");
  840. if(DistanceBetweenPlayers(playerid, id) > 5.0) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You must be near to the player you want to offer drugs.");
  841. if(IsPlayerConnected(PlayerDrugData[id][DrugsOfferedBy])) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't sell drugs to this player right now.");
  842. if(!(0 < price <= 5000)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Price can't be less than $1 and more than $5,000.");
  843. if(PlayerDrugData[id][Drugs] >= CARRY_LIMIT) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}The player you want to sell drugs can't carry any more drugs.");
  844. if(PlayerDrugData[id][DrugsOfferCooldown] > gettime()) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Wait before offering drugs again to this player.");
  845. PlayerDrugData[id][DrugsOfferedBy] = playerid;
  846. PlayerDrugData[id][DrugsOfferedPrice] = price;
  847. PlayerDrugData[id][DrugsOfferCooldown] = gettime() + OFFER_COOLDOWN;
  848.  
  849. new string[172];
  850. format(string, sizeof(string), "{FFFFFF}%s(%d) offered you some drugs.\nPrice: {2ECC71}%s per gram {FFFFFF}(has %s grams)\n\nHow many grams would you like to buy?", Player_GetName(playerid), playerid, formatInt(price), formatInt(PlayerDrugData[playerid][Drugs], .iCurrencyChar = '\0'));
  851. ShowPlayerDialog(id, DIALOG_DRUG_OFFER, DIALOG_STYLE_INPUT, "Drug Offer", string, "Buy", "Close");
  852.  
  853. format(string, sizeof(string), "DRUGS: {FFFFFF}Offer sent to %s(%d).", Player_GetName(id), id);
  854. SendClientMessage(playerid, 0x3498DBFF, string);
  855. return 1;
  856. }
  857.  
  858. CMD:drugstats(playerid, params[])
  859. {
  860. ShowDrugStats(playerid);
  861. return 1;
  862. }
  863.  
  864. CMD:dealer(playerid, params[])
  865. {
  866. new id = GetClosestDealer(playerid);
  867. if(id == -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not near a drug dealer.");
  868. PlayerDrugData[playerid][DealerID] = id;
  869. ShowDealerMenu(playerid);
  870. return 1;
  871. }
  872.  
  873. CMD:plant(playerid, params[])
  874. {
  875. if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't use this command in a vehicle.");
  876. if(isnull(params)) return SendClientMessage(playerid, 0xE88732FF, "SYNTAX: {FFFFFF}/plant [place/harvest]");
  877.  
  878. if(!strcmp(params, "place", true)) {
  879. /* -- planting -- */
  880. if(PlayerDrugData[playerid][Seeds] < 1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You don't have a drug seed.");
  881. if(Player_PlantCount(playerid) >= PLAYER_LIMIT) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't plant any more drug plants.");
  882. if(GetClosestPlant(playerid) != -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't place a drug plant here because there is one nearby.");
  883. new id = Iter_Free(Plants);
  884. if(id == -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Server drug plant limit reached.");
  885. GetPlayerName(playerid, PlantData[id][plantedBy], MAX_PLAYER_NAME);
  886. GetPlayerPos(playerid, PlantData[id][plantX], PlantData[id][plantY], PlantData[id][plantZ]);
  887.  
  888. PlantData[id][plantGrowth] = 0;
  889. PlantData[id][plantObj] = CreateDynamicObject(2244, PlantData[id][plantX], PlantData[id][plantY], PlantData[id][plantZ] - 0.70, 0.0, 0.0, 0.0);
  890. SetDynamicObjectMaterial(PlantData[id][plantObj], 2, 19478, "signsurf", "sign", 0xFFFFFFFF);
  891.  
  892. new label_string[128];
  893. format(label_string, sizeof(label_string), "Drug Plant (%d)\n\n{FFFFFF}Placed by %s\nGrowth: {E74C3C}0%%\n\n{FFFFFF}/plant harvest", id, PlantData[id][plantedBy]);
  894. PlantData[id][plantLabel] = CreateDynamic3DTextLabel(label_string, 0xF1C40FFF, PlantData[id][plantX], PlantData[id][plantY], PlantData[id][plantZ], 5.0);
  895.  
  896. PlantData[id][plantTimer] = SetTimerEx("PlantGrowth", GROWTH_INTERVAL * 1000, true, "i", id);
  897. Iter_Add(Plants, id);
  898.  
  899. PlayerDrugData[playerid][Seeds]--;
  900. PlayerDrugData[playerid][TotalPlanted]++;
  901. /* -- planting -- */
  902. }else if(!strcmp(params, "harvest")) {
  903. /* -- harvesting -- */
  904. if(PlayerDrugData[playerid][Drugs] >= CARRY_LIMIT) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't carry any more drugs.");
  905. new id = GetClosestPlant(playerid);
  906. if(id == -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not near a drug plant.");
  907. if(!PlantData[id][gotLeaves]) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't harvest this plant because it's not ready.");
  908. new harvested = PlantData[id][plantGrowth], string[96];
  909. if(PlayerDrugData[playerid][Drugs] + harvested > CARRY_LIMIT) harvested = CARRY_LIMIT - PlayerDrugData[playerid][Drugs];
  910. format(string, sizeof(string), "DRUG PLANT: {FFFFFF}You harvested a drug plant and got %d grams of drugs.", harvested);
  911. SendClientMessage(playerid, 0x3498DBFF, string);
  912.  
  913. PlayerDrugData[playerid][Drugs] += harvested;
  914. PlayerDrugData[playerid][TotalHarvestedPlants]++;
  915. PlayerDrugData[playerid][TotalHarvestedGrams] += harvested;
  916.  
  917. new owner_id = Plant_GetOwnerID(id);
  918. if(strcmp(PlantData[id][plantedBy], Player_GetName(playerid), true) && IsPlayerConnected(owner_id)) SendClientMessage(owner_id, 0x3498DBFF, "DRUG PLANT: {FFFFFF}Somebody harvested one of your drug plants!");
  919.  
  920. Plant_Destroy(id);
  921. /* -- harvesting -- */
  922. }else{
  923. SendClientMessage(playerid, 0xE88732FF, "SYNTAX: {FFFFFF}/plant [place/harvest]");
  924. }
  925.  
  926. return 1;
  927. }
  928.  
  929. // Admin Commands - Dealers
  930. CMD:createdealer(playerid, params[])
  931. {
  932. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Only RCON admins can use this command.");
  933. new skin;
  934. if(sscanf(params, "i", skin)) return SendClientMessage(playerid, 0xE88732FF, "SYNTAX: {FFFFFF}/createdealer [skin id]");
  935. if(!(0 <= skin <= 311)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Invalid skin ID.");
  936. new id = Iter_Free(Dealers);
  937. if(id == -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Can't add any more dealers.");
  938. GetPlayerPos(playerid, DealerData[id][dealerX], DealerData[id][dealerY], DealerData[id][dealerZ]);
  939. GetPlayerFacingAngle(playerid, DealerData[id][dealerA]);
  940.  
  941. DealerData[id][dealerSkin] = skin;
  942. DealerData[id][dealerDrugs] = 0;
  943. DealerData[id][dealerActorID] = CreateActor(skin, DealerData[id][dealerX], DealerData[id][dealerY], DealerData[id][dealerZ], DealerData[id][dealerA]);
  944. SetActorInvulnerable(DealerData[id][dealerActorID], 1);
  945.  
  946. new label[128];
  947. format(label, sizeof(label), "Drug Dealer (%d)\n\n{FFFFFF}Use {F1C40F}/dealer {FFFFFF}to open dealer menu.", id);
  948. DealerData[id][dealerLabel] = CreateDynamic3DTextLabel(label, 0xF1C40FFF, DealerData[id][dealerX], DealerData[id][dealerY], DealerData[id][dealerZ] + 0.25, 5.0, .testlos = 1);
  949. Iter_Add(Dealers, id);
  950.  
  951. stmt_bind_value(AddDealer, 0, DB::TYPE_INTEGER, id);
  952. stmt_bind_value(AddDealer, 1, DB::TYPE_INTEGER, skin);
  953. stmt_bind_value(AddDealer, 2, DB::TYPE_FLOAT, DealerData[id][dealerX]);
  954. stmt_bind_value(AddDealer, 3, DB::TYPE_FLOAT, DealerData[id][dealerY]);
  955. stmt_bind_value(AddDealer, 4, DB::TYPE_FLOAT, DealerData[id][dealerZ]);
  956. stmt_bind_value(AddDealer, 5, DB::TYPE_FLOAT, DealerData[id][dealerA]);
  957.  
  958. if(stmt_execute(AddDealer))
  959. {
  960. SendClientMessage(playerid, 0x3498DBFF, "DRUG DEALER: {FFFFFF}Dealer created.");
  961. SetPlayerPos(playerid, DealerData[id][dealerX] + (1.5 * floatsin(-DealerData[id][dealerA], degrees)), DealerData[id][dealerY] + (1.5 * floatcos(-DealerData[id][dealerA], degrees)), DealerData[id][dealerZ]);
  962. }
  963.  
  964. return 1;
  965. }
  966.  
  967. CMD:setdealerskin(playerid, params[])
  968. {
  969. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Only RCON admins can use this command.");
  970. if(isnull(params)) return SendClientMessage(playerid, 0xE88732FF, "SYNTAX: {FFFFFF}/setdealerskin [dealer id] [skin id]");
  971. new id, skin;
  972. if(sscanf(params, "ii", id, skin)) return SendClientMessage(playerid, 0xE88732FF, "SYNTAX: {FFFFFF}/setdealerskin [dealer id] [skin id]");
  973. if(!Iter_Contains(Dealers, id)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Invalid ID.");
  974. if(!(0 <= skin <= 311)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Invalid skin ID.");
  975. DealerData[id][dealerSkin] = skin;
  976.  
  977. DestroyActor(DealerData[id][dealerActorID]);
  978. DealerData[id][dealerActorID] = CreateActor(skin, DealerData[id][dealerX], DealerData[id][dealerY], DealerData[id][dealerZ], DealerData[id][dealerA]);
  979. SetActorInvulnerable(DealerData[id][dealerActorID], 1);
  980.  
  981. stmt_bind_value(UpdateDealer, 0, DB::TYPE_INTEGER, skin);
  982. stmt_bind_value(UpdateDealer, 1, DB::TYPE_FLOAT, DealerData[id][dealerX]);
  983. stmt_bind_value(UpdateDealer, 2, DB::TYPE_FLOAT, DealerData[id][dealerY]);
  984. stmt_bind_value(UpdateDealer, 3, DB::TYPE_FLOAT, DealerData[id][dealerZ]);
  985. stmt_bind_value(UpdateDealer, 4, DB::TYPE_FLOAT, DealerData[id][dealerA]);
  986. stmt_bind_value(UpdateDealer, 5, DB::TYPE_INTEGER, id);
  987.  
  988. if(stmt_execute(UpdateDealer)) SendClientMessage(playerid, 0x3498DBFF, "DRUG DEALER: {FFFFFF}Dealer updated.");
  989. return 1;
  990. }
  991.  
  992. CMD:setdealerpos(playerid, params[])
  993. {
  994. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Only RCON admins can use this command.");
  995. new id;
  996. if(sscanf(params, "i", id)) return SendClientMessage(playerid, 0xE88732FF, "SYNTAX: {FFFFFF}/setdealerpos [dealer id]");
  997. if(!Iter_Contains(Dealers, id)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Invalid ID.");
  998. GetPlayerPos(playerid, DealerData[id][dealerX], DealerData[id][dealerY], DealerData[id][dealerZ]);
  999. GetPlayerFacingAngle(playerid, DealerData[id][dealerA]);
  1000.  
  1001. DestroyActor(DealerData[id][dealerActorID]);
  1002. DealerData[id][dealerActorID] = CreateActor(DealerData[id][dealerSkin], DealerData[id][dealerX], DealerData[id][dealerY], DealerData[id][dealerZ], DealerData[id][dealerA]);
  1003. SetActorInvulnerable(DealerData[id][dealerActorID], 1);
  1004.  
  1005. Streamer_SetFloatData(STREAMER_TYPE_3D_TEXT_LABEL, DealerData[id][dealerLabel], E_STREAMER_X, DealerData[id][dealerX]);
  1006. Streamer_SetFloatData(STREAMER_TYPE_3D_TEXT_LABEL, DealerData[id][dealerLabel], E_STREAMER_Y, DealerData[id][dealerY]);
  1007. Streamer_SetFloatData(STREAMER_TYPE_3D_TEXT_LABEL, DealerData[id][dealerLabel], E_STREAMER_Z, DealerData[id][dealerZ] + 0.25);
  1008.  
  1009. stmt_bind_value(UpdateDealer, 0, DB::TYPE_INTEGER, DealerData[id][dealerSkin]);
  1010. stmt_bind_value(UpdateDealer, 1, DB::TYPE_FLOAT, DealerData[id][dealerX]);
  1011. stmt_bind_value(UpdateDealer, 2, DB::TYPE_FLOAT, DealerData[id][dealerY]);
  1012. stmt_bind_value(UpdateDealer, 3, DB::TYPE_FLOAT, DealerData[id][dealerZ]);
  1013. stmt_bind_value(UpdateDealer, 4, DB::TYPE_FLOAT, DealerData[id][dealerA]);
  1014. stmt_bind_value(UpdateDealer, 5, DB::TYPE_INTEGER, id);
  1015.  
  1016. if(stmt_execute(UpdateDealer))
  1017. {
  1018. SendClientMessage(playerid, 0x3498DBFF, "DRUG DEALER: {FFFFFF}Dealer updated.");
  1019. SetPlayerPos(playerid, DealerData[id][dealerX] + (1.5 * floatsin(-DealerData[id][dealerA], degrees)), DealerData[id][dealerY] + (1.5 * floatcos(-DealerData[id][dealerA], degrees)), DealerData[id][dealerZ]);
  1020. }
  1021.  
  1022. return 1;
  1023. }
  1024.  
  1025. CMD:removedealer(playerid, params[])
  1026. {
  1027. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Only RCON admins can use this command.");
  1028. new id;
  1029. if(sscanf(params, "i", id)) return SendClientMessage(playerid, 0xE88732FF, "SYNTAX: {FFFFFF}/removedealer [dealer id]");
  1030. if(!Iter_Contains(Dealers, id)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Invalid ID.");
  1031. DestroyActor(DealerData[id][dealerActorID]);
  1032. DestroyDynamic3DTextLabel(DealerData[id][dealerLabel]);
  1033.  
  1034. DealerData[id][dealerDrugs] = 0;
  1035. DealerData[id][dealerActorID] = -1;
  1036. DealerData[id][dealerLabel] = Text3D: -1;
  1037. Iter_Remove(Dealers, id);
  1038.  
  1039. stmt_bind_value(RemoveDealer, 0, DB::TYPE_INTEGER, id);
  1040. if(stmt_execute(RemoveDealer)) SendClientMessage(playerid, 0x3498DBFF, "DRUG DEALER: {FFFFFF}Dealer removed.");
  1041. return 1;
  1042. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement