Guest User

Untitled

a guest
Aug 10th, 2022
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.08 KB | None | 0 0
  1. local QBCore = exports['qb-core']:GetCoreObject()
  2. local PlayerJob = QBCore.Functions.GetPlayerData().job
  3. local shownBossMenu = false
  4. local DynamicMenuItems = {}
  5.  
  6. -- UTIL
  7. local function CloseMenuFull()
  8.     exports['qb-menu']:closeMenu()
  9.     exports['qb-core']:HideText()
  10.     shownBossMenu = false
  11. end
  12.  
  13. local function comma_value(amount)
  14.     local formatted = amount
  15.     while true do
  16.         local k
  17.         formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
  18.         if (k == 0) then
  19.             break
  20.         end
  21.     end
  22.     return formatted
  23. end
  24.  
  25. local function AddBossMenuItem(data, id)
  26.     local menuID = id or (#DynamicMenuItems + 1)
  27.     DynamicMenuItems[menuID] = deepcopy(data)
  28.     return menuID
  29. end
  30.  
  31. exports("AddBossMenuItem", AddBossMenuItem)
  32.  
  33. local function RemoveBossMenuItem(id)
  34.     DynamicMenuItems[id] = nil
  35. end
  36.  
  37. exports("RemoveBossMenuItem", RemoveBossMenuItem)
  38.  
  39. AddEventHandler('onResourceStart', function(resource)
  40.     if resource == GetCurrentResourceName() then
  41.         PlayerJob = QBCore.Functions.GetPlayerData().job
  42.     end
  43. end)
  44.  
  45. RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
  46.     PlayerJob = QBCore.Functions.GetPlayerData().job
  47. end)
  48.  
  49. RegisterNetEvent('QBCore:Client:OnJobUpdate', function(JobInfo)
  50.     PlayerJob = JobInfo
  51. end)
  52.  
  53. RegisterNetEvent('qb-bossmenu:client:OpenMenu', function()
  54.     if not PlayerJob.name or not PlayerJob.isboss then return end
  55.  
  56.     local bossMenu = {
  57.         {
  58.             header = "Boss Menu - " .. string.upper(PlayerJob.label),
  59.             icon = "fa-solid fa-circle-info",
  60.             isMenuHeader = true,
  61.         },
  62.         {
  63.             header = "Manage Employees",
  64.             txt = "Check your Employees List",
  65.             icon = "fa-solid fa-list",
  66.             params = {
  67.                 event = "qb-bossmenu:client:employeelist",
  68.             }
  69.         },
  70.         {
  71.             header = "Hire Employees",
  72.             txt = "Hire Nearby Civilians",
  73.             icon = "fa-solid fa-hand-holding",
  74.             params = {
  75.                 event = "qb-bossmenu:client:HireMenu",
  76.             }
  77.         },
  78.         {
  79.             header = "Storage Access",
  80.             txt = "Open Storage",
  81.             icon = "fa-solid fa-box-open",
  82.             params = {
  83.                 event = "qb-bossmenu:client:Stash",
  84.             }
  85.         },
  86.         {
  87.             header = "Outfits",
  88.             txt = "See Saved Outfits",
  89.             icon = "fa-solid fa-shirt",
  90.             params = {
  91.                 event = "qb-bossmenu:client:Wardrobe",
  92.             }
  93.         },
  94.         {
  95.             header = "Money Management",
  96.             txt = "Check your Company Balance",
  97.             icon = "fa-solid fa-sack-dollar",
  98.             params = {
  99.                 event = "qb-bossmenu:client:SocietyMenu",
  100.             }
  101.         },
  102.         {
  103.             header = "Employees Duty",
  104.             txt = "Shows Duty time of your employes",
  105.             icon = "fa-solid fa-sack-dollar",
  106.             params = {
  107.                 event = "qb-bossmenu:client:DutyTime",
  108.             }
  109.         },
  110.     }
  111.  
  112.     for _, v in pairs(DynamicMenuItems) do
  113.         bossMenu[#bossMenu + 1] = v
  114.     end
  115.  
  116.     bossMenu[#bossMenu + 1] = {
  117.         header = "Exit",
  118.         icon = "fa-solid fa-angle-left",
  119.         params = {
  120.             event = "qb-menu:closeMenu",
  121.         }
  122.     }
  123.  
  124.     exports['qb-menu']:openMenu(bossMenu)
  125. end)
  126.  
  127. RegisterNetEvent('qb-bossmenu:client:employeelist', function()
  128.     local EmployeesMenu = {
  129.         {
  130.             header = "Manage Employees - " .. string.upper(PlayerJob.label),
  131.             isMenuHeader = true,
  132.             icon = "fa-solid fa-circle-info",
  133.         },
  134.     }
  135.     QBCore.Functions.TriggerCallback('qb-bossmenu:server:GetEmployees', function(cb)
  136.         for _, v in pairs(cb) do
  137.             EmployeesMenu[#EmployeesMenu + 1] = {
  138.                 header = v.name,
  139.                 txt = v.grade.name,
  140.                 icon = "fa-solid fa-circle-user",
  141.                 params = {
  142.                     event = "qb-bossmenu:client:ManageEmployee",
  143.                     args = {
  144.                         player = v,
  145.                         work = PlayerJob
  146.                     }
  147.                 }
  148.             }
  149.         end
  150.         EmployeesMenu[#EmployeesMenu + 1] = {
  151.             header = "Return",
  152.             icon = "fa-solid fa-angle-left",
  153.             params = {
  154.                 event = "qb-bossmenu:client:OpenMenu",
  155.             }
  156.         }
  157.         exports['qb-menu']:openMenu(EmployeesMenu)
  158.     end, PlayerJob.name)
  159. end)
  160.  
  161. RegisterNetEvent('qb-bossmenu:client:ManageEmployee', function(data)
  162.     local EmployeeMenu = {
  163.         {
  164.             header = "Manage " .. data.player.name .. " - " .. string.upper(PlayerJob.label),
  165.             isMenuHeader = true,
  166.             icon = "fa-solid fa-circle-info"
  167.         },
  168.     }
  169.     for k, v in pairs(QBCore.Shared.Jobs[data.work.name].grades) do
  170.         EmployeeMenu[#EmployeeMenu + 1] = {
  171.             header = v.name,
  172.             txt = "Grade: " .. k,
  173.             params = {
  174.                 isServer = true,
  175.                 event = "qb-bossmenu:server:GradeUpdate",
  176.                 icon = "fa-solid fa-file-pen",
  177.                 args = {
  178.                     cid = data.player.empSource,
  179.                     grade = tonumber(k),
  180.                     gradename = v.name
  181.                 }
  182.             }
  183.         }
  184.     end
  185.     EmployeeMenu[#EmployeeMenu + 1] = {
  186.         header = "Fire Employee",
  187.         icon = "fa-solid fa-user-large-slash",
  188.         params = {
  189.             isServer = true,
  190.             event = "qb-bossmenu:server:FireEmployee",
  191.             args = data.player.empSource
  192.         }
  193.     }
  194.     EmployeeMenu[#EmployeeMenu + 1] = {
  195.         header = "Return",
  196.         icon = "fa-solid fa-angle-left",
  197.         params = {
  198.             event = "qb-bossmenu:client:OpenMenu",
  199.         }
  200.     }
  201.     exports['qb-menu']:openMenu(EmployeeMenu)
  202. end)
  203.  
  204. RegisterNetEvent('qb-bossmenu:client:Stash', function()
  205.     TriggerServerEvent("inventory:server:OpenInventory", "stash", "boss_" .. PlayerJob.name, {
  206.         maxweight = 4000000,
  207.         slots = 25,
  208.     })
  209.     TriggerEvent("inventory:client:SetCurrentStash", "boss_" .. PlayerJob.name)
  210. end)
  211.  
  212. RegisterNetEvent('qb-bossmenu:client:Wardrobe', function()
  213.     TriggerEvent('qb-clothing:client:openOutfitMenu')
  214. end)
  215.  
  216. RegisterNetEvent('qb-bossmenu:client:HireMenu', function()
  217.     local HireMenu = {
  218.         {
  219.             header = "Hire Employees - " .. string.upper(PlayerJob.label),
  220.             isMenuHeader = true,
  221.             icon = "fa-solid fa-circle-info",
  222.         },
  223.     }
  224.     QBCore.Functions.TriggerCallback('qb-bossmenu:getplayers', function(players)
  225.         for _, v in pairs(players) do
  226.             if v and v ~= PlayerId() then
  227.                 HireMenu[#HireMenu + 1] = {
  228.                     header = v.name,
  229.                     txt = "Citizen ID: " .. v.citizenid .. " - ID: " .. v.sourceplayer,
  230.                     icon = "fa-solid fa-user-check",
  231.                     params = {
  232.                         isServer = true,
  233.                         event = "qb-bossmenu:server:HireEmployee",
  234.                         args = v.sourceplayer
  235.                     }
  236.                 }
  237.             end
  238.         end
  239.         HireMenu[#HireMenu + 1] = {
  240.             header = "Return",
  241.             icon = "fa-solid fa-angle-left",
  242.             params = {
  243.                 event = "qb-bossmenu:client:OpenMenu",
  244.             }
  245.         }
  246.         exports['qb-menu']:openMenu(HireMenu)
  247.     end)
  248. end)
  249.  
  250. RegisterNetEvent('qb-bossmenu:client:DutyTime', function()
  251.     TriggerServerEvent('sqz_duty:GetEmployes', PlayerJob.name)
  252. end)
  253.  
  254. RegisterNetEvent('qb-bossmenu:client:SocietyMenu', function()
  255.     QBCore.Functions.TriggerCallback('qb-bossmenu:server:GetAccount', function(cb)
  256.         local SocietyMenu = {
  257.             {
  258.                 header = "Balance: $" .. comma_value(cb) .. " - " .. string.upper(PlayerJob.label),
  259.                 isMenuHeader = true,
  260.                 icon = "fa-solid fa-circle-info",
  261.             },
  262.             {
  263.                 header = "Deposit",
  264.                 icon = "fa-solid fa-money-bill-transfer",
  265.                 txt = "Deposit Money into account",
  266.                 params = {
  267.                     event = "qb-bossmenu:client:SocetyDeposit",
  268.                     args = comma_value(cb)
  269.                 }
  270.             },
  271.             {
  272.                 header = "Withdraw",
  273.                 icon = "fa-solid fa-money-bill-transfer",
  274.                 txt = "Withdraw Money from account",
  275.                 params = {
  276.                     event = "qb-bossmenu:client:SocetyWithDraw",
  277.                     args = comma_value(cb)
  278.                 }
  279.             },
  280.             {
  281.                 header = "Return",
  282.                 icon = "fa-solid fa-angle-left",
  283.                 params = {
  284.                     event = "qb-bossmenu:client:OpenMenu",
  285.                 }
  286.             },
  287.         }
  288.         exports['qb-menu']:openMenu(SocietyMenu)
  289.     end, PlayerJob.name)
  290. end)
  291.  
  292. RegisterNetEvent('qb-bossmenu:client:SocetyDeposit', function(money)
  293.     local deposit = exports['qb-input']:ShowInput({
  294.         header = "Deposit Money <br> Available Balance: $" .. money,
  295.         submitText = "Confirm",
  296.         inputs = {
  297.             {
  298.                 type = 'number',
  299.                 isRequired = true,
  300.                 name = 'amount',
  301.                 text = 'Amount'
  302.             }
  303.         }
  304.     })
  305.     if deposit then
  306.         if not deposit.amount then return end
  307.         TriggerServerEvent("qb-bossmenu:server:depositMoney", tonumber(deposit.amount))
  308.     end
  309. end)
  310.  
  311. RegisterNetEvent('qb-bossmenu:client:SocetyWithDraw', function(money)
  312.     local withdraw = exports['qb-input']:ShowInput({
  313.         header = "Withdraw Money <br> Available Balance: $" .. money,
  314.         submitText = "Confirm",
  315.         inputs = {
  316.             {
  317.                 type = 'number',
  318.                 isRequired = true,
  319.                 name = 'amount',
  320.                 text = 'Amount'
  321.             }
  322.         }
  323.     })
  324.     if withdraw then
  325.         if not withdraw.amount then return end
  326.         TriggerServerEvent("qb-bossmenu:server:withdrawMoney", tonumber(withdraw.amount))
  327.     end
  328. end)
  329.  
  330. -- MAIN THREAD
  331. CreateThread(function()
  332.     if Config.UseTarget then
  333.         for job, zones in pairs(Config.BossMenuZones) do
  334.             for index, data in ipairs(zones) do
  335.                 exports['qb-target']:AddBoxZone(job.."-BossMenu-"..index, data.coords, data.length, data.width, {
  336.                     name = job.."-BossMenu-"..index,
  337.                     heading = data.heading,
  338.                     -- debugPoly = true,
  339.                     minZ = data.minZ,
  340.                     maxZ = data.maxZ,
  341.                 }, {
  342.                     options = {
  343.                         {
  344.                             type = "client",
  345.                             event = "qb-bossmenu:client:OpenMenu",
  346.                             icon = "fas fa-sign-in-alt",
  347.                             label = "Boss Menu",
  348.                             canInteract = function() return job == PlayerJob.name and PlayerJob.isboss end,
  349.                         },
  350.                     },
  351.                     distance = 2.5
  352.                 })
  353.             end
  354.         end
  355.     else
  356.         while true do
  357.             local wait = 2500
  358.             local pos = GetEntityCoords(PlayerPedId())
  359.             local inRangeBoss = false
  360.             local nearBossmenu = false
  361.             if PlayerJob then
  362.                 wait = 0
  363.                 for k, menus in pairs(Config.BossMenus) do
  364.                     for _, coords in ipairs(menus) do
  365.                         if k == PlayerJob.name and PlayerJob.isboss then
  366.                             if #(pos - coords) < 5.0 then
  367.                                 inRangeBoss = true
  368.                                 if #(pos - coords) <= 1.5 then
  369.                                     nearBossmenu = true
  370.                                     if not shownBossMenu then
  371.                                         exports['qb-core']:DrawText('[E] Open Job Management', 'left')
  372.                                         shownBossMenu = true
  373.                                     end
  374.                                     if IsControlJustReleased(0, 38) then
  375.                                         exports['qb-core']:HideText()
  376.                                         TriggerEvent("qb-bossmenu:client:OpenMenu")
  377.                                     end
  378.                                 end
  379.  
  380.                                 if not nearBossmenu and shownBossMenu then
  381.                                     CloseMenuFull()
  382.                                     shownBossMenu = false
  383.                                 end
  384.                             end
  385.                         end
  386.                     end
  387.                 end
  388.                 if not inRangeBoss then
  389.                     Wait(1500)
  390.                     if shownBossMenu then
  391.                         CloseMenuFull()
  392.                         shownBossMenu = false
  393.                     end
  394.                 end
  395.             end
  396.             Wait(wait)
  397.         end
  398.     end
  399. end)
Add Comment
Please, Sign In to add comment