forked from kubanscripts/kuban_admincomp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcl_comp.lua
More file actions
119 lines (108 loc) · 3.49 KB
/
Copy pathcl_comp.lua
File metadata and controls
119 lines (108 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
local selectedItem = nil
local selectedAmount = nil
local selectedPlayer = nil
RegisterNetEvent("kuban-comp:client:OpenCreateCompMenu")
AddEventHandler("kuban-comp:client:OpenCreateCompMenu", function()
openCompensationMenu()
end)
function openCompensationMenu()
if Config.MenuType == "ox" then
openOxMenu()
elseif Config.MenuType == "qb" then
openQbMenu()
else
print("Invalid MenuType in Config")
end
end
function openOxMenu()
local options = {
{
title = "Select Item",
description = selectedItem and ("Current: " .. selectedItem) or "Not Set",
icon = "box",
event = "kuban-comp:client:SelectItem"
},
{
title = "Select Amount",
description = selectedAmount and ("Current: " .. selectedAmount) or "Not Set",
icon = "hashtag",
event = "kuban-comp:client:SelectAmount"
},
{
title = "Create Compensation",
icon = "plus",
disabled = (not selectedItem or not selectedAmount),
event = "kuban-comp:client:ConfirmCompensation"
}
}
lib.registerContext({
id = "comp_main_menu",
title = "Create Compensation",
options = options
})
lib.showContext("comp_main_menu")
end
function openQbMenu()
local menu = {
{
header = "Create Compensation",
isMenuHeader = true
},
{
header = "Select Item",
txt = selectedItem and ("Current: " .. selectedItem) or "Not Set",
params = {
event = "kuban-comp:client:SelectItem"
}
},
{
header = "Select Amount",
txt = selectedAmount and ("Current: " .. selectedAmount) or "Not Set",
params = {
event = "kuban-comp:client:SelectAmount"
}
},
{
header = "Create Compensation",
txt = "Confirm Selection",
params = {
event = "kuban-comp:client:ConfirmCompensation"
},
disabled = (not selectedItem or not selectedAmount)
}
}
exports["qb-menu"]:openMenu(menu)
end
RegisterNetEvent("kuban-comp:client:SelectItem")
AddEventHandler("kuban-comp:client:SelectItem", function()
local input = lib.inputDialog("Enter Item Name", {
{ type = "input", label = "Item Name", required = true }
})
if input and input[1] then
selectedItem = input[1]
openCompensationMenu()
end
end)
RegisterNetEvent("kuban-comp:client:SelectAmount")
AddEventHandler("kuban-comp:client:SelectAmount", function()
local input = lib.inputDialog("Enter Amount", {
{ type = "number", label = "Amount", required = true, min = 1 }
})
if input and input[1] then
selectedAmount = input[1]
openCompensationMenu()
end
end)
RegisterNetEvent("kuban-comp:client:ConfirmCompensation")
AddEventHandler("kuban-comp:client:ConfirmCompensation", function()
if selectedItem and selectedAmount then
TriggerServerEvent("kuban-comp:server:CreateComp", selectedItem, selectedAmount)
else
TriggerEvent("QBCore:Notify", "All fields must be filled!", "error")
end
end)
RegisterNetEvent("kuban-comp:client:CopyCode")
AddEventHandler("kuban-comp:client:CopyCode", function(code)
lib.setClipboard(code)
TriggerEvent("QBCore:Notify", "Compensation code copied to clipboard: " .. code, "success")
end)