1
0

GovArms.pwn 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. #include <YSI\y_hooks>
  2. /*
  3. BRIEFING (TIM)
  4. Jingles I have a very important update that if possible I would like pushed to the top of the list.
  5. There needs to be a booth at city hall players can sell their weapons back to the government.
  6. Gov leaders need to be able to set a buyback price for each gun and I would prefer a command that lets
  7. this stay in place and government leaders can do a command to start/stop the program.
  8. I want all sales to be logged as well so government can issue these weapons to factions in the future,
  9. and a counter made with the total sales of each gun. Also make it so if they set the price to 0 it wont allow players \
  10. to sell that gun. Make the money come out of the government vault as well. Thanks!
  11. */
  12. new arrWeaponCosts[47]; // array to store the costs in (NOTE: 46 has the open/close value!!)
  13. new GovArmsPoint;
  14. hook OnGameModeInit()
  15. {
  16. GovGuns_Streamer();
  17. return 1;
  18. }
  19. hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  20. if(arrAntiCheat[playerid][ac_iFlags][AC_DIALOGSPOOFING] > 0) return 1;
  21. switch(dialogid)
  22. {
  23. case DIALOG_GOVGUN_MAIN:
  24. {
  25. if(response) switch(listitem)
  26. {
  27. case 0: return mysql_tquery(MainPipeline, "SELECT * FROM `govgunsales` WHERE 1", "GovGuns_OnShowSales", "i", playerid);
  28. case 1:
  29. {
  30. GovGuns_EditPrices(playerid);
  31. }
  32. case 2:
  33. {
  34. szMiscArray[0] = 0;
  35. switch(arrWeaponCosts[46])
  36. {
  37. case 0:
  38. {
  39. arrWeaponCosts[46] = 1;
  40. format(szMiscArray, sizeof(szMiscArray), "%s has opened the Government Arms Center.", GetPlayerNameEx(playerid));
  41. SendGroupMessage(arrGroupData[PlayerInfo[playerid][pMember]][g_iGroupType], DEPTRADIO, szMiscArray);
  42. return 1;
  43. }
  44. default:
  45. {
  46. arrWeaponCosts[46] = 0;
  47. format(szMiscArray, sizeof(szMiscArray), "%s has closed the Government Arms Center.", GetPlayerNameEx(playerid));
  48. SendGroupMessage(arrGroupData[PlayerInfo[playerid][pMember]][g_iGroupType], DEPTRADIO, szMiscArray);
  49. return 1;
  50. }
  51. }
  52. }
  53. }
  54. }
  55. case DIALOG_GOVGUN_EDITPRICE:
  56. {
  57. if(response)
  58. {
  59. szMiscArray[0] = 0;
  60. new wepid = ListItemTrackId[playerid][listitem];
  61. SetPVarInt(playerid, "_GovGun", wepid);
  62. format(szMiscArray, sizeof(szMiscArray), "Edit the purchase price of the {00FFFF}%s {FFFFFF}\n\n Current purchase price: $%s", Weapon_ReturnName(wepid), number_format(arrWeaponCosts[wepid]));
  63. return ShowPlayerDialogEx(playerid, DIALOG_GOVGUN_EDITPRICE2, DIALOG_STYLE_INPUT, "Government Arms | Edit Weapon Price", szMiscArray, "Proceed", "Cancel");
  64. }
  65. }
  66. case DIALOG_GOVGUN_SELL:
  67. {
  68. if(response)
  69. {
  70. szMiscArray[0] = 0;
  71. new wepid = ListItemTrackId[playerid][listitem];
  72. SetPVarInt(playerid, "_GovGun", wepid);
  73. format(szMiscArray, sizeof(szMiscArray), "Are you sure you want to sell your %s for: {FF0000}$%s{FFFFFF}?", Weapon_ReturnName(wepid), number_format(arrWeaponCosts[wepid]));
  74. return ShowPlayerDialogEx(playerid, DIALOG_GOVGUN_SELL2, DIALOG_STYLE_MSGBOX, "Government Arms | Sell Gun", szMiscArray, "Sell", "Cancel");
  75. }
  76. }
  77. case DIALOG_GOVGUN_EDITPRICE2:
  78. {
  79. if(response)
  80. {
  81. szMiscArray[0] = 0;
  82. new wepid = GetPVarInt(playerid, "_GovGun");
  83. arrWeaponCosts[wepid] = strval(inputtext);
  84. mysql_format(MainPipeline, szMiscArray, sizeof(szMiscArray), "UPDATE `govgunsales` SET `wepprice` = %d WHERE `wepid` = %d", strval(inputtext), wepid);
  85. mysql_tquery(MainPipeline, szMiscArray, "OnQueryFinish", "ii", SENDDATA_THREAD, playerid);
  86. format(szMiscArray, sizeof(szMiscArray), "You have edited the %s's price to: {FFFFFF}$%s", Weapon_ReturnName(wepid), number_format(arrWeaponCosts[wepid]));
  87. SendClientMessageEx(playerid, COLOR_YELLOW, szMiscArray);
  88. DeletePVar(playerid, "_GovGun");
  89. return GovGuns_EditPrices(playerid);
  90. }
  91. }
  92. case DIALOG_GOVGUN_SELL2:
  93. {
  94. if(response)
  95. {
  96. szMiscArray[0] = 0;
  97. new iGroupID;
  98. for(iGroupID = 0; iGroupID < MAX_GROUPS; ++iGroupID)
  99. {
  100. if(arrGroupData[iGroupID][g_iGroupType] == 5) break;
  101. }
  102. new wepid = GetPVarInt(playerid, "_GovGun");
  103. if(arrGroupData[iGroupID][g_iBudget] < arrWeaponCosts[wepid]) return SendClientMessageEx(playerid, COLOR_GRAD1, "The government doesn't have enough funds to pay you.");
  104. GivePlayerCash(playerid, arrWeaponCosts[wepid]);
  105. RemovePlayerWeapon(playerid, wepid);
  106. arrGroupData[iGroupID][g_iBudget] -= arrWeaponCosts[wepid];
  107. format(szMiscArray, sizeof(szMiscArray), "%s sold their %s at a cost of $%d to %s's budget fund.",GetPlayerNameEx(playerid), Weapon_ReturnName(wepid), arrWeaponCosts[wepid], arrGroupData[iGroupID][g_szGroupName]);
  108. GroupPayLog(iGroupID, szMiscArray);
  109. szMiscArray[0] = 0; // unsure if this is needed.
  110. format(szMiscArray, sizeof(szMiscArray), "You have sold your %s for {FFFFFF}$%s", Weapon_ReturnName(wepid), number_format(arrWeaponCosts[wepid]));
  111. SendClientMessageEx(playerid, COLOR_YELLOW, szMiscArray);
  112. szMiscArray[0] = 0;
  113. mysql_format(MainPipeline, szMiscArray, sizeof(szMiscArray), "UPDATE `govgunsales` SET `wepsales` = `wepsales` + 1 WHERE `wepid` = %d", wepid);
  114. mysql_tquery(MainPipeline, szMiscArray, "OnQueryFinish", "ii", SENDDATA_THREAD, playerid);
  115. szMiscArray[0] = 0;
  116. format(szMiscArray, sizeof(szMiscArray), "%s sells their %s to the government.", GetPlayerNameEx(playerid), Weapon_ReturnName(wepid));
  117. ProxDetector(8.0, playerid, szMiscArray, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
  118. DeletePVar(playerid, "_GovGun");
  119. return 1;
  120. }
  121. }
  122. case DIALOG_GOVGUNS_SALES:
  123. {
  124. return GovGuns_MainMenu(playerid);
  125. }
  126. case ARMS_MENU: {
  127. if(!response) return SendClientMessageEx(playerid, COLOR_GREY, "You have left the government arms center.");
  128. switch(listitem) {
  129. case 0: {
  130. if(!response) return ShowArmsMenu(playerid);
  131. new szWeaponName[32],
  132. iCount, iAmmo, iWepID;
  133. if(!IsPlayerInRangeOfPoint(playerid, 5.0, 1464.3099, -1747.5853, 15.6267)) return SendClientMessageEx(playerid, COLOR_GRAD1, "You aren't at the government arms point at City Hall in Los Santos.");
  134. if(arrWeaponCosts[46] == 0) return SendClientMessageEx(playerid, COLOR_GRAD1, "The government arms center is currently closed.");
  135. szMiscArray = "Name\tSale Price\n";
  136. for(new i; i < 12; ++i) {
  137. GetPlayerWeaponData(playerid, i, iWepID, iAmmo);
  138. if(PlayerInfo[playerid][pGuns][i] == iWepID && GovGuns_IsSelling(iWepID)) {
  139. ListItemTrackId[playerid][iCount] = iWepID;
  140. szWeaponName = Weapon_ReturnName(iWepID);
  141. format(szMiscArray, sizeof(szMiscArray), "%s%s\t$%s\n", szMiscArray, szWeaponName, number_format(arrWeaponCosts[iWepID]));
  142. iCount++;
  143. }
  144. }
  145. if(iCount == 0) return SendClientMessageEx(playerid, COLOR_GRAD1, "You do not have any weapons that you can sell to the government.");
  146. ShowPlayerDialogEx(playerid, DIALOG_GOVGUN_SELL, DIALOG_STYLE_TABLIST_HEADERS, "Government Arms | Sell Gun", szMiscArray, "Cancel", "Sell");
  147. }
  148. case 1: {
  149. if(!response) return ShowArmsMenu(playerid);
  150. if(PlayerInfo[playerid][pGunLic] > gettime()) return SendClientMessageEx(playerid, COLOR_GRAD2, "You already have a valid gun license");
  151. ShowPlayerDialogEx(playerid, APPLY_GUN_LIC, DIALOG_STYLE_MSGBOX,
  152. "Gun License Application",
  153. "You are about to apply for a gun license\nYou will have a background check for crimes for the last 3 weeks\nThis process will cost $100,000",
  154. "Apply",
  155. "Cancel"
  156. );
  157. }
  158. }
  159. }
  160. }
  161. return 0;
  162. }
  163. GovGuns_MainMenu(playerid)
  164. {
  165. szMiscArray[0] = 0;
  166. switch(arrWeaponCosts[46])
  167. {
  168. case 0: szMiscArray = "{FF0000}Closed";
  169. case 1: szMiscArray = "{00FF00}Open";
  170. }
  171. format(szMiscArray, sizeof(szMiscArray), "List purchases\nEdit purchase prices\nOpen/Close Center (currently: %s{FFFFFF})", szMiscArray);
  172. return ShowPlayerDialogEx(playerid, DIALOG_GOVGUN_MAIN, DIALOG_STYLE_LIST, "Government Arms Center | Main Menu", szMiscArray, "Select", "");
  173. }
  174. GovGuns_LoadCosts()
  175. {
  176. mysql_tquery(MainPipeline, "SELECT * FROM `govgunsales` WHERE 1", "GovGuns_OnLoadCosts", "");
  177. return 1;
  178. }
  179. GovGuns_Streamer()
  180. {
  181. CreateDynamicObject(3430, 1464.40723, -1750.29785, 15.8659, 0.00000, 0.00000, 300.33374);
  182. CreateDynamic3DTextLabel("Government Arms Center\n{DDDDDD}Press ~k~~CONVERSATION_YES~ to access the menu", COLOR_YELLOW, 1464.3186,-1747.9330,15.9453, 8.0);
  183. GovArmsPoint = CreateDynamicSphere(1464.3186,-1747.9330,15.445, 5.00);
  184. }
  185. GovGuns_IsSellingEdit(i)
  186. {
  187. switch(i)
  188. {
  189. case 22 .. 34: return 1; // enter IDs of weapons that are enabled for sale.
  190. }
  191. return 0;
  192. }
  193. GovGuns_IsSelling(i)
  194. {
  195. switch(i)
  196. {
  197. case 22 .. 34: if(arrWeaponCosts[i] > 0) return 1; // enter IDs of weapons that are enabled for sale.
  198. }
  199. return 0;
  200. }
  201. GovGuns_EditPrices(playerid)
  202. {
  203. szMiscArray[0] = 0;
  204. new iCount;
  205. szMiscArray = "Name\tPurchase Price\n";
  206. for(new i; i < 46; ++i)
  207. {
  208. if(GovGuns_IsSellingEdit(i))
  209. {
  210. ListItemTrackId[playerid][iCount] = i;
  211. format(szMiscArray, sizeof(szMiscArray), "%s%s\t$%s\n", szMiscArray, Weapon_ReturnName(i), number_format(arrWeaponCosts[i]));
  212. iCount++;
  213. }
  214. }
  215. return ShowPlayerDialogEx(playerid, DIALOG_GOVGUN_EDITPRICE, DIALOG_STYLE_TABLIST_HEADERS, "Government Arms | Edit Purchase Price", szMiscArray, "Edit", "Cancel");
  216. }
  217. forward GovGuns_OnLoadCosts();
  218. public GovGuns_OnLoadCosts()
  219. {
  220. new iRows, iCount;
  221. cache_get_row_count(iRows);
  222. while(iCount < iRows)
  223. {
  224. cache_get_value_name_int(iCount, "wepprice", arrWeaponCosts[iCount]);
  225. iCount++;
  226. }
  227. printf("[Gov Weapon Prices] Loaded %i Weapons", iCount);
  228. return 1;
  229. }
  230. forward GovGuns_OnShowSales(playerid);
  231. public GovGuns_OnShowSales(playerid)
  232. {
  233. new iRows, iCount;
  234. cache_get_row_count(iRows);
  235. if(!iRows) return SendClientMessageEx(playerid, COLOR_GRAD1, "Something went wrong. Please try again later.");
  236. szMiscArray = "Name\tSold\n";
  237. while(iCount < iRows)
  238. {
  239. if(GovGuns_IsSellingEdit(iCount))
  240. {
  241. new value;
  242. format(szMiscArray, sizeof(szMiscArray), "%s%s\t%spc\n", szMiscArray, Weapon_ReturnName(iCount), number_format(cache_get_value_name_int(iCount, "wepsales", value)));
  243. }
  244. iCount++;
  245. }
  246. return ShowPlayerDialogEx(playerid, DIALOG_GOVGUNS_SALES, DIALOG_STYLE_TABLIST_HEADERS, "Government Arms | Sales", szMiscArray, "<<", "");
  247. }
  248. CMD:govarms(playerid, params[])
  249. {
  250. if(IsAGovernment(playerid) && PlayerInfo[playerid][pMember] == PlayerInfo[playerid][pLeader])
  251. {
  252. GovGuns_MainMenu(playerid);
  253. }
  254. else SendClientMessageEx(playerid, COLOR_GRAD1, "You are not a leader in the government.");
  255. return 1;
  256. }
  257. /*CMD:sellgovgun(playerid, params[])
  258. {
  259. szMiscArray[0] = 0;
  260. new szWeaponName[32],
  261. iCount, iAmmo, iWepID;
  262. if(!IsPlayerInRangeOfPoint(playerid, 5.0, 1464.3099, -1747.5853, 15.6267)) return SendClientMessageEx(playerid, COLOR_GRAD1, "You aren't at the government arms point at City Hall in Los Santos.");
  263. if(arrWeaponCosts[46] == 0) return SendClientMessageEx(playerid, COLOR_GRAD1, "The government arms center is currently closed.");
  264. szMiscArray = "Name\tSale Price\n";
  265. for(new i; i < 12; ++i)
  266. {
  267. GetPlayerWeaponData(playerid, i, iWepID, iAmmo);
  268. if(PlayerInfo[playerid][pGuns][i] == iWepID && GovGuns_IsSelling(iWepID))
  269. {
  270. ListItemTrackId[playerid][iCount] = iWepID;
  271. szWeaponName = Weapon_ReturnName(iWepID);
  272. format(szMiscArray, sizeof(szMiscArray), "%s%s\t$%s\n", szMiscArray, szWeaponName, number_format(arrWeaponCosts[iWepID]));
  273. iCount++;
  274. }
  275. }
  276. if(iCount == 0) return SendClientMessageEx(playerid, COLOR_GRAD1, "You do not have any weapons that you can sell to the government.");
  277. ShowPlayerDialogEx(playerid, DIALOG_GOVGUN_SELL, DIALOG_STYLE_TABLIST_HEADERS, "Government Arms | Sell Gun", szMiscArray, "Cancel", "Sell");
  278. return 1;
  279. }*/
  280. ShowArmsMenu(playerid) {
  281. szMiscArray[0] = 0;
  282. format(szMiscArray, sizeof(szMiscArray), "{FF8000}** {C2A2DA}%s approaches the ATM, typing in their PIN.", GetPlayerNameEx(playerid));
  283. SetPlayerChatBubble(playerid, szMiscArray, COLOR_PURPLE, 15.0, 5000);
  284. ShowPlayerDialogEx(playerid, ARMS_MENU, DIALOG_STYLE_LIST, "Arms Menu", "Sell gun to gov\nFirearm License", "Select", "Cancel");
  285. return 1;
  286. }
  287. hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
  288. if(newkeys & KEY_YES && IsPlayerInDynamicArea(playerid, GovArmsPoint)) {
  289. ShowArmsMenu(playerid);
  290. }
  291. return 1;
  292. }