CheezPuff

[Free] Frag JB Wish v1.1 [By CheezPuff]

Jul 13th, 2024 (edited)
1,427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.27 KB | None | 0 0
  1. /*
  2.     Frag JailBreak Wish System v1.1
  3.     - Fixed set_task return value (void) -- now uses TASK_REWARD + id as task ID
  4.     - Fixed task_exists() not in AMXX -- replaced with direct remove_task()
  5.     - Fixed parse() with int variables -- now parses to strings then str_to_num()
  6.     - Fixed "1,000 Cash" comma breaking str_to_num() -- rewards now use index + enum
  7.     - Fixed FinishWish re-calling CanMakeWish -- wishes_used stored in global array
  8. */
  9.  
  10. #include <amxmodx>
  11. #include <amxmisc>
  12. #include <nvault>
  13. #include <fun>
  14.  
  15. #define PLUGIN   "Frag JailBreak Wish System"
  16. #define VERSION  "1.1"
  17. #define AUTHOR   "CheezPuff"
  18.  
  19. #define WISH_COOLDOWN          3600
  20. #define VAULT_NAME             "wish_system"
  21. #define MAX_WISHES             2
  22. #define REWARD_LOOP_TIME       5.0
  23. #define REWARD_CHANGE_INTERVAL 0.2
  24.  
  25. #define TASK_REWARD_LOOP  5000   // 5000 + id
  26. #define TASK_FINISH_WISH  6000   // 6000 + id
  27.  
  28. // Reward indexes
  29. #define REWARD_CASH_1000   0
  30. #define REWARD_CASH_5000   1
  31. #define REWARD_CASH_10000  2
  32. #define REWARD_CASH_25000  3
  33. #define REWARD_CASH_45000  4
  34. #define REWARD_ARMOR_100   5
  35. #define REWARD_EXTRA_WISH  6
  36. #define REWARD_NOTHING     7
  37. #define REWARD_COUNT       8
  38.  
  39. // Display names shown in HUD
  40. new const g_szRewardNames[REWARD_COUNT][] = {
  41.     "1,000 Cash",
  42.     "5,000 Cash",
  43.     "10,000 Cash",
  44.     "25,000 Cash",
  45.     "45,000 Cash",
  46.     "100 Armor",
  47.     "Extra Wish",
  48.     "Nothing"
  49. }
  50.  
  51. // Actual values -- no parsing needed
  52. new const g_iRewardValues[REWARD_COUNT] = {
  53.     1000,
  54.     5000,
  55.     10000,
  56.     25000,
  57.     45000,
  58.     100,
  59.     0,
  60.     0
  61. }
  62.  
  63. new g_szAuthID[33][35]
  64. new g_szIP[33][16]
  65. new g_iPlayerCash[33]
  66. new g_iCurrentReward[33]
  67. new g_iWishesUsed[33]
  68. new g_iVault
  69.  
  70. // -------------------------------------------------------------------------
  71.  
  72. public plugin_init() {
  73.     register_plugin(PLUGIN, VERSION, AUTHOR)
  74.  
  75.     g_iVault = nvault_open(VAULT_NAME)
  76.     if(g_iVault == INVALID_HANDLE)
  77.         set_fail_state("[Wish] Failed to open vault!")
  78.  
  79.     register_clcmd("say /wish", "CmdWish")
  80.     register_concmd("wish_reset", "CmdResetWishes", ADMIN_RCON, "- Reset all wish timers")
  81. }
  82.  
  83. public plugin_end() {
  84.     nvault_close(g_iVault)
  85. }
  86.  
  87. public client_authorized(id) {
  88.     get_user_authid(id, g_szAuthID[id], charsmax(g_szAuthID[]))
  89.     get_user_ip(id, g_szIP[id], charsmax(g_szIP[]), 1)
  90.     g_iWishesUsed[id] = 0
  91.     LoadWishData(id)
  92. }
  93.  
  94. public client_disconnected(id) {
  95.     remove_task(TASK_REWARD_LOOP + id)
  96.     remove_task(TASK_FINISH_WISH + id)
  97. }
  98.  
  99. // -------------------------------------------------------------------------
  100.  
  101. stock LoadWishData(id) {
  102.     new data[64], szWishes[8], szTime[16], szCash[16]
  103.     if(nvault_get(g_iVault, g_szAuthID[id], data, charsmax(data))) {
  104.         parse(data, szWishes, charsmax(szWishes), szTime, charsmax(szTime), szCash, charsmax(szCash))
  105.         new wishes   = str_to_num(szWishes)
  106.         new lastTime = str_to_num(szTime)
  107.  
  108.         // Reset if cooldown passed
  109.         if(wishes >= MAX_WISHES && get_systime() - lastTime >= WISH_COOLDOWN)
  110.             wishes = 0
  111.  
  112.         g_iWishesUsed[id] = wishes
  113.         g_iPlayerCash[id] = str_to_num(szCash)
  114.     }
  115. }
  116.  
  117. stock SaveWishData(id) {
  118.     new data[64]
  119.     formatex(data, charsmax(data), "%d %d %d", g_iWishesUsed[id], get_systime(), g_iPlayerCash[id])
  120.     nvault_set(g_iVault, g_szAuthID[id], data)
  121.     nvault_set(g_iVault, g_szIP[id], data)
  122. }
  123.  
  124. // -------------------------------------------------------------------------
  125.  
  126. public CmdWish(id) {
  127.     if(g_iWishesUsed[id] >= MAX_WISHES) {
  128.         new data[64], szWishes[8], szTime[16]
  129.         if(nvault_get(g_iVault, g_szAuthID[id], data, charsmax(data))) {
  130.             parse(data, szWishes, charsmax(szWishes), szTime, charsmax(szTime))
  131.             new lastTime  = str_to_num(szTime)
  132.             new remaining = WISH_COOLDOWN - (get_systime() - lastTime)
  133.             if(remaining > 0) {
  134.                 client_print(id, print_chat, "[Wish] Wait %d:%02d before wishing again.", remaining / 60, remaining % 60)
  135.                 return PLUGIN_HANDLED
  136.             }
  137.             // Cooldown passed -- reset
  138.             g_iWishesUsed[id] = 0
  139.         }
  140.     }
  141.  
  142.     if(task_exists(TASK_REWARD_LOOP + id) || task_exists(TASK_FINISH_WISH + id)) {
  143.         client_print(id, print_chat, "[Wish] Wish already in progress!")
  144.         return PLUGIN_HANDLED
  145.     }
  146.  
  147.     StartWishProcess(id)
  148.     return PLUGIN_HANDLED
  149. }
  150.  
  151. StartWishProcess(id) {
  152.     g_iCurrentReward[id] = 0
  153.  
  154.     set_hudmessage(0, 255, 255, -1.0, 0.2, 0, 0.1, 0.25, 0.0, 0.0, -1)
  155.     show_hudmessage(id, "Frag JailBreak - Wish^nGood Luck!^n^n>> %s <<^n^n%d Cash",
  156.         g_szRewardNames[g_iCurrentReward[id]], g_iPlayerCash[id])
  157.  
  158.     set_task(REWARD_CHANGE_INTERVAL, "TaskChangeReward", TASK_REWARD_LOOP + id, _, _, "b")
  159.     set_task(REWARD_LOOP_TIME,       "TaskFinishWish",   TASK_FINISH_WISH + id)
  160. }
  161.  
  162. public TaskChangeReward(taskid) {
  163.     new id = taskid - TASK_REWARD_LOOP
  164.     if(!is_user_connected(id)) {
  165.         remove_task(TASK_REWARD_LOOP + id)
  166.         return
  167.     }
  168.     g_iCurrentReward[id] = random(REWARD_COUNT)
  169.     set_hudmessage(0, 255, 255, -1.0, 0.2, 0, 0.1, 0.25, 0.0, 0.0, -1)
  170.     show_hudmessage(id, "Frag JailBreak - Wish^nGood Luck!^n^n>> %s <<^n^n%d Cash",
  171.         g_szRewardNames[g_iCurrentReward[id]], g_iPlayerCash[id])
  172. }
  173.  
  174. public TaskFinishWish(taskid) {
  175.     new id = taskid - TASK_FINISH_WISH
  176.     remove_task(TASK_REWARD_LOOP + id)
  177.  
  178.     if(!is_user_connected(id)) return
  179.  
  180.     ApplyReward(id, g_iCurrentReward[id])
  181.  
  182.     g_iWishesUsed[id]++
  183.     SaveWishData(id)
  184.  
  185.     new remaining = MAX_WISHES - g_iWishesUsed[id]
  186.     set_hudmessage(0, 255, 255, -1.0, 0.2, 0, 6.0, 5.0, 0.1, 0.2, -1)
  187.     show_hudmessage(id, "Frag JailBreak - Wish^nResult: %s^n^n>%d Wishes left<^n^n%d Cash",
  188.         g_szRewardNames[g_iCurrentReward[id]], remaining, g_iPlayerCash[id])
  189. }
  190.  
  191. // -------------------------------------------------------------------------
  192.  
  193. ApplyReward(id, reward) {
  194.     switch(reward) {
  195.         case REWARD_CASH_1000,
  196.              REWARD_CASH_5000,
  197.              REWARD_CASH_10000,
  198.              REWARD_CASH_25000,
  199.              REWARD_CASH_45000: {
  200.             g_iPlayerCash[id] += g_iRewardValues[reward]
  201.             client_print(id, print_chat, "[Wish] You won %d Cash!", g_iRewardValues[reward])
  202.         }
  203.         case REWARD_ARMOR_100: {
  204.             new newArmor = get_user_armor(id) + g_iRewardValues[reward]
  205.             if(newArmor > 200) newArmor = 200
  206.             set_user_armor(id, newArmor)
  207.             client_print(id, print_chat, "[Wish] You won %d Armor!", g_iRewardValues[reward])
  208.         }
  209.         case REWARD_EXTRA_WISH: {
  210.             if(g_iWishesUsed[id] > 0) g_iWishesUsed[id]--
  211.             client_print(id, print_chat, "[Wish] You won an Extra Wish!")
  212.         }
  213.         case REWARD_NOTHING: {
  214.             client_print(id, print_chat, "[Wish] Better luck next time! You won nothing.")
  215.         }
  216.     }
  217. }
  218.  
  219. // -------------------------------------------------------------------------
  220.  
  221. public CmdResetWishes(id, level, cid) {
  222.     if(!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED
  223.     nvault_prune(g_iVault, 0, get_systime() + 1)
  224.     for(new i = 1; i <= MaxClients; i++)
  225.         g_iWishesUsed[i] = 0
  226.     client_print(id, print_chat, "[Wish] All wish timers reset.")
  227.     return PLUGIN_HANDLED
  228. }
  229.  
Advertisement
Add Comment
Please, Sign In to add comment