Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Frag JailBreak Wish System v1.1
- - Fixed set_task return value (void) -- now uses TASK_REWARD + id as task ID
- - Fixed task_exists() not in AMXX -- replaced with direct remove_task()
- - Fixed parse() with int variables -- now parses to strings then str_to_num()
- - Fixed "1,000 Cash" comma breaking str_to_num() -- rewards now use index + enum
- - Fixed FinishWish re-calling CanMakeWish -- wishes_used stored in global array
- */
- #include <amxmodx>
- #include <amxmisc>
- #include <nvault>
- #include <fun>
- #define PLUGIN "Frag JailBreak Wish System"
- #define VERSION "1.1"
- #define AUTHOR "CheezPuff"
- #define WISH_COOLDOWN 3600
- #define VAULT_NAME "wish_system"
- #define MAX_WISHES 2
- #define REWARD_LOOP_TIME 5.0
- #define REWARD_CHANGE_INTERVAL 0.2
- #define TASK_REWARD_LOOP 5000 // 5000 + id
- #define TASK_FINISH_WISH 6000 // 6000 + id
- // Reward indexes
- #define REWARD_CASH_1000 0
- #define REWARD_CASH_5000 1
- #define REWARD_CASH_10000 2
- #define REWARD_CASH_25000 3
- #define REWARD_CASH_45000 4
- #define REWARD_ARMOR_100 5
- #define REWARD_EXTRA_WISH 6
- #define REWARD_NOTHING 7
- #define REWARD_COUNT 8
- // Display names shown in HUD
- new const g_szRewardNames[REWARD_COUNT][] = {
- "1,000 Cash",
- "5,000 Cash",
- "10,000 Cash",
- "25,000 Cash",
- "45,000 Cash",
- "100 Armor",
- "Extra Wish",
- "Nothing"
- }
- // Actual values -- no parsing needed
- new const g_iRewardValues[REWARD_COUNT] = {
- 1000,
- 5000,
- 10000,
- 25000,
- 45000,
- 100,
- 0,
- 0
- }
- new g_szAuthID[33][35]
- new g_szIP[33][16]
- new g_iPlayerCash[33]
- new g_iCurrentReward[33]
- new g_iWishesUsed[33]
- new g_iVault
- // -------------------------------------------------------------------------
- public plugin_init() {
- register_plugin(PLUGIN, VERSION, AUTHOR)
- g_iVault = nvault_open(VAULT_NAME)
- if(g_iVault == INVALID_HANDLE)
- set_fail_state("[Wish] Failed to open vault!")
- register_clcmd("say /wish", "CmdWish")
- register_concmd("wish_reset", "CmdResetWishes", ADMIN_RCON, "- Reset all wish timers")
- }
- public plugin_end() {
- nvault_close(g_iVault)
- }
- public client_authorized(id) {
- get_user_authid(id, g_szAuthID[id], charsmax(g_szAuthID[]))
- get_user_ip(id, g_szIP[id], charsmax(g_szIP[]), 1)
- g_iWishesUsed[id] = 0
- LoadWishData(id)
- }
- public client_disconnected(id) {
- remove_task(TASK_REWARD_LOOP + id)
- remove_task(TASK_FINISH_WISH + id)
- }
- // -------------------------------------------------------------------------
- stock LoadWishData(id) {
- new data[64], szWishes[8], szTime[16], szCash[16]
- if(nvault_get(g_iVault, g_szAuthID[id], data, charsmax(data))) {
- parse(data, szWishes, charsmax(szWishes), szTime, charsmax(szTime), szCash, charsmax(szCash))
- new wishes = str_to_num(szWishes)
- new lastTime = str_to_num(szTime)
- // Reset if cooldown passed
- if(wishes >= MAX_WISHES && get_systime() - lastTime >= WISH_COOLDOWN)
- wishes = 0
- g_iWishesUsed[id] = wishes
- g_iPlayerCash[id] = str_to_num(szCash)
- }
- }
- stock SaveWishData(id) {
- new data[64]
- formatex(data, charsmax(data), "%d %d %d", g_iWishesUsed[id], get_systime(), g_iPlayerCash[id])
- nvault_set(g_iVault, g_szAuthID[id], data)
- nvault_set(g_iVault, g_szIP[id], data)
- }
- // -------------------------------------------------------------------------
- public CmdWish(id) {
- if(g_iWishesUsed[id] >= MAX_WISHES) {
- new data[64], szWishes[8], szTime[16]
- if(nvault_get(g_iVault, g_szAuthID[id], data, charsmax(data))) {
- parse(data, szWishes, charsmax(szWishes), szTime, charsmax(szTime))
- new lastTime = str_to_num(szTime)
- new remaining = WISH_COOLDOWN - (get_systime() - lastTime)
- if(remaining > 0) {
- client_print(id, print_chat, "[Wish] Wait %d:%02d before wishing again.", remaining / 60, remaining % 60)
- return PLUGIN_HANDLED
- }
- // Cooldown passed -- reset
- g_iWishesUsed[id] = 0
- }
- }
- if(task_exists(TASK_REWARD_LOOP + id) || task_exists(TASK_FINISH_WISH + id)) {
- client_print(id, print_chat, "[Wish] Wish already in progress!")
- return PLUGIN_HANDLED
- }
- StartWishProcess(id)
- return PLUGIN_HANDLED
- }
- StartWishProcess(id) {
- g_iCurrentReward[id] = 0
- set_hudmessage(0, 255, 255, -1.0, 0.2, 0, 0.1, 0.25, 0.0, 0.0, -1)
- show_hudmessage(id, "Frag JailBreak - Wish^nGood Luck!^n^n>> %s <<^n^n%d Cash",
- g_szRewardNames[g_iCurrentReward[id]], g_iPlayerCash[id])
- set_task(REWARD_CHANGE_INTERVAL, "TaskChangeReward", TASK_REWARD_LOOP + id, _, _, "b")
- set_task(REWARD_LOOP_TIME, "TaskFinishWish", TASK_FINISH_WISH + id)
- }
- public TaskChangeReward(taskid) {
- new id = taskid - TASK_REWARD_LOOP
- if(!is_user_connected(id)) {
- remove_task(TASK_REWARD_LOOP + id)
- return
- }
- g_iCurrentReward[id] = random(REWARD_COUNT)
- set_hudmessage(0, 255, 255, -1.0, 0.2, 0, 0.1, 0.25, 0.0, 0.0, -1)
- show_hudmessage(id, "Frag JailBreak - Wish^nGood Luck!^n^n>> %s <<^n^n%d Cash",
- g_szRewardNames[g_iCurrentReward[id]], g_iPlayerCash[id])
- }
- public TaskFinishWish(taskid) {
- new id = taskid - TASK_FINISH_WISH
- remove_task(TASK_REWARD_LOOP + id)
- if(!is_user_connected(id)) return
- ApplyReward(id, g_iCurrentReward[id])
- g_iWishesUsed[id]++
- SaveWishData(id)
- new remaining = MAX_WISHES - g_iWishesUsed[id]
- set_hudmessage(0, 255, 255, -1.0, 0.2, 0, 6.0, 5.0, 0.1, 0.2, -1)
- show_hudmessage(id, "Frag JailBreak - Wish^nResult: %s^n^n>%d Wishes left<^n^n%d Cash",
- g_szRewardNames[g_iCurrentReward[id]], remaining, g_iPlayerCash[id])
- }
- // -------------------------------------------------------------------------
- ApplyReward(id, reward) {
- switch(reward) {
- case REWARD_CASH_1000,
- REWARD_CASH_5000,
- REWARD_CASH_10000,
- REWARD_CASH_25000,
- REWARD_CASH_45000: {
- g_iPlayerCash[id] += g_iRewardValues[reward]
- client_print(id, print_chat, "[Wish] You won %d Cash!", g_iRewardValues[reward])
- }
- case REWARD_ARMOR_100: {
- new newArmor = get_user_armor(id) + g_iRewardValues[reward]
- if(newArmor > 200) newArmor = 200
- set_user_armor(id, newArmor)
- client_print(id, print_chat, "[Wish] You won %d Armor!", g_iRewardValues[reward])
- }
- case REWARD_EXTRA_WISH: {
- if(g_iWishesUsed[id] > 0) g_iWishesUsed[id]--
- client_print(id, print_chat, "[Wish] You won an Extra Wish!")
- }
- case REWARD_NOTHING: {
- client_print(id, print_chat, "[Wish] Better luck next time! You won nothing.")
- }
- }
- }
- // -------------------------------------------------------------------------
- public CmdResetWishes(id, level, cid) {
- if(!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED
- nvault_prune(g_iVault, 0, get_systime() + 1)
- for(new i = 1; i <= MaxClients; i++)
- g_iWishesUsed[i] = 0
- client_print(id, print_chat, "[Wish] All wish timers reset.")
- return PLUGIN_HANDLED
- }
Advertisement
Add Comment
Please, Sign In to add comment