-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.lua
More file actions
125 lines (104 loc) · 3.96 KB
/
Copy pathserver.lua
File metadata and controls
125 lines (104 loc) · 3.96 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
ESX = exports['es_extended']:getSharedObject()
local playerCoords = {}
MySQL.ready(function()
MySQL.Async.execute([[
CREATE TABLE IF NOT EXISTS fxinv (
identifier VARCHAR(50) PRIMARY KEY,
dead BOOLEAN DEFAULT 0
)
]], {}, function(affectedRows)
if Config.Debug then
print("FX-INV: SQL Updated")
end
end)
end)
local function ensurePlayerInDatabase(identifier)
MySQL.Async.fetchScalar("SELECT identifier FROM fxinv WHERE identifier = @identifier", {
['@identifier'] = identifier
}, function(result)
if not result then
MySQL.Async.execute("INSERT INTO fxinv (identifier, dead) VALUES (@identifier, 1)", {
['@identifier'] = identifier
})
end
end)
end
RegisterServerEvent('esx:onPlayerDeath')
AddEventHandler('esx:onPlayerDeath', function(data)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local identifier = GetPlayerIdentifier(_source, 0) -- STEAM
if xPlayer then
ensurePlayerInDatabase(identifier)
MySQL.Async.execute("UPDATE fxinv SET dead = 1 WHERE identifier = @identifier", {
['@identifier'] = identifier
})
playerCoords[_source] = xPlayer.getCoords(true)
end
end)
RegisterServerEvent('fxinv:playerSpawned')
AddEventHandler('fxinv:playerSpawned', function()
local _source = source
local identifier = GetPlayerIdentifier(_source, 0)
if identifier then
MySQL.Async.execute("UPDATE fxinv SET dead = 0 WHERE identifier = @identifier", {
['@identifier'] = identifier
})
end
end)
AddEventHandler('playerDropped', function(data, reason)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
if not xPlayer then return end
local identifier = GetPlayerIdentifier(_source, 0) -- STEAM
local coords = playerCoords[_source]
local inventoryData = exports.ox_inventory:Inventory(_source)
MySQL.Async.fetchScalar("SELECT dead FROM fxinv WHERE identifier = @identifier", {
['@identifier'] = identifier
}, function(isDead)
if isDead == true then
local rawInventory = inventoryData.items
local inventory = {}
for _, v in pairs(rawInventory) do
if Config.OnlyWeapon and v.name:sub(1, 7) == 'WEAPON_' then
inventory[#inventory + 1] = { v.name, v.count, v.metadata }
exports.ox_inventory:RemoveItem(_source, v.name, v.count, v.metadata)
elseif not Config.OnlyWeapon then
inventory[#inventory + 1] = { v.name, v.count, v.metadata }
end
end
if #inventory > 0 then
exports.ox_inventory:CustomDrop(_source, inventory, coords)
if Config.Debug then
print("FX-INV: Drop Created in " .. json.encode(coords))
end
end
end
end)
if not Config.OnlyWeapon then
exports.ox_inventory:ClearInventory(_source, false)
end
playerCoords[_source] = nil
end)
-- TXAdmin Listening
local function changeState(identifier)
MySQL.Async.execute("UPDATE fxinv SET dead = 0 WHERE identifier = @identifier", {
['@identifier'] = identifier
})
end
AddEventHandler('txAdmin:events:scheduledRestart', function(source, eventData)
if eventData.secondsRemaining == 15 then
local _source = source
local identifier = GetPlayerIdentifier(_source, 0) -- STEAM
changeState(identifier)
playerCoords[_source] = nil
end
end)
AddEventHandler('txAdmin:events:healedPlayer', function(source)
if source then
local _source = source
local identifier = GetPlayerIdentifier(_source, 0) -- STEAM
changeState(identifier)
playerCoords[_source] = nil
end
end)