Skip to content

Commit

Permalink
feat(resource): Remove ox_lib dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
antond15 committed Oct 9, 2022
1 parent d4d6754 commit a9a8ac8
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 27 deletions.
29 changes: 13 additions & 16 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,24 @@ version '1.0.0'
description 'A framework-standalone scoreboard UI for FiveM.'
repository 'https://github.com/antond15/ac_scoreboard'

dependency 'ox_lib'

ui_page 'web/build/index.html'
shared_script 'config.lua'

files {
'web/build/index.html',
'web/build/**/*',
'locales/*.lua'
}

shared_scripts {
'@ox_lib/init.lua',
'config.lua'
server_scripts {
'resource/server/server.lua',
'resource/server/framework.lua',
'resource/server/version.lua'
}

client_scripts {
'resource/locales.lua',
'resource/client.lua'
'resource/client/locales.lua',
'resource/client/client.lua'
}

server_scripts {
'resource/server/server.lua',
'resource/server/framework.lua'
ui_page 'web/build/index.html'

files {
'web/build/index.html',
'web/build/**/*',
'locales/*.lua'
}
19 changes: 15 additions & 4 deletions resource/client.lua → resource/client/client.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
local opened = false
local initialDataSet = false
local playerId = PlayerId()

SetTimeout(500, function()
TriggerServerEvent('ac_scoreboard:playerJoined')
end)

local dataPromise = nil
RegisterNetEvent('ac_scoreboard:receiveData', function(data)
if dataPromise then
dataPromise:resolve(data)
dataPromise = nil
end
end)

---@param action string
---@param data table | boolean
local function sendNuiMessage(action, data)
Expand Down Expand Up @@ -49,15 +57,18 @@ local function getUiLocales()
return uiLocales
end

local initialDataSet = false
local function setData()
local data = lib.callback.await('ac_scoreboard:getData', false)
dataPromise = promise.new()
TriggerServerEvent('ac_scoreboard:requestData')
local data = Citizen.Await(dataPromise)

if not initialDataSet then
initialDataSet = true
data.serverName = ac.serverName
data.visibleParts = ac.visibleParts
data.drawerSide = ac.drawerSide
data.serverId = cache.serverId
data.serverId = GetPlayerServerId(playerId)
data.locales = getUiLocales()
end

Expand All @@ -83,7 +94,7 @@ RegisterCommand(ac.commandName, function()

CreateThread(function()
while opened do
DisablePlayerFiring(cache.playerId, true)
DisablePlayerFiring(playerId, true)
HudWeaponWheelIgnoreSelection()
DisableControlAction(0, 1, true)
DisableControlAction(0, 2, true)
Expand Down
File renamed without changes.
10 changes: 3 additions & 7 deletions resource/server/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,16 @@ CreateThread(function()
end
end)

lib.callback.register('ac_scoreboard:getData', function()
RegisterNetEvent('ac_scoreboard:requestData', function()
-- Convar change handlers are "not really important or worth the risk of badly designing stuff",
-- so we update 'maxPlayers' every 5 minutes if called, like a dicks.
if os.time() - lastMaxPlayers > 300 then
maxPlayers = GetConvarInt('sv_maxclients', 32)
lastMaxPlayers = os.time()
end

return {
TriggerClientEvent('ac_scoreboard:receiveData', source, {
players = players,
maxPlayers = maxPlayers
}
})
end)

if ac.versionCheck then
lib.versionCheck('antond15/ac_scoreboard')
end
34 changes: 34 additions & 0 deletions resource/server/version.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- Yoinked from https://github.com/overextended/ox_lib/blob/master/resource/version/server.lua
if ac.versionCheck then
local currentVersion = GetResourceMetadata('ac_scoreboard', 'version', 0)

if currentVersion then
currentVersion = currentVersion:match('%d%.%d+%.%d+')
end

SetTimeout(1000, function()
PerformHttpRequest('https://api.github.com/repos/antond15/ac_scoreboard/releases/latest', function(status, response)
if status ~= 200 then return end

response = json.decode(response)
if response.prerelease then return end

local latestVersion = response.tag_name:match('%d%.%d+%.%d+')
if not latestVersion or latestVersion == currentVersion then return end

local cv = { string.strsplit('.', currentVersion) }
local lv = { string.strsplit('.', latestVersion) }

for i = 1, #cv do
local current, minimum = tonumber(cv[i]), tonumber(lv[i])

if current ~= minimum then
if current < minimum then
return print(('^3An update is available for ac_scoreboard (current version: %s)\r\n%s^0'):format(currentVersion, response.html_url))
else break end
end
end

end, 'GET')
end)
end

0 comments on commit a9a8ac8

Please sign in to comment.