-
-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
AddStateBagChangeHandler('isLoggedIn', ('player:%s'):format(cache.serverId), function(_, _, value) | ||
if not value then client.onLogout() end | ||
end) | ||
|
||
RegisterNetEvent('qbx_core:client:onGroupUpdate', function(groupName, groupGrade) | ||
local groups = PlayerData.groups | ||
if not groupGrade then | ||
groups[groupName] = nil | ||
else | ||
groups[groupName] = groupGrade | ||
end | ||
client.setPlayerData('groups', groups) | ||
end) | ||
|
||
RegisterNetEvent('qbx_core:client:setGroups', function(groups) | ||
client.setPlayerData('groups', groups) | ||
end) | ||
|
||
---@diagnostic disable-next-line: duplicate-set-field | ||
function client.setPlayerStatus(values) | ||
local playerState = LocalPlayer.state | ||
for name, value in pairs(values) do | ||
-- compatibility for ESX style values | ||
if value > 100 or value < -100 then | ||
value = value * 0.0001 | ||
end | ||
|
||
playerState:set(name, playerState[name] + value, true) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
assert(lib.checkDependency('qbx_core', '1.18.0'), 'qbx_core v1.18.0 or higher is required') | ||
assert(lib.checkDependency('qbx_vehicles', '1.2.0'), 'qbx_vehicles v1.2.0 or higher is required') | ||
local Inventory = require 'modules.inventory.server' | ||
local QBX = exports.qbx_core | ||
|
||
AddEventHandler('qbx_core:server:playerLoggedOut', server.playerDropped) | ||
|
||
AddEventHandler('qbx_core:server:onGroupUpdate', function(source, groupName, groupGrade) | ||
local inventory = Inventory(source) | ||
if not inventory then return end | ||
inventory.player.groups[groupName] = not groupGrade and nil or groupGrade | ||
end) | ||
|
||
local function setupPlayer(playerData) | ||
playerData.identifier = playerData.citizenid | ||
playerData.name = ('%s %s'):format(playerData.charinfo.firstname, playerData.charinfo.lastname) | ||
server.setPlayerInventory(playerData) | ||
|
||
Inventory.SetItem(playerData.source, 'money', playerData.money.cash) | ||
end | ||
|
||
AddStateBagChangeHandler('loadInventory', nil, function(bagName, _, value) | ||
if not value then return end | ||
local plySrc = GetPlayerFromStateBagName(bagName) | ||
if not plySrc then return end | ||
setupPlayer(QBX:GetPlayer(plySrc).PlayerData) | ||
end) | ||
|
||
SetTimeout(500, function() | ||
local playersData = QBX:GetPlayersData() | ||
for i = 1, #playersData do setupPlayer(playersData[i]) end | ||
end) | ||
|
||
function server.UseItem(source, itemName, data) | ||
local cb = QBX:CanUseItem(itemName) | ||
return cb and cb(source, data) | ||
end | ||
|
||
---@diagnostic disable-next-line: duplicate-set-field | ||
function server.setPlayerData(player) | ||
local groups = QBX:GetGroups(player.source) | ||
return { | ||
source = player.source, | ||
name = ('%s %s'):format(player.charinfo.firstname, player.charinfo.lastname), | ||
groups = groups, | ||
sex = player.charinfo.gender, | ||
dateofbirth = player.charinfo.birthdate, | ||
} | ||
end | ||
|
||
---@diagnostic disable-next-line: duplicate-set-field | ||
function server.syncInventory(inv) | ||
local accounts = Inventory.GetAccountItemCounts(inv) | ||
|
||
if not accounts then return end | ||
local player = QBX:GetPlayer(inv.id) | ||
|
||
for account, amount in pairs(accounts) do | ||
account = account == 'money' and 'cash' or account | ||
if player.Functions.GetMoney(account) ~= amount then | ||
player.Functions.SetMoney(account, amount, ('Sync %s with inventory'):format(account)) | ||
end | ||
end | ||
end | ||
|
||
---@diagnostic disable-next-line: duplicate-set-field | ||
function server.hasLicense(inv, license) | ||
local player = QBX:GetPlayer(inv.id) | ||
return player and player.PlayerData.metadata.licences[license] | ||
end | ||
|
||
---@diagnostic disable-next-line: duplicate-set-field | ||
function server.buyLicense(inv, license) | ||
local player = QBX:GetPlayer(inv.id) | ||
if not player then return end | ||
|
||
if player.PlayerData.metadata.licences[license.name] then | ||
return false, 'already_have' | ||
elseif Inventory.GetItem(inv, 'money', false, true) < license.price then | ||
return false, 'can_not_afford' | ||
end | ||
|
||
Inventory.RemoveItem(inv, 'money', license.price) | ||
player.PlayerData.metadata.licences[license.name] = true | ||
player.Functions.SetMetaData('licences', player.PlayerData.metadata.licences) | ||
|
||
return true, 'have_purchased' | ||
end | ||
|
||
---@diagnostic disable-next-line: duplicate-set-field | ||
function server.isPlayerBoss(playerId, group, grade) | ||
return QBX:IsGradeBoss(group, grade) | ||
end | ||
|
||
---@param entityId number | ||
---@return number | string | ||
---@diagnostic disable-next-line: duplicate-set-field | ||
function server.getOwnedVehicleId(entityId) | ||
return Entity(entityId).vehicleid or exports.qbx_vehicles:GetVehicleIdByPlate(GetVehicleNumberPlateText(entityId)) or GetVehicleNumberPlateText(entityId) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters