Skip to content

Commit

Permalink
refactor: remove config.lua and utilise new convars
Browse files Browse the repository at this point in the history
Moves the convar loading into init.lua and updates config references.
  • Loading branch information
thelindat committed Jan 20, 2022
1 parent 29891bc commit 917a870
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 246 deletions.
13 changes: 6 additions & 7 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ local function OpenInventory(inv, data)
SetInterval(interval, 100)
SetNuiFocus(true, true)
SetNuiFocusKeepInput(true)
if shared.blurscreen then TriggerScreenblurFadeIn(0) end
if client.screenblur then TriggerScreenblurFadeIn(0) end
CloseTrunk()
currentInventory = right or defaultInventory
left.items = PlayerData.inventory
Expand Down Expand Up @@ -228,8 +228,7 @@ local function useSlot(slot)

return data.client.export(0, data, {name = item.name, slot = item.slot, metadata = item.metadata})
elseif data.client.event then -- deprecated, to be removed
print('data.client.event is deprecated, utilise exports instead.')
return TriggerEvent(data.client.event, data, {name = item.name, slot = item.slot, metadata = item.metadata})
return print(('unable to trigger event for %s, data.client.event has been removed. utilise exports instead.'):format(item.name))
end
end

Expand Down Expand Up @@ -429,7 +428,7 @@ local function RegisterCommands()
OpenInventory(closestMarker[3], {id=closestMarker[2], type=closestMarker[4]})
else OpenInventory() end
end)
RegisterKeyMapping('inv', shared.locale('open_player_inventory'), 'keyboard', shared.keys[1])
RegisterKeyMapping('inv', shared.locale('open_player_inventory'), 'keyboard', client.keys[1])
TriggerEvent('chat:removeSuggestion', '/inv')

local Vehicles = data 'vehicles'
Expand Down Expand Up @@ -552,7 +551,7 @@ local function RegisterCommands()
else return TriggerEvent('ox_inventory:closeInventory')
end
end)
RegisterKeyMapping('inv2', shared.locale('open_secondary_inventory'), 'keyboard', shared.keys[2])
RegisterKeyMapping('inv2', shared.locale('open_secondary_inventory'), 'keyboard', client.keys[2])
TriggerEvent('chat:removeSuggestion', '/inv2')

RegisterCommand('reload', function()
Expand All @@ -569,7 +568,7 @@ local function RegisterCommands()
SendNUIMessage({ action = 'toggleHotbar' })
end
end)
RegisterKeyMapping('hotbar', shared.locale('disable_hotbar'), 'keyboard', shared.keys[3])
RegisterKeyMapping('hotbar', shared.locale('disable_hotbar'), 'keyboard', client.keys[3])
TriggerEvent('chat:removeSuggestion', '/hotbar')

RegisterCommand('steal', function()
Expand Down Expand Up @@ -877,7 +876,7 @@ RegisterNetEvent('ox_inventory:setPlayerInventory', function(currentDrops, inven
end
end, 200)

local EnableKeys = shared.enablekeys
local EnableKeys = client.enablekeys
tick = SetInterval(function()
DisablePlayerVehicleRewards(PlayerData.id)

Expand Down
174 changes: 0 additions & 174 deletions config.lua

This file was deleted.

3 changes: 1 addition & 2 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ dependencies {

shared_scripts {
'@pe-lualib/init.lua',
'config.lua'
'modules/init.lua'
}

server_script 'modules/bridge/server.lua'

shared_scripts {
'modules/init.lua',
'modules/**/shared.lua'
}

Expand Down
2 changes: 1 addition & 1 deletion modules/bridge/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ end

local Utils = client.utils

if shared.esx then
if shared.framework == 'esx' then
local ESX = exports.es_extended:getSharedObject()

PlayerData.dead = PlayerData.dead
Expand Down
2 changes: 1 addition & 1 deletion modules/bridge/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ server.accounts = {
money = 0,
}

if shared.esx then
if shared.framework == 'esx' then
local ESX = exports['es_extended']:getSharedObject()

-- ESX.ServerCallbacks does not exist in the Overextended fork of ESX, so throw an error
Expand Down
61 changes: 61 additions & 0 deletions modules/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
IsDuplicityVersion = IsDuplicityVersion()
shared = {
resource = GetCurrentResourceName(),
framework = GetConvar('inventory:framework', 'esx'),
locale = GetConvar('inventory:locale', 'en'),
playerslots = GetConvarInt('inventory:slots', 50),
playerweight = GetConvarInt('inventory:weight', 50),
autoreload = GetConvar('inventory:autoreload', 'false') == 'true',
trimplate = GetConvar('inventory:trimplate', 'true') == 'true',
qtarget = GetConvar('inventory:qtarget', 'false') == 'true',
police = json.decode(GetConvar('inventory:police', '["police", "sheriff"]')),
}

do
if type(shared.police) == 'string' then
shared.police = {shared.police}
end

local police = table.create(0, #shared.police)

for i = 1, #shared.police do
police[shared.police[i]] = 0
end
shared.police = police
end

if IsDuplicityVersion then
server = {
randomprices = GetConvar('inventory:randomprices', 'false') == 'true',
versioncheck = GetConvar('inventory:versioncheck', 'true') == 'true',
randomloot = GetConvar('inventory:randomloot', 'true') == 'true',
evidencegrade = GetConvarInt('inventory:evidencegrade', 2),
vehicleloot = json.decode(GetConvar('inventory:vehicleloot', [[
[
["cola", 1, 1],
["water", 1, 1],
["garbage", 1, 2, 50],
["panties", 1, 1, 5],
["money", 1, 50],
["money", 200, 400, 5],
["bandage", 1, 1]
]
]])),
dumpsterloot = json.decode(GetConvar('inventory:dumpsterloot', [[
[
["mustard", 1, 1],
["garbage", 1, 3],
["money", 1, 10],
["burger", 1, 1]
]
]])),
}
else
client = {
screenblur = GetConvar('inventory:screenblur', 'true') == 'true',
keys = json.decode(GetConvar('inventory:keys', '["F2", "K", "TAB"]')),
enablekeys = json.decode(GetConvar('inventory:enablekeys', '[249]')),
clearstashes = GetConvar('inventory:clearstashes', '6 MONTH'),
}
end

function shared.print(...) print(string.strjoin(' ', ...)) end
function shared.info(...) shared.print('^2[info]^7', ...) end
function shared.warning(...) shared.print('^3[warning]^7', ...) end
Expand Down
Loading

0 comments on commit 917a870

Please sign in to comment.