-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.lua
92 lines (81 loc) · 2.36 KB
/
main.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
ESX = nil
local guiEnabled = false
local phoneReady = false
local nextMissionTrigger = nil
--- Shows the GUI
-- Not extracted to functions.lua because it uses local vars
function EnableGui(enable, machineToHack)
SetNuiFocus(enable)
guiEnabled = enable
SendNUIMessage({
type = "enableui",
enable = enable,
machine = machineToHack
})
end
--- Event handler for generating a new random "next mission delay"
AddEventHandler(eventNamespace .. "getNextTriggerTime", function()
nextMissionTrigger = os.time(os.date("!*t")) + math.random(30, 300);
end)
--- Event handler for esx_phone initialization
RegisterNetEvent('esx_phone:loaded')
AddEventHandler('esx_phone:loaded', function(phoneNumber, contacts)
phoneReady = true
end)
--- NativeUI callback for quitting the PC UI
RegisterNUICallback('escape', function(data)
EnableGui(false, NIL)
end)
--- NativeUI callback for executing a command on a PC
RegisterNUICallback('command', function(data)
if data.command then
SendNUIMessage({
type = 'terminalOut',
output = ExecuteRPCommand(data.command, data.machine),
})
else
SendNUIMessage({
type = 'terminalOut',
output = "",
})
end
end)
--- Thread to get the ESX object
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj)
ESX = obj
end)
Citizen.Wait(0)
end
end)
--- Marker logic
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if isHacking or isHacker() then
drawPcMarkers()
end
end
end)
function timeForNextMission()
return not nextMissionTrigger == nil and os.time(os.date("!*t")) >= nextMissionTrigger
end
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if not isHacker() then
_tutorialLogic()
elseif isInFirstMission() and timeForNextMission() then
_firstMissionLogic()
elseif isInSecondMission() and timeForNextMission() then
_secondMissionLogic()
elseif isInThirdMission() and timeForNextMission() then
_thirdMissionLogic()
elseif isInFourthMission() and timeForNextMission() then
_fourthMissionLogic()
else
Citizen.Wait(20000) -- wait 20 secs
end
end
end)