forked from DevAlexandre0/Camping
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
69 lines (59 loc) · 2.24 KB
/
server.lua
File metadata and controls
69 lines (59 loc) · 2.24 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
RegisterNetEvent('camping:saveCampingData')
AddEventHandler('camping:saveCampingData', function(type, model, x, y, z, stashID, heading)
local query = "INSERT INTO camping (type, model, x, y, z, stashID, heading) VALUES (@type, @model, @x, @y, @z, @stashID, @heading)"
exports.oxmysql:insert(query, {
['@type'] = type,
['@model'] = model,
['@x'] = x,
['@y'] = y,
['@z'] = z,
['@stashID'] = stashID or '',
['@heading'] = heading
})
end)
RegisterNetEvent('camping:LoadData')
AddEventHandler('camping:LoadData', function()
local result = exports.oxmysql:executeSync("SELECT * FROM camping")
for _, data in ipairs(result) do
TriggerClientEvent('camping:loadCampingData', -1, data)
debugLog("Loaded camping data : " .. json.encode(data))
end
end)
RegisterNetEvent('camping:deleteCampingData')
AddEventHandler('camping:deleteCampingData', function(type, stashID)
local query = "DELETE FROM camping WHERE type = @type AND stashID = @stashID"
exports.oxmysql:execute(query, {
['@type'] = type,
['@stashID'] = stashID
})
end)
-- Add Item
RegisterNetEvent('camping:AI', function(itemName, amount)
if source == '' then return end
local src = source
local added = exports.ox_inventory:AddItem(src, itemName, amount)
debugLog(("Added %d of %s to player %d"):format(amount, itemName, src))
end)
-- Remove Item
RegisterNetEvent('camping:RI', function(itemName, amount)
if source == '' then return end
local src = source
local removed = exports.ox_inventory:RemoveItem(src, itemName, amount)
debugLog(("Removed %d of %s from player %d"):format(amount, itemName, src))
end)
local tentStashes = {}
-- Create a tent stash
RegisterNetEvent('camping:createTentStash', function(stashId)
if tentStashes[stashId] then
debugLog("Tent stash already exists: " .. stashId)
return
end
exports.ox_inventory:RegisterStash(stashId, "Tent", 10, 10000)
tentStashes[stashId] = stashId
debugLog("Tent stash created with ID: " .. stashId)
end)
function debugLog(message)
if Config.DEBUG then
print("^3[DEBUG]^7 " .. tostring(message))
end
end