forked from overextended/qtarget
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
173 lines (147 loc) · 4.56 KB
/
init.lua
File metadata and controls
173 lines (147 loc) · 4.56 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
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
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 and distance preview
Config.Debug = false
-- Supported values: ESX, QB, false
Config.Framework = false
-------------------------------------------------------------------------------
-- Functions
-------------------------------------------------------------------------------
local function JobCheck() return true end
local function GangCheck() return true end
local function ItemCount() return true end
local function CitizenCheck() return true end
CreateThread(function()
if not Config.Framework then
local framework = 'es_extended'
local state = GetResourceState(framework)
if state == 'missing' then
framework = 'qb-core'
state = GetResourceState(framework)
end
if state ~= 'missing' then
if state ~= ('started' or 'starting') then
local timeout = 0
repeat
Wait(0)
timeout += 1
until (GetResourceState(framework) == 'started' or timeout > 100)
end
Config.Framework = (framework == 'es_extended') and 'ESX' or 'QB'
end
end
if Config.Framework == 'ESX' then
local ESX = exports['es_extended']:getSharedObject()
local resState = GetResourceState('ox_inventory')
if resState ~= 'missing' and resState ~= 'unknown' then
ItemCount = function(item)
return exports.ox_inventory:Search(2, item)
end
else
ItemCount = function(item)
for _, v in pairs(ESX.GetPlayerData().inventory) do
if v.name == item then
return v.count
end
end
return 0
end
end
JobCheck = function(job)
if type(job) == 'table' then
job = job[ESX.PlayerData.job.name]
if job and ESX.PlayerData.job.grade >= job then
return true
end
elseif job == ESX.PlayerData.job.name or job == 'all' then
return true
end
return false
end
RegisterNetEvent('esx:playerLoaded', function(xPlayer)
ESX.PlayerData = xPlayer
end)
RegisterNetEvent('esx:setJob', function(job)
ESX.PlayerData.job = job
end)
RegisterNetEvent('esx:onPlayerLogout', function()
table.wipe(ESX.PlayerData)
end)
elseif Config.Framework == 'QB' then
local QBCore = exports['qb-core']:GetCoreObject()
local PlayerData = QBCore.Functions.GetPlayerData()
ItemCount = function(item)
for _, v in pairs(PlayerData.items) do
if v.name == item then
return v.amount
end
end
return 0
end
JobCheck = function(job)
if type(job) == 'table' then
job = job[PlayerData.job.name]
if PlayerData.job.grade.level >= job then
return true
end
elseif job == PlayerData.job.name or job == 'all' then
return true
end
return false
end
GangCheck = function(gang)
if type(gang) == 'table' then
gang = gang[PlayerData.gang.name]
if PlayerData.gang.grade.level >= gang then
return true
end
elseif gang == PlayerData.gang.name or gang == 'all' 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()
end)
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
table.wipe(PlayerData)
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
function CheckOptions(data, entity, distance)
if data.distance and distance > data.distance then return false end
if data.job and not JobCheck(data.job) then return false end
if data.gang and not GangCheck(data.gang) then return false end
if data.item and ItemCount(data.item) < 1 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
end)