Skip to content

Commit

Permalink
refacttor(bridge/ox): update ox_core version dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Mar 1, 2024
1 parent f1b4118 commit 9b76804
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
35 changes: 19 additions & 16 deletions modules/bridge/ox/client.lua
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
CreateThread(function() lib.load('@ox_core.imports.client') end)
if not lib.checkDependency('ox_core', '0.21.3', true) then return end

local Ox = require '@ox_core.lib.init' --[[@as OxClient]]
local player = Ox.GetPlayer()

RegisterNetEvent('ox:playerLogout', client.onLogout)

RegisterNetEvent('ox:setGroup', function(name, grade)
PlayerData.groups[name] = grade
OnPlayerData('groups')
PlayerData.groups[name] = grade
OnPlayerData('groups')
end)

---@diagnostic disable-next-line: duplicate-set-field
function client.setPlayerStatus(values)
for name, value in pairs(values) do
-- Thanks to having status values setup out of 1000000 (matching esx_status's standard)
-- we need to awkwardly change the value
if value > 100 or value < -100 then
-- Hunger and thirst start at 0 and go up to 100 as you get hungry/thirsty (inverse of ESX)
if (name == 'hunger' or name == 'thirst') then
value = -value
end
for name, value in pairs(values) do
-- Thanks to having status values setup out of 1000000 (matching esx_status's standard)
-- we need to awkwardly change the value
if value > 100 or value < -100 then
-- Hunger and thirst start at 0 and go up to 100 as you get hungry/thirsty (inverse of ESX)
if (name == 'hunger' or name == 'thirst') then
value = -value
end

value = value * 0.0001
end
value = value * 0.0001
end

---@diagnostic disable-next-line: undefined-global
player.addStatus(name, value)
end
---@diagnostic disable-next-line: undefined-global
player.addStatus(name, value)
end
end
18 changes: 17 additions & 1 deletion modules/bridge/ox/server.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
CreateThread(function() lib.load('@ox_core.imports.server') end)
if not lib.checkDependency('ox_core', '0.21.3', true) then return end

local Ox = require '@ox_core.lib.init' --[[@as OxServer]]

local Inventory = require 'modules.inventory.server'

AddEventHandler('ox:playerLogout', server.playerDropped)

AddEventHandler('ox:setGroup', function(source, name, grade)
local inventory = Inventory(source)

if not inventory then return end

inventory.player.groups[name] = grade
end)

---@diagnostic disable-next-line: duplicate-set-field
function server.setPlayerData(player)
player.groups = Ox.GetPlayer(player.source)?.getGroups()
return player
end

---@diagnostic disable-next-line: duplicate-set-field
function server.hasLicense(inv, name)
local player = Ox.GetPlayer(inv.id)

if not player then return end

return player.getLicense(name)
end

---@diagnostic disable-next-line: duplicate-set-field
function server.buyLicense(inv, license)
local player = Ox.GetPlayer(inv.id)

if not player then return end


if player.getLicense(license.name) then
return false, 'already_have'
elseif Inventory.GetItem(inv, 'money', false, true) < license.price then
Expand Down

0 comments on commit 9b76804

Please sign in to comment.