-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.lua
61 lines (50 loc) · 1.89 KB
/
server.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
ESX = exports['es_extended']:getSharedObject()
-- ESX
RegisterNetEvent('ox_thief:confiscatePlayerItem')
AddEventHandler('ox_thief:confiscatePlayerItem', function(target, itemType, itemName, amount)
local source = source
local sourceXPlayer = ESX.GetPlayerFromId(source)
local targetXPlayer = ESX.GetPlayerFromId(target)
if itemType == 'item_standard' then
local targetItem = targetXPlayer.getInventoryItem(itemName)
local sourceItem = sourceXPlayer.getInventoryItem(itemName)
if targetItem.count > 0 and targetItem.count <= amount then
if sourceXPlayer.canCarryItem(itemName, sourceItem.count) then
targetXPlayer.removeInventoryItem(itemName, amount)
sourceXPlayer.addInventoryItem (itemName, amount)
end
end
elseif itemType == 'item_account' then
local targetAccount = targetXPlayer.getAccount(itemName)
if targetAccount.money >= amount then
targetXPlayer.removeAccountMoney(itemName, amount, "Confiscated")
sourceXPlayer.addAccountMoney (itemName, amount, "Confiscated")
end
elseif itemType == 'item_weapon' then
if amount == nil then amount = 0 end
if targetXPlayer.hasWeapon(itemName) then
targetXPlayer.removeWeapon(itemName)
sourceXPlayer.addWeapon (itemName, amount)
end
end
end)
ESX.RegisterServerCallback('ox_thief:getPlayerData', function(source, cb, target, notify)
local xPlayer = ESX.GetPlayerFromId(target)
if xPlayer then
local data = {
name = xPlayer.getName(),
job = xPlayer.job.label,
grade = xPlayer.job.grade_label,
inventory = xPlayer.getInventory(),
accounts = xPlayer.getAccounts(),
weapons = xPlayer.getLoadout()
}
cb(data)
end
end)
-- QB
RegisterServerEvent('ox_thief:openPlayerInventory')
AddEventHandler('ox_thief:openPlayerInventory', function(playerId)
local source = source
exports['qb-inventory']:OpenInventoryById(source, playerId)
end)