Advertisement
Guest User

Random Contract (lib/managers/menumanager)

a guest
May 31st, 2016
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.13 KB | None | 0 0
  1. local menu_id = "menu_roll_contract"
  2.  
  3. Hooks:Add("MenuManagerSetupCustomMenus", "MenuManagerSetupCustomMenus_RandomContract", function(menu_manager, nodes)
  4.     if nodes.lobby then
  5.         MenuHelper:NewMenu( menu_id )
  6.     end
  7. end)
  8.  
  9. Hooks:Add("MenuManagerPopulateCustomMenus", "MenuManagerPopulateCustomMenus_RandomContract", function(menu_manager, nodes)
  10.     if nodes.lobby then
  11.         MenuCallbackHandler.Random_contract_now = function(self, item)
  12.             local job_id_list = tweak_data.narrative:get_jobs_index()
  13.             local job_tweak_data, is_not_dlc_or_got, choose_job, can_afford, retries
  14.             local retry_limit = 50
  15.             while (not is_not_dlc_or_got or not can_afford) and ((retries or 0) < retry_limit) do
  16.                 choose_job = job_id_list[math.random( #job_id_list )]
  17.                 job_tweak_data = tweak_data.narrative.jobs[choose_job]
  18.                 is_not_dlc_or_got = not job_tweak_data.dlc or managers.dlc:is_dlc_unlocked(job_tweak_data.dlc)
  19.                 can_afford = managers.money:can_afford_buy_premium_contract(tweak_data:difficulty_to_index(item._priority))
  20.                 retries = (retries or 0) + 1
  21.             end
  22.             if retries and retries < retry_limit then
  23.                 create_job({ difficulty = item._priority, job_id = choose_job })
  24.             else
  25.                 QuickMenu:new(
  26.                     "Random Contrect",
  27.                     "Looks like you can't afford any random heist currently. sorry.",
  28.                     {
  29.                         {"Ok", is_cancel_button = true}
  30.                     },
  31.                     true
  32.                 )
  33.             end
  34.         end
  35.         MenuHelper:AddButton({
  36.             id = "roll_contract_ovk",
  37.             title = "roll_contract_ovk_title",
  38.             desc = "roll_contract_ovk_desc",
  39.             callback = "Random_contract_now",
  40.             priority = "overkill_145",
  41.             menu_id = menu_id,
  42.         })
  43.         MenuHelper:AddButton({
  44.             id = "roll_contract_dw",
  45.             title = "roll_contract_dw_title",
  46.             desc = "roll_contract_dw_desc",
  47.             callback = "Random_contract_now",
  48.             priority = "overkill_290",
  49.             menu_id = menu_id,
  50.         })
  51.     end
  52. end)
  53.  
  54. Hooks:Add("MenuManagerBuildCustomMenus", "MenuManagerBuildCustomMenus_RandomContract", function(menu_manager, nodes)
  55.     if nodes.lobby and ( not LuaNetworking:IsMultiplayer() or ( LuaNetworking:IsMultiplayer() and LuaNetworking:IsHost() ) ) then
  56.         nodes[menu_id] = MenuHelper:BuildMenu( menu_id )
  57.         MenuHelper:AddMenuItem( nodes.lobby, menu_id, "menu_roll_contract_name", "menu_roll_contract_desc" )
  58.     end
  59. end)
  60.  
  61. Hooks:Add("LocalizationManagerPostInit", "RandomContract_loc", function(loc)
  62.     LocalizationManager:add_localized_strings({
  63.     ["menu_roll_contract"] = "Random contract",
  64.     ["menu_roll_contract_name"] = "Random contract",
  65.     ["menu_roll_contract_desc"] = "Change your contract to something random",
  66.     ["roll_contract_ovk_title"] = "OVERKILL",
  67.     ["roll_contract_ovk_desc"] = "Give you random contract in OVERKILL",
  68.     ["roll_contract_dw_title"] = "DEATH WISH",
  69.     ["roll_contract_dw_desc"] = "Give you random contract in DEATH WISH",
  70.   })
  71. end)
  72.  
  73. function create_job(data)
  74.     local difficulty_id = tweak_data:difficulty_to_index(data.difficulty)
  75.     managers.money:on_buy_premium_contract(data.job_id, difficulty_id)
  76.     managers.job:on_buy_job(data.job_id, difficulty_id)
  77.     MenuCallbackHandler:start_job({job_id = data.job_id, difficulty = data.difficulty})
  78.     MenuCallbackHandler:save_progress()
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement