-
Notifications
You must be signed in to change notification settings - Fork 215
🔑 Optionally save acquired keys into DB #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
c4f4193
b4361ab
49540b8
5b0f093
346b673
5636725
19bdd38
de3f7ab
4517ef4
91db3fb
a871904
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -49,6 +49,12 @@ RegisterNetEvent('qb-vehiclekeys:server:setVehLockState', function(vehNetId, sta | |||||||||
SetVehicleDoorsLocked(NetworkGetEntityFromNetworkId(vehNetId), state) | ||||||||||
end) | ||||||||||
|
||||||||||
RegisterServerEvent("qb-vehiclekeys:server:synckeys", function(KeyList) | ||||||||||
if not Config.SaveInDB then return end | ||||||||||
local Player = QBCore.Functions.GetPlayer(source) | ||||||||||
Player.Functions.SetMetaData("VehKeys", KeyList) | ||||||||||
end) | ||||||||||
|
||||||||||
Cocodrulo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
QBCore.Functions.CreateCallback('qb-vehiclekeys:server:GetVehicleKeys', function(source, cb) | ||||||||||
local Player = QBCore.Functions.GetPlayer(source) | ||||||||||
if not Player then return end | ||||||||||
Cocodrulo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
|
@@ -59,6 +65,11 @@ QBCore.Functions.CreateCallback('qb-vehiclekeys:server:GetVehicleKeys', function | |||||||||
keysList[plate] = true | ||||||||||
end | ||||||||||
end | ||||||||||
if Player.PlayerData.metadata["vehicleKeys"] and Config.PersistentKeys then | ||||||||||
for plate in pairs(Player.PlayerData.metadata["vehicleKeys"]) do | ||||||||||
keysList[plate] = true | ||||||||||
end | ||||||||||
end | ||||||||||
cb(keysList) | ||||||||||
end) | ||||||||||
|
||||||||||
|
@@ -78,38 +89,61 @@ function GiveKeys(id, plate) | |||||||||
local Player = QBCore.Functions.GetPlayer(id) | ||||||||||
if not Player then return end | ||||||||||
local citizenid = Player.PlayerData.citizenid | ||||||||||
|
||||||||||
if not plate then | ||||||||||
if GetVehiclePedIsIn(GetPlayerPed(id), false) ~= 0 then | ||||||||||
plate = QBCore.Shared.Trim(GetVehicleNumberPlateText(GetVehiclePedIsIn(GetPlayerPed(id), false))) | ||||||||||
else | ||||||||||
return | ||||||||||
end | ||||||||||
end | ||||||||||
|
||||||||||
if not VehicleList[plate] then VehicleList[plate] = {} end | ||||||||||
VehicleList[plate][citizenid] = true | ||||||||||
|
||||||||||
local oldKeys = Player.PlayerData.metadata["vehicleKeys"] or {} | ||||||||||
oldKeys[plate] = true | ||||||||||
Player.Functions.SetMetaData("vehicleKeys", oldKeys) | ||||||||||
|
||||||||||
TriggerClientEvent('QBCore:Notify', id, Lang:t('notify.vgetkeys')) | ||||||||||
TriggerClientEvent('qb-vehiclekeys:client:AddKeys', id, plate) | ||||||||||
end | ||||||||||
|
||||||||||
exports('GiveKeys', GiveKeys) | ||||||||||
|
||||||||||
function RemoveKeys(id, plate) | ||||||||||
local citizenid = QBCore.Functions.GetPlayer(id).PlayerData.citizenid | ||||||||||
local Player = QBCore.Functions.GetPlayer(id) | ||||||||||
if not Player then return end | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
better readability There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think is better to keep it one line, it's cleaner from my view |
||||||||||
local citizenid = Player.PlayerData.citizenid | ||||||||||
|
||||||||||
if VehicleList[plate] and VehicleList[plate][citizenid] then | ||||||||||
VehicleList[plate][citizenid] = nil | ||||||||||
end | ||||||||||
|
||||||||||
local oldKeys = Player.PlayerData.metadata["vehicleKeys"] or {} | ||||||||||
oldKeys[plate] = nil | ||||||||||
Player.Functions.SetMetaData("vehicleKeys", oldKeys) | ||||||||||
|
||||||||||
TriggerClientEvent('qb-vehiclekeys:client:RemoveKeys', id, plate) | ||||||||||
end | ||||||||||
|
||||||||||
exports('RemoveKeys', RemoveKeys) | ||||||||||
|
||||||||||
function HasKeys(id, plate) | ||||||||||
local citizenid = QBCore.Functions.GetPlayer(id).PlayerData.citizenid | ||||||||||
local Player = QBCore.Functions.GetPlayer(id) | ||||||||||
if not Player then return false end | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
better readability There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think is better to keep it one line, it's cleaner from my view |
||||||||||
local citizenid = Player.PlayerData.citizenid | ||||||||||
|
||||||||||
if VehicleList[plate] and VehicleList[plate][citizenid] then | ||||||||||
return true | ||||||||||
end | ||||||||||
|
||||||||||
if Player.PlayerData.metadata["vehicleKeys"] and Config.PersistentKeys then | ||||||||||
if Player.PlayerData.metadata["vehicleKeys"][plate] then | ||||||||||
return true | ||||||||||
end | ||||||||||
end | ||||||||||
Cocodrulo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
return false | ||||||||||
end | ||||||||||
|
||||||||||
|
@@ -136,4 +170,4 @@ QBCore.Commands.Add('removekeys', Lang:t('addcom.rkeys'), { { name = Lang:t('add | |||||||||
return | ||||||||||
end | ||||||||||
RemoveKeys(tonumber(args[1]), args[2]) | ||||||||||
end, 'admin') | ||||||||||
end, 'admin') |
Uh oh!
There was an error while loading. Please reload this page.