This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathesxBaseFunction.lua
240 lines (217 loc) · 6.02 KB
/
esxBaseFunction.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
ESX = nil
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
function getPlayerIdentifier(playerId)
local xPlayer = ESX.GetPlayerFromId(playerId)
if xPlayer then
return xPlayer.identifier
else
for k,v in ipairs(GetPlayerIdentifiers(playerId)) do
return v
end
end
end
function GetRealPlayerName(playerId)
local xPlayer = ESX.GetPlayerFromId(playerId)
if xPlayer then
return xPlayer.getName()
else
return GetPlayerName(playerId)
end
end
function GetOOCPlayerName(playerId)
return GetPlayerName(playerId)
end
function citizenWear()
ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin)
TriggerEvent('skinchanger:loadSkin', skin)
end)
end
function isPlayerPedMale()
isMale = -1
ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin)
isMale = skin.sex == 0
end)
while isMale == -1 do
Citizen.Wait(0)
end
return isMale
end
function getPlayerSkin()
skins = {}
ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin)
table.insert(skins , { c = 8 , d = skin.tshirt_1, t = skin.tshirt_2 })
table.insert(skins , { c = 11 , d = skin.torso_1, t = skin.torso_2 })
table.insert(skins , { c = 3 , d = skin.arms , t = skin.arms_2 })
table.insert(skins , { c = 10 , d = skin.decals_1 , t = skin.decals_2 })
table.insert(skins , { c = 4 , d = skin.pants_1 , t = skin.pants_2 })
table.insert(skins , { c = 6 , d = skin.shoes_1 , t = skin.shoes_2 })
table.insert(skins , { c = 1 , d = skin.mask_1 , t = skin.mask_2 })
table.insert(skins , { c = 7 , d = skin.chain_1 , t = skin.chain_2 })
table.insert(skins , { c = 5 , d = skin.bags_1 , t = skin.bags_2 })
end)
while #skins ~= 9 do
Citizen.Wait(0)
end
return skins
end
function setPlayerMoney(playerId,amount,typeTransaction)
local xPlayer = ESX.GetPlayerFromId(playerId)
if xPlayer then
if typeTransaction == 'add' then
xPlayer.addMoney(amount)
return true
elseif typeTransaction == 'remove' and xPlayer.getMoney() >= amount then
xPlayer.removeMoney(amount)
return true
elseif typeTransaction == 'remove' and xPlayer.getMoney() < amount then
return false
end
else
return false
end
end
function addSalary(playerId,amount)
local xPlayer = ESX.GetPlayerFromId(playerId)
if xPlayer then
xPlayer.addAccountMoney('bank', amount)
return true
else
return false
end
end
function OpenPlayerInventory(player)
local xPlayer = ESX.GetPlayerFromId(player)
if xPlayer then
local data = {}
local account = xPlayer.getAccounts()
for i=1, #account, 1 do
if account[i].name == 'black_money' and account[i].money > 0 then
table.insert(data, {
label = _U('confiscate_dirty'),
value = 'black_money',
itemType = 'account',
amount = account[i].money
})
break
end
end
if xPlayer.getMoney() > 0 then
table.insert(data, {
label = _U('money'),
value = 'money',
itemType = 'account',
amount = xPlayer.getMoney()
})
end
local loadout = xPlayer.getLoadout()
for i=1, #loadout , 1 do
table.insert(data, {
label = _U('confiscate_weapon', ESX.GetWeaponLabel(loadout[i].name)),
value = loadout[i].name,
itemType = 'weapon',
amount = loadout[i].ammo
})
end
local inventory = xPlayer.getInventory()
for i=1, #inventory, 1 do
if inventory[i].count > 0 then
table.insert(data, {
label = _U('confiscate_inv', inventory[i].label),
value = inventory[i].name,
itemType = 'item',
amount = inventory[i].count
})
end
end
return data
end
return {}
end
function PlayerInventoryGetItem(player, itemType, itemName, amount)
local XPlayer = ESX.GetPlayerFromId(player)
if XPlayer then
if itemType == 'item' then
local Item = XPlayer.getInventoryItem(itemName)
if Item.count > 0 and Item.count >= amount then
XPlayer.removeInventoryItem(itemName, amount)
return true
end
elseif itemType == 'account' then
if itemName == 'money' then
if XPlayer.getMoney() >= amount then
XPlayer.removeMoney(amount)
return true
end
else
if XPlayer.getAccount(itemName).money >= amount then
XPlayer.removeAccountMoney(itemName, amount)
return true
end
end
elseif itemType == 'weapon' then
if amount == nil then amount = 0 end
XPlayer.removeWeapon(itemName, amount)
return true
end
end
return false
end
function PlayerInventoryGiveItem(player, itemType, itemName, amount)
local XPlayer = ESX.GetPlayerFromId(player)
if XPlayer then
if itemType == 'item' then
if XPlayer.canCarryItem then
if XPlayer.canCarryItem(itemName, amount) then
XPlayer.addInventoryItem(itemName, amount)
return true
end
else
XPlayer.addInventoryItem(itemName, amount)
return true
end
elseif itemType == 'account' then
if itemName == 'money' then
XPlayer.addMoney(amount)
return true
else
XPlayer.addAccountMoney(itemName, amount)
return true
end
elseif itemType == 'weapon' then
if amount == nil then amount = 0 end
XPlayer.addWeapon(itemName, amount)
return true
end
end
return false
end
function isOwnedvehicle(source , vehicleProps)
local xPlayer = ESX.GetPlayerFromId(source)
local result = MySQL.Sync.fetchAll('SELECT plate FROM owned_vehicles WHERE owner = @owner AND plate = @plate AND ( job Is null or job = "" or job = "civ" )', {
['@owner'] = xPlayer.identifier,
['@plate'] = vehicleProps.plate
})
if result[1] then
return true
end
return false
end
function deleteOwnedvehicle(source , vehicleProps)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.Async.execute('DELETE FROM owned_vehicles WHERE owner = @owner AND plate = @plate AND ( job Is null or job = "" or job = "civ" )', {
['@owner'] = xPlayer.identifier,
['@plate'] = vehicleProps.plate
} , function(e) end)
return true
end
function selectFromDB(query , params)
return MySQL.Sync.fetchAll(query, params )
end
function executeOnDB(query , params , cb)
MySQL.Async.execute(query, params , function(e) cb(e) end)
end