ed
This commit is contained in:
parent
8ee1bc193d
commit
6fbb9c5ea6
2 changed files with 183 additions and 5 deletions
74
resources/[carscripts]/nordi_seats/server/main.lua
Normal file
74
resources/[carscripts]/nordi_seats/server/main.lua
Normal file
|
@ -0,0 +1,74 @@
|
|||
local QBCore = exports['qb-core']:GetCoreObject()
|
||||
local anchoredBoats = {} -- Gespeicherte Anker {plate = anchorData}
|
||||
|
||||
-- Lade Anker aus Datenbank
|
||||
local function loadAnchorsFromDB()
|
||||
local result = MySQL.query.await('SELECT * FROM anchored_boats')
|
||||
if result then
|
||||
for _, row in pairs(result) do
|
||||
anchoredBoats[row.plate] = {
|
||||
coords = json.decode(row.coords),
|
||||
heading = row.heading,
|
||||
time = row.timestamp
|
||||
}
|
||||
end
|
||||
print("^2[Anker]^7 " .. #result .. " verankerte Boote aus der Datenbank geladen.")
|
||||
end
|
||||
end
|
||||
|
||||
-- Speichere Anker in Datenbank
|
||||
local function saveAnchorToDB(plate, anchorData)
|
||||
MySQL.insert('INSERT INTO anchored_boats (plate, coords, heading, timestamp) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE coords = VALUES(coords), heading = VALUES(heading), timestamp = VALUES(timestamp)', {
|
||||
plate,
|
||||
json.encode(anchorData.coords),
|
||||
anchorData.heading,
|
||||
anchorData.time or os.time()
|
||||
})
|
||||
end
|
||||
|
||||
-- Entferne Anker aus Datenbank
|
||||
local function removeAnchorFromDB(plate)
|
||||
MySQL.execute('DELETE FROM anchored_boats WHERE plate = ?', {plate})
|
||||
end
|
||||
|
||||
-- Events
|
||||
RegisterNetEvent('nordi_seats:server:saveAnchor', function(plate, anchorData)
|
||||
local src = source
|
||||
if not plate or not anchorData then return end
|
||||
|
||||
anchoredBoats[plate] = anchorData
|
||||
saveAnchorToDB(plate, anchorData)
|
||||
|
||||
print("^2[Anker]^7 Boot " .. plate .. " wurde verankert (Spieler: " .. src .. ")")
|
||||
end)
|
||||
|
||||
RegisterNetEvent('nordi_seats:server:removeAnchor', function(plate)
|
||||
local src = source
|
||||
if not plate then return end
|
||||
|
||||
anchoredBoats[plate] = nil
|
||||
removeAnchorFromDB(plate)
|
||||
|
||||
print("^2[Anker]^7 Boot " .. plate .. " Anker wurde gelichtet (Spieler: " .. src .. ")")
|
||||
end)
|
||||
|
||||
-- Callbacks
|
||||
QBCore.Functions.CreateCallback('nordi_seats:server:getAnchoredBoats', function(source, cb)
|
||||
cb(anchoredBoats)
|
||||
end)
|
||||
|
||||
QBCore.Functions.CreateCallback('nordi_seats:server:getAnchorByPlate', function(source, cb, plate)
|
||||
cb(anchoredBoats[plate])
|
||||
end)
|
||||
|
||||
-- Lade Anker beim Start
|
||||
CreateThread(function()
|
||||
loadAnchorsFromDB()
|
||||
end)
|
||||
|
||||
-- Cleanup bei Resource Stop
|
||||
AddEventHandler('onResourceStop', function(resourceName)
|
||||
if GetCurrentResourceName() == resourceName then
|
||||
print("^3[Anker]^7 Resource gestoppt. Anker bleiben in der Datenbank gespeichert.")
|
||||
end
|
||||
end)
|
Loading…
Add table
Add a link
Reference in a new issue