syndicate_safe.inc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. file: syndicate_safe.inc
  3. description: A safe to hold drugs for the Syndicate group (requested)
  4. author: Jay Cortez
  5. date created: 27th February 2018
  6. */
  7. #define SYNSAFE_FILE "syndicate_safe.ini"
  8. #define SYNSAFE_MAX_COKE 3000
  9. #define SYNSAFE_MAX_METH 3000
  10. #define SYNSAFE_MAX_CANNABIS 3000
  11. enum syndicateSafeEnum {
  12. s_Coke,
  13. s_Meth,
  14. s_Cannabis,
  15. bool:s_Loaded
  16. };
  17. new SyndicateSafe[syndicateSafeEnum];
  18. // Call the load function on gamemode init
  19. Hook:syndsafe_OnGameModeInit() {
  20. SyndicateSafe[s_Loaded] = false;
  21. LoadSyndicateSafe();
  22. }
  23. // Command to interact with the safe
  24. CMD:gsafe(playerid, params[]) {
  25. if(PlayerInfo[playerid][pGroup] != GROUP_CRIME)
  26. return AdmErrorMsg;
  27. if(!SyndicateSafe[s_Loaded])
  28. return SendClientMessage(playerid, COLOR_GREY, "Safe contents could not be loaded. Please contact a developer.");
  29. #if DEVMODE == 0
  30. if(!IsPlayerNearSyndicateHQ(playerid))
  31. return SendClientMessage(playerid, COLOR_GREY, "You are not at the safe.");
  32. #endif
  33. new actionStr[20], actionItem[20], actionItemAmount;
  34. if(sscanf(params, "s[20]s[20]i", actionStr, actionItem, actionItemAmount)) {
  35. SendClientMessage(playerid, COLOR_GREY, "{00BFFF}Usage:{FFFFFF} /syndi(cate)safe [put/get] [coke/meth/cannabis] [amount]");
  36. new infoStr[128];
  37. format(infoStr, sizeof(infoStr), "Safe contents: %i.0g Coke, %i.0g Meth, %i.0g Cannabis.",
  38. SyndicateSafe[s_Coke],
  39. SyndicateSafe[s_Meth],
  40. SyndicateSafe[s_Cannabis]
  41. );
  42. SendClientMessage(playerid, COLOR_LIGHTBLUE, infoStr);
  43. // Action
  44. format(infoStr, sizeof(infoStr), "* %s opens the safe and checks what's inside.", PlayerICName(playerid));
  45. SetPlayerChatBubble(playerid, infoStr, COLOR_PURPLE, 20.0, 15000);
  46. return 1;
  47. }
  48. if(actionItemAmount < 1)
  49. return SendClientMessage(playerid, COLOR_GREY, "Invalid amount.");
  50. new infoStr[128];
  51. // Store items
  52. if(strmatch(actionStr, "put")) {
  53. if(strmatch(actionItem, "coke")) {
  54. if(PlayerInfo[playerid][pCocaine] < actionItemAmount)
  55. return SendClientMessage(playerid, COLOR_GREY, "You do not have enough coke.");
  56. if(SyndicateSafe[s_Coke] + actionItemAmount > SYNSAFE_MAX_COKE)
  57. return SendClientMessage(playerid, COLOR_GREY, "The safe cannot hold this much coke.");
  58. PlayerInfo[playerid][pCocaine] -= actionItemAmount;
  59. SyndicateSafe[s_Coke] += actionItemAmount;
  60. format(actionItem, sizeof(actionItem), "coke");
  61. }
  62. else if(strmatch(actionItem, "meth")) {
  63. if(PlayerInfo[playerid][pMeth] < actionItemAmount)
  64. return SendClientMessage(playerid, COLOR_GREY, "You do not have enough meth.");
  65. if(SyndicateSafe[s_Meth] + actionItemAmount > SYNSAFE_MAX_METH)
  66. return SendClientMessage(playerid, COLOR_GREY, "The safe cannot hold this much meth.");
  67. PlayerInfo[playerid][pMeth] -= actionItemAmount;
  68. SyndicateSafe[s_Meth] += actionItemAmount;
  69. format(actionItem, sizeof(actionItem), "meth");
  70. }
  71. else if(strmatch(actionItem, "cannabis")) {
  72. if(PlayerInfo[playerid][pCannabis] < actionItemAmount)
  73. return SendClientMessage(playerid, COLOR_GREY, "You do not have enough cannabis.");
  74. if(SyndicateSafe[s_Cannabis] + actionItemAmount > SYNSAFE_MAX_CANNABIS)
  75. return SendClientMessage(playerid, COLOR_GREY, "The safe cannot hold this much cannabis.");
  76. PlayerInfo[playerid][pCannabis] -= actionItemAmount;
  77. SyndicateSafe[s_Cannabis] += actionItemAmount;
  78. format(actionItem, sizeof(actionItem), "cannabis");
  79. }
  80. else return SendClientMessage(playerid, COLOR_GREY, "Invalid item.");
  81. // Send info message
  82. format(infoStr, sizeof(infoStr), "You have deposited %i.0g of %s into the locker.",
  83. actionItemAmount,
  84. actionItem
  85. );
  86. SendClientMessage(playerid, COLOR_LIGHTBLUE, infoStr);
  87. }
  88. // Retrieve items from safe
  89. else if(strmatch(actionStr, "get")) {
  90. if(strmatch(actionItem, "coke")) {
  91. if(SyndicateSafe[s_Coke] < actionItemAmount)
  92. return SendClientMessage(playerid, COLOR_GREY, "There is not enough coke in the safe.");
  93. PlayerInfo[playerid][pCocaine] += actionItemAmount;
  94. SyndicateSafe[s_Coke] -= actionItemAmount;
  95. format(actionItem, sizeof(actionItem), "coke");
  96. }
  97. else if(strmatch(actionItem, "meth")) {
  98. if(SyndicateSafe[s_Meth] < actionItemAmount)
  99. return SendClientMessage(playerid, COLOR_GREY, "There is not enough meth in safe.");
  100. PlayerInfo[playerid][pMeth] += actionItemAmount;
  101. SyndicateSafe[s_Meth] -= actionItemAmount;
  102. format(actionItem, sizeof(actionItem), "meth");
  103. }
  104. else if(strmatch(actionItem, "cannabis")) {
  105. if(SyndicateSafe[s_Cannabis] < actionItemAmount)
  106. return SendClientMessage(playerid, COLOR_GREY, "There is not enough cannabis in the safe.");
  107. PlayerInfo[playerid][pCannabis] += actionItemAmount;
  108. SyndicateSafe[s_Cannabis] -= actionItemAmount;
  109. format(actionItem, sizeof(actionItem), "cannabis");
  110. }
  111. else return SendClientMessage(playerid, COLOR_GREY, "Invalid item.");
  112. // Send info message
  113. format(infoStr, sizeof(infoStr), "You have taken %i.0g of %s from the locker.",
  114. actionItemAmount,
  115. actionItem
  116. );
  117. SendClientMessage(playerid, COLOR_LIGHTBLUE, infoStr);
  118. }
  119. SaveSyndicateSafe();
  120. return 1;
  121. }
  122. // Loads the syndicate safe contents
  123. LoadSyndicateSafe() {
  124. if(dini_Exists(SYNSAFE_FILE)) {
  125. SyndicateSafe[s_Coke] = dini_Int(SYNSAFE_FILE, "s_Coke");
  126. SyndicateSafe[s_Meth] = dini_Int(SYNSAFE_FILE, "s_Meth");
  127. SyndicateSafe[s_Cannabis] = dini_Int(SYNSAFE_FILE, "s_Cannabis");
  128. }
  129. SyndicateSafe[s_Loaded] = true;
  130. }
  131. // Saves the contents of the syndicate safe
  132. SaveSyndicateSafe() {
  133. if(!dini_Exists(SYNSAFE_FILE)) dini_Create(SYNSAFE_FILE);
  134. dini_IntSet(SYNSAFE_FILE, "s_Coke", SyndicateSafe[s_Coke]);
  135. dini_IntSet(SYNSAFE_FILE, "s_Meth", SyndicateSafe[s_Meth]);
  136. dini_IntSet(SYNSAFE_FILE, "s_Cannabis", SyndicateSafe[s_Cannabis]);
  137. }