fmddrugs.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. ______ __ __ _____ _____ _____ _ _ _____ _____ _______ _______ _______ ______ __ __ ______ __ _____ ______ _____ __ __ ____ _ _ _____
  3. | ____| \/ | __ \ | __ \| __ \| | | |/ ____|/ ____| / ____\ \ / / ____|__ __| ____| \/ | | _ \ \ / / | __ \| ____|/ ____| \/ |/ __ \| \ | | __ \
  4. | |__ | \ / | | | | | | | | |__) | | | | | __| (___ | (___ \ \_/ / (___ | | | |__ | \ / | | |_) \ \_/ / | | | | |__ | (___ | \ / | | | | \| | | | |
  5. | __| | |\/| | | | | | | | | _ /| | | | | |_ |\___ \ \___ \ \ / \___ \ | | | __| | |\/| | | _ < \ / | | | | __| \___ \| |\/| | | | | . ` | | | |
  6. | | | | | | |__| | | |__| | | \ \| |__| | |__| |____) | ____) | | | ____) | | | | |____| | | | | |_) | | | | |__| | |____ ____) | | | | |__| | |\ | |__| |
  7. |_| |_| |_|_____/ |_____/|_| \_\\____/ \_____|_____/ |_____/ |_| |_____/ |_| |______|_| |_| |____/ |_| |_____/|______|_____/|_| |_|\____/|_| \_|_____/
  8. */
  9. #define DIALOG_FMD_DRUGS 17854
  10. #define DIALOG_FMD_DRUGS_CHOOSE 17855
  11. #define DIALOG_FMD_DRUGS_PLAYER 17856
  12. #define DIALOG_FMD_DRUGS_AMOUNT 17857
  13. #define DIALOG_FMD_DRUGS_PRICE 17858
  14. #define DRUGS_CHOICE_XANAX 1
  15. #define DRUGS_CHOICE_CANNABIS 2
  16. new drugschoice[MAX_PLAYERS], playerchoice[MAX_PLAYERS], playeramount[MAX_PLAYERS], playerprice[MAX_PLAYERS];
  17. GetOfferDrugsName(drug)
  18. {
  19. new drugname[10];
  20. if(drug == DRUGS_CHOICE_XANAX) drugname = "Xanax";
  21. else if(drug == DRUGS_CHOICE_CANNABIS) drugname = "Cannabis";
  22. return drugname;
  23. }
  24. CMD:fmddrugs(playerid, params[])
  25. {
  26. if(PlayerInfo[playerid][pMember] != FACTION_FMD) return AdmErrorMsg;
  27. if(PlayerInfo[playerid][pRank] < 4) return SendClientMessage(playerid, COLOR_GREY, "Only R4+ can use this.");
  28. if(!IsPlayerInRangeOfPoint(playerid, 10.0, 2142.3999, 1467.9122, 10001.0830)) return SendClientMessage(playerid, COLOR_GREY, "You must be by the pharmacy counter to do this."); //@developers replace x y z with the pharmacy's coordinates
  29. ShowPlayerDialog(playerid, DIALOG_FMD_DRUGS, DIALOG_STYLE_LIST, "{FF8282}FMD Drugs Database", "{FFFFFF}Give Drugs\nDrugs Logs", "Select", "Cancel");
  30. return 1;
  31. }
  32. CMD:buyfmddrugs(playerid, params[])
  33. {
  34. if(playerchoice[playerid] == -1) return SendClientMessage(playerid, COLOR_GREY, "You do not have an offer from a FMD member to buy drugs.");
  35. if(!IsPlayerConnected(playerchoice[playerid]) || playerchoice[playerid] == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GREY, "Seller disconnected.");
  36. if(!IsPlayerInRangeOfPlayer(4.0, playerid, playerchoice[playerid])) return SendClientMessage(playerid, COLOR_GREY, "You are not near the player.");
  37. if(PlayerInfo[playerid][pCash] < playerprice[playerid]) return SendClientMessage(playerid, COLOR_GREY, "You can not afford this.");
  38. GiveMoney(playerid, -playerprice[playerid]);
  39. FMD += playerprice[playerid];
  40. if(drugschoice[playerid] == DRUGS_CHOICE_XANAX) PlayerInfo[playerid][pXanax] += playeramount[playerid];
  41. else if(drugschoice[playerid] == DRUGS_CHOICE_CANNABIS) PlayerInfo[playerid][pCannabis] += playeramount[playerid];
  42. new msg[100];
  43. format(msg, sizeof(msg), "You have bought %d %s for %d from paramedic %s", playeramount[playerid], GetOfferDrugsName(drugschoice[playerid]), playerprice[playerid], PlayerICName(playerchoice[playerid]));
  44. SendClientMessage(playerid, COLOR_LIGHTBLUE, msg);
  45. format(msg, sizeof(msg), "%s has bought %d %s from you (FMD bank earning: %d).", PlayerICName(playerid), playeramount[playerid], GetOfferDrugsName(drugschoice[playerid]), playerprice[playerid]);
  46. SendClientMessage(playerchoice[playerid], COLOR_LIGHTBLUE, msg);
  47. new query[200], day, month, year, hour, minute, second, dstr[40];
  48. gettime(hour, minute, second);
  49. getdate(year, month, day);
  50. format(dstr, sizeof(dstr), "%d/%d/%d %d:%d:%d", day, month, year, hour, minute, second);
  51. mysql_format(sqlGameConnection, query, sizeof(query), "INSERT INTO `fmddrugs` (`Name`, `GivenBy`, `Date`, `Type`, `Amount`, `Price`) VALUES('%e', '%e', '%e', '%e', %d, %d)", PlayerOOCName(playerid), PlayerOOCName(playerchoice[playerid]), dstr, GetOfferDrugsName(drugschoice[playerid]), playeramount[playerid], playerprice[playerid]);
  52. mysql_pquery(sqlGameConnection, query, "FMDDrugsLog", "sssdd", PlayerOOCName(playerid), PlayerOOCName(playerchoice[playerid]), GetOfferDrugsName(drugschoice[playerid]), playeramount[playerid], playerprice[playerid]);
  53. playerchoice[playerid] = -1;
  54. return 1;
  55. }
  56. forward FMDDrugsLog(player[], givenby[], drug[], amount, price);
  57. public FMDDrugsLog(player[], givenby[], drug[], amount, price)
  58. {
  59. printf("%s has been given %d %s by %s for $%d (FMD Sale)", player, amount, drug, givenby, price);
  60. new msg[128];
  61. format(msg, sizeof(msg), "{FF0000}AdmWarning{FFFFFF}: %s has been given %d %s by %s for $%d (FMD Sale)", player, amount, drug, givenby, price);
  62. SendAdminMessage(-1, msg);
  63. return 1;
  64. }
  65. Hook:fmddrugs_OnPlayerConnect(playerid)
  66. {
  67. playerchoice[playerid] = -1;
  68. return 1;
  69. }
  70. Hook:fmddrugs_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  71. {
  72. if(dialogid == DIALOG_FMD_DRUGS)
  73. {
  74. if(response)
  75. {
  76. switch(listitem)
  77. {
  78. // give drugs
  79. case 0:
  80. {
  81. ShowPlayerDialog(playerid, DIALOG_FMD_DRUGS_CHOOSE, DIALOG_STYLE_LIST, "{FF8282}Which drugs would you like to give?", "{FFFFFF}Xanax\nCannabis", "Select", "Cancel");
  82. }
  83. // check drugs logs
  84. case 1:
  85. {
  86. new query[128], Name[24], GivenBy[24], rows, fields, cstr[5000], Date[24], Cache:result, amount, price;
  87. mysql_format(sqlGameConnection, query, sizeof(query), "SELECT * FROM `fmddrugs` ORDER BY `ID` DESC LIMIT 50");
  88. result = mysql_query(sqlGameConnection, query);
  89. cache_get_data(rows, fields, sqlGameConnection);
  90. if(!rows) return SendMDCMessage(playerid, "No logs on record.");
  91. format(cstr, sizeof(cstr), "Date\t\tName\t\tGiven By\t\tAmount | Price\n");
  92. for(new i = 0; i < rows; i++)
  93. {
  94. cache_get_field_content(i, "Name", Name);
  95. cache_get_field_content(i, "GivenBy", GivenBy);
  96. cache_get_field_content(i, "Date", Date);
  97. amount = cache_get_field_content_int(i, "Amount");
  98. price = cache_get_field_content_int(i, "Price");
  99. format(cstr, sizeof(cstr), "%s{FF8282}(%s)\t{FF8282}%s\t{FF8282}%s\t{FF8282}%d | $%d\n", cstr, Date, Name, GivenBy, amount, price);
  100. }
  101. ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_TABLIST_HEADERS, "{FF8282}FMD Drugs Database", cstr, "Okay", "");
  102. cache_delete(Cache:result, sqlGameConnection);
  103. }
  104. }
  105. }
  106. }
  107. if(dialogid == DIALOG_FMD_DRUGS_CHOOSE)
  108. {
  109. if(response)
  110. {
  111. if(listitem == 0) drugschoice[playerid] = DRUGS_CHOICE_XANAX;
  112. else if(listitem == 1) drugschoice[playerid] = DRUGS_CHOICE_CANNABIS;
  113. ShowPlayerDialog(playerid, DIALOG_FMD_DRUGS_PLAYER, DIALOG_STYLE_INPUT, "Player ID", "{FFFFFF}Please enter the ID of the player", "Next", "Cancel");
  114. }
  115. }
  116. if(dialogid == DIALOG_FMD_DRUGS_PLAYER)
  117. {
  118. if(response)
  119. {
  120. new input = strval(inputtext);
  121. if(!IsNumeric(inputtext) || !IsPlayerConnected(input) || input == INVALID_PLAYER_ID)
  122. {
  123. SendClientMessage(playerid, COLOR_GREY, "Invalid player ID.");
  124. return ShowPlayerDialog(playerid, DIALOG_FMD_DRUGS_PLAYER, DIALOG_STYLE_INPUT, "Player ID", "{FFFFFF}Please enter the ID of the player", "Next", "Cancel");
  125. }
  126. else if(PlayerInfo[input][pMember] == FACTION_FMD)
  127. {
  128. SendClientMessage(playerid, COLOR_GREY, "You may not sell drugs to other FMD members.");
  129. return ShowPlayerDialog(playerid, DIALOG_FMD_DRUGS_PLAYER, DIALOG_STYLE_INPUT, "Player ID", "{FFFFFF}Please enter the ID of the player", "Next", "Cancel");
  130. }
  131. else if(input == playerid)
  132. {
  133. SendClientMessage(playerid, COLOR_GREY, "You may not sell drugs to yourself.");
  134. return ShowPlayerDialog(playerid, DIALOG_FMD_DRUGS_PLAYER, DIALOG_STYLE_INPUT, "Player ID", "{FFFFFF}Please enter the ID of the player", "Next", "Cancel");
  135. }
  136. else
  137. {
  138. playerchoice[playerid] = input;
  139. ShowPlayerDialog(playerid, DIALOG_FMD_DRUGS_AMOUNT, DIALOG_STYLE_INPUT, "Drugs Amount", "{FFFFFF}Please enter the amount of drugs", "Next", "Cancel");
  140. }
  141. }
  142. }
  143. if(dialogid == DIALOG_FMD_DRUGS_AMOUNT)
  144. {
  145. if(response)
  146. {
  147. new input = strval(inputtext);
  148. if(!IsNumeric(inputtext) || input < 1 || input > 20)
  149. {
  150. SendClientMessage(playerid, COLOR_GREY, "Invalid amount (amount must be between 1-20)");
  151. return ShowPlayerDialog(playerid, DIALOG_FMD_DRUGS_AMOUNT, DIALOG_STYLE_INPUT, "Drugs Amount", "{FFFFFF}Please enter the amount of drugs", "Next", "Cancel");
  152. }
  153. else
  154. {
  155. playeramount[playerid] = input;
  156. ShowPlayerDialog(playerid, DIALOG_FMD_DRUGS_PRICE, DIALOG_STYLE_INPUT, "Drugs Price", "{FFFFFF}Please enter the price for the drugs", "Done", "Cancel");
  157. }
  158. }
  159. }
  160. if(dialogid == DIALOG_FMD_DRUGS_PRICE)
  161. if(response)
  162. {
  163. new input = strval(inputtext);
  164. if(!IsNumeric(inputtext) || input < 5000 || input > 100000)
  165. {
  166. SendClientMessage(playerid, COLOR_GREY, "Invalid price (price must be between $5,000 and $100,000)");
  167. return ShowPlayerDialog(playerid, DIALOG_FMD_DRUGS_PRICE, DIALOG_STYLE_INPUT, "Drugs Price", "{FFFFFF}Please enter the price for the drugs", "Done", "Cancel");
  168. }
  169. else
  170. {
  171. new msg[100];
  172. playerprice[playerid] = input;
  173. if(!IsPlayerConnected(playerchoice[playerid]) || playerchoice[playerid] == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GREY, "Player disconnected.");
  174. new target = playerchoice[playerid];
  175. format(msg, sizeof(msg), "%s has offered to sell you %d drugs (%s) for $%d (/buyfmddrugs to accept)", PlayerICName(playerid), playeramount[playerid], GetOfferDrugsName(drugschoice[playerid]), playerprice[playerid]);
  176. SendClientMessage(target, COLOR_LIGHTBLUE, msg);
  177. format(msg, sizeof(msg), "You have offered to sell %s %d %s for $%d.", PlayerICName(target), playeramount[playerid], GetOfferDrugsName(drugschoice[playerid]), playerprice[playerid]);
  178. SendClientMessage(playerid, COLOR_LIGHTBLUE, msg);
  179. playerchoice[target] = playerid;
  180. drugschoice[target] = drugschoice[playerid];
  181. playeramount[target] = playeramount[playerid];
  182. playerprice[target] = playerprice[playerid];
  183. }
  184. }
  185. return 1;
  186. }