forked from qbcore-framework/qb-target
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
224 lines (173 loc) · 6.37 KB
/
init.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
function Load(name)
local resourceName = GetCurrentResourceName()
local chunk = LoadResourceFile(resourceName, ('data/%s.lua'):format(name))
if chunk then
local err
chunk, err = load(chunk, ('@@%s/data/%s.lua'):format(resourceName, name), 't')
if err then
error(('\n^1 %s'):format(err), 0)
end
return chunk()
end
end
-------------------------------------------------------------------------------
-- Settings
-------------------------------------------------------------------------------
Config = {}
-- It's possible to interact with entities through walls so this should be low
Config.MaxDistance = 7.0
-- Enable debug options
Config.Debug = false
-- Supported values: true, false
Config.Standalone = false
-- Enable outlines around the entity you're looking at
Config.EnableOutline = false
-- Whether to have the target as a toggle or not
Config.Toggle = false
-- Draw a Sprite on the center of a PolyZone to hint where it's located
Config.DrawSprite = false
-- The default distance to draw the Sprite
Config.DrawDistance = 10.0
-- The color of the sprite in rgb, the first value is red, the second value is green, the third value is blue and the last value is alpha (opacity). Here is a link to a color picker to get these values: https://htmlcolorcodes.com/color-picker/
Config.DrawColor = {255, 255, 255, 255}
-- The color of the sprite in rgb when the PolyZone is targeted, the first value is red, the second value is green, the third value is blue and the last value is alpha (opacity). Here is a link to a color picker to get these values: https://htmlcolorcodes.com/color-picker/
Config.SuccessDrawColor = {30, 144, 255, 255}
-- The color of the outline in rgb, the first value is red, the second value is green, the third value is blue and the last value is alpha (opacity). Here is a link to a color picker to get these values: https://htmlcolorcodes.com/color-picker/
Config.OutlineColor = {255, 255, 255, 255}
-- Enable default options (Toggling vehicle doors)
Config.EnableDefaultOptions = true
-- Disable the target eye whilst being in a vehicle
Config.DisableInVehicle = false
-- Key to open the target eye, here you can find all the names: https://docs.fivem.net/docs/game-references/input-mapper-parameter-ids/keyboard/
Config.OpenKey = 'LMENU' -- Left Alt
-- Control for key press detection on the context menu, it's the Right Mouse Button by default, controls are found here https://docs.fivem.net/docs/game-references/controls/
Config.MenuControlKey = 238
-------------------------------------------------------------------------------
-- Target Configs
-------------------------------------------------------------------------------
-- These are all empty for you to fill in, refer to the .md files for help in filling these in
Config.CircleZones = {
}
Config.BoxZones = {
}
Config.PolyZones = {
}
Config.TargetBones = {
}
Config.TargetModels = {
}
Config.GlobalPedOptions = {
}
Config.GlobalVehicleOptions = {
}
Config.GlobalObjectOptions = {
}
Config.GlobalPlayerOptions = {
}
Config.Peds = {
}
-------------------------------------------------------------------------------
-- Functions
-------------------------------------------------------------------------------
local function JobCheck() return true end
local function GangCheck() return true end
local function JobTypeCheck() return true end
local function ItemCheck() return true end
local function CitizenCheck() return true end
CreateThread(function()
local state = GetResourceState('qb-core')
if state ~= 'missing' then
local timeout = 0
while state ~= 'started' and timeout <= 100 do
timeout += 1
state = GetResourceState('qb-core')
Wait(0)
end
Config.Standalone = false
end
if Config.Standalone then
local firstSpawn = false
local event = AddEventHandler('playerSpawned', function()
SpawnPeds()
firstSpawn = true
end)
-- Remove event after it has been triggered
while true do
if firstSpawn then
RemoveEventHandler(event)
break
end
Wait(1000)
end
else
local QBCore = exports['qb-core']:GetCoreObject()
local PlayerData = QBCore.Functions.GetPlayerData()
ItemCheck = QBCore.Functions.HasItem
JobCheck = function(job)
if type(job) == 'table' then
job = job[PlayerData.job.name]
if job and PlayerData.job.grade.level >= job then
return true
end
elseif job == 'all' or job == PlayerData.job.name then
return true
end
return false
end
JobTypeCheck = function(jobType)
if type(jobType) == 'table' then
jobType = jobType[PlayerData.job.type]
if jobType then
return true
end
elseif jobType == 'all' or jobType == PlayerData.job.type then
return true
end
return false
end
GangCheck = function(gang)
if type(gang) == 'table' then
gang = gang[PlayerData.gang.name]
if gang and PlayerData.gang.grade.level >= gang then
return true
end
elseif gang == 'all' or gang == PlayerData.gang.name then
return true
end
return false
end
CitizenCheck = function(citizenid)
return citizenid == PlayerData.citizenid or citizenid[PlayerData.citizenid]
end
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
PlayerData = QBCore.Functions.GetPlayerData()
SpawnPeds()
end)
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
PlayerData = {}
DeletePeds()
end)
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(JobInfo)
PlayerData.job = JobInfo
end)
RegisterNetEvent('QBCore:Client:OnGangUpdate', function(GangInfo)
PlayerData.gang = GangInfo
end)
RegisterNetEvent('QBCore:Player:SetPlayerData', function(val)
PlayerData = val
end)
end
end)
function CheckOptions(data, entity, distance)
if distance and data.distance and distance > data.distance then return false end
if data.job and not JobCheck(data.job) then return false end
if data.excludejob and JobCheck(data.excludejob) then return false end
if data.jobType and not JobTypeCheck(data.jobType) then return false end
if data.excludejobType and JobTypeCheck(data.excludejobType) then return false end
if data.gang and not GangCheck(data.gang) then return false end
if data.excludegang and GangCheck(data.excludegang) then return false end
if data.item and not ItemCheck(data.item) then return false end
if data.citizenid and not CitizenCheck(data.citizenid) then return false end
if data.canInteract and not data.canInteract(entity, distance, data) then return false end
return true
end