This repository was archived by the owner on Apr 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
99 lines (93 loc) · 3.81 KB
/
server.lua
File metadata and controls
99 lines (93 loc) · 3.81 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
lib.versionCheck('unitysync/sync_armory')
local ESX = exports.es_extended:getSharedObject()
local inv = exports.ox_inventory
local webhook = 'CHANGE_ME' -- Set to false to disable webhook.
local function sendToDiscord(data)
if not webhook then return end
local embed = {
{
['color'] = data.color,
['title'] = '**Police Armory**',
['description'] = data.message,
['footer'] = {
['text'] = 'Armory Logs',
},
}
}
if webhook == 'CHANGE_ME' then
lib.print.warn('Webhook not set up, please set it up in sv_main.lua')
else
PerformHttpRequest(webhook, function(err, text, headers) end, 'POST',
json.encode({ username = data.name, embeds = embed }), { ['Content-Type'] = 'application/json' })
end
end
for type, password in pairs(Config.Passwords) do
if password == 'CHANGE_ME' then
lib.print.warn(('Password is not set up for type: %s. Please set it up in config.lua'):format(type))
end
end
RegisterNetEvent('sync_armory:getWeapons', function(data)
local item = data.item
local xPlayer = ESX.GetPlayerFromId(source)
local canCarryItem = inv:CanCarryItem(source, item, 1)
local itemCount = inv:GetItemCount(source, item)
if xPlayer.getJob().name == 'police' and itemCount == 0 and canCarryItem then
sendToDiscord({
color = 16711680,
name = 'Armory Logs',
message = ('**Action:** `Received Item` \n **Character Name:** `%s`\n **Player Name:** `%s`\n **Item:** `%s`\n <t:%s:f>'):format(xPlayer.getName(), GetPlayerName(source), item, os.time())
})
for i, weapons in pairs(Config.Weapons) do
for _, v in pairs(weapons) do
if item == v.item then -- Only allow defined weapons to be given
inv:AddItem(source, item, 1, { components = v.components })
break
end
end
end
elseif xPlayer.getJob().name == 'police' and itemCount > 0 then
TriggerClientEvent('ox_lib:notify', source, {
title = 'Police Armory',
description = 'You can only carry 1 of each weapon.',
type = 'error'
})
end
end)
RegisterNetEvent('sync_armory:removeWeapons', function(item)
local xPlayer = ESX.GetPlayerFromId(source)
sendToDiscord({
color = 16711680,
name = 'Armory Logs',
message = ('**Action:** `Removed Weapon` \n **Character Name:** `%s`\n **Player Name:** `%s`\n **Weapon:** `%s`\n <t:%s:f>'):format(xPlayer.getName(), GetPlayerName(source), item, os.time())
})
local itemCount = inv:GetItemCount(source, item)
if itemCount ~= 0 then
for i, weapons in pairs(Config.Weapons) do
for _, v in pairs(weapons) do
if item == v.item then -- Only allow defined items to be removed
inv:RemoveItem(source, item, 1)
break
end
end
end
end
end)
RegisterNetEvent('sync_armory:getItems', function(item, count)
local xPlayer = ESX.GetPlayerFromId(source)
local canCarryItem = inv:CanCarryItem(source, item, count)
if xPlayer.getJob().name == 'police' and canCarryItem then
sendToDiscord({
color = 16711680,
name = 'Armory Logs',
message = ('**Action:** `Received Item` \n **Character Name:** `%s`\n **Player Name:** `%s`\n **Item:** `%s`\n <t:%s:f>'):format(xPlayer.getName(), GetPlayerName(source), item, os.time())
})
for type, items in pairs(Config.Items) do
for i, v in pairs(items) do
if item == v.item then -- Only allow defined items to be given
inv:AddItem(source, item, count)
break
end
end
end
end
end)