-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclinet.lua
153 lines (119 loc) · 5.48 KB
/
clinet.lua
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
--------------------------------------------------------------------------------
-- NUI Message Handler
--------------------------------------------------------------------------------
local function SendNUIEvent(eventType, data)
SendNUIMessage({
type = eventType,
table = data
})
end
--------------------------------------------------------------------------------
-- UI Visibility
--------------------------------------------------------------------------------
local function ShowMissionUI(isVisible)
SendNUIEvent('toggleUi', { state = isVisible })
end
exports('ShowMissionUI', ShowMissionUI)
--------------------------------------------------------------------------------
-- Task Number Toggle
--------------------------------------------------------------------------------
local function ToggleTaskNumberVisibility(isVisible)
SendNUIEvent('toggleNumberOfTask', { state = isVisible })
end
exports('ToggleTaskNumberVisibility', ToggleTaskNumberVisibility)
--------------------------------------------------------------------------------
-- Task Amount Update
--------------------------------------------------------------------------------
local function UpdateAllTaskAmounts(taskAmount)
SendNUIEvent('updateTaskAmount', { taskAmount = taskAmount })
end
exports('UpdateAllTaskAmounts', UpdateAllTaskAmounts)
--------------------------------------------------------------------------------
-- Stage Amount Update (for a specific task)
--------------------------------------------------------------------------------
local function UpdateSingleTaskProgress(taskIndex, currentStage)
SendNUIEvent('updateStageAmount', {
index = taskIndex,
currentStage = currentStage
})
end
exports('UpdateSingleTaskProgress', UpdateSingleTaskProgress)
--------------------------------------------------------------------------------
-- Toggle Completion By Index
--------------------------------------------------------------------------------
local function ToggleCompletionForTask(taskIndex)
SendNUIEvent('toggleCompleteByIndex', { index = taskIndex })
end
exports('ToggleCompletionForTask', ToggleCompletionForTask)
--------------------------------------------------------------------------------
-- Set Entire Task Table
--------------------------------------------------------------------------------
local function SetAllTasks(taskData)
-- taskData should be a table of tasks: { { text = "Task Name", current=0, total=4 }, ... }
SendNUIEvent('setTaskData', taskData)
end
exports('SetAllTasks', SetAllTasks)
--------------------------------------------------------------------------------
-- Reset All Completion States
--------------------------------------------------------------------------------
local function ResetAllTaskCompletions()
SendNUIEvent('resetCompletes')
end
exports('ResetAllTaskCompletions', ResetAllTaskCompletions)
--------------------------------------------------------------------------------
-- TEST COMMANDS (Rename as you see fit)
--------------------------------------------------------------------------------
-- Example: /missiontest
RegisterCommand('missiontest', function(source, args, rawCommand)
-- Show UI
exports["legends-tasks"]:ShowMissionUI(true)
-- Initialize some example tasks
local exampleTasks = {
{ text = "Steal supplies from Valentine general store", current = 0, total = 4 },
{ text = "Hunt legendary bear in Tall Trees", current = 0, total = 3 },
{ text = "Deliver mail packages to Rhodes", current = 0, total = 5 }
}
exports["legends-tasks"]:SetAllTasks(exampleTasks)
end)
-- Example: /missionhide
RegisterCommand('missionhide', function(source, args, rawCommand)
exports["legends-tasks"]:ShowMissionUI(false)
end)
-- Example: /missionshow
RegisterCommand('missionshow', function(source, args, rawCommand)
exports["legends-tasks"]:ShowMissionUI(true)
end)
-- Example: /missionnumbers show OR /missionnumbers hide
RegisterCommand('missionnumbers', function(source, args, rawCommand)
if args[1] == 'show' then
exports["legends-tasks"]:ToggleTaskNumberVisibility(true)
elseif args[1] == 'hide' then
exports["legends-tasks"]:ToggleTaskNumberVisibility(false)
end
end)
-- Example: /missionupdate 1 2
-- Updates the current stage for the 1st task to 2
RegisterCommand('missionupdate', function(source, args, rawCommand)
local taskIndex = tonumber(args[1]) or 0
local newStage = tonumber(args[2]) or 0
exports["legends-tasks"]:UpdateSingleTaskProgress(taskIndex, newStage)
end)
-- Example: /missioncomplete 1
RegisterCommand('missioncomplete', function(source, args, rawCommand)
local taskIndex = tonumber(args[1]) or 0
exports["legends-tasks"]:ToggleCompletionForTask(taskIndex)
end)
-- Example: /missionreset
RegisterCommand('missionreset', function(source, args, rawCommand)
exports["legends-tasks"]:ResetAllTaskCompletions()
end)
-- Example: /missionsetall
RegisterCommand('missionsetall', function(source, args, rawCommand)
local newTasks = {
{ text = "Rob the Saint Denis bank", current = 0, total = 6 },
{ text = "Find treasure near Blackwater", current = 0, total = 4 },
{ text = "Help locals in Armadillo", current = 0, total = 3 },
{ text = "Clear gang hideout in Thieves Landing", current = 0, total = 5 }
}
exports["legends-tasks"]:SetAllTasks(newTasks)
end)