Skip to content

Commit

Permalink
feat(resource): Added optional update checker
Browse files Browse the repository at this point in the history
Signed-off-by: Nullified <[email protected]>
  • Loading branch information
Gittified committed Oct 13, 2022
1 parent 0838117 commit c64480f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
7 changes: 4 additions & 3 deletions config.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Config = {}

Config.GripRoads = {1, 4, 3, 7, 181, 15, 13, 55, 68, 69, 12}
Config.OffroadClass = {9}
Config.UpdateCheck = true -- Check for update on resource start?
Config.GripRoads = { 1, 4, 3, 7, 181, 15, 13, 55, 68, 69, 12 }
Config.OffroadClass = { 9 }

-- Client side notifications!
Config.Notification = function(message)
Expand All @@ -10,4 +11,4 @@ Config.Notification = function(message)
multiline = true,
args = { 'null_offroad', message }
})
end
end
2 changes: 2 additions & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
fx_version 'cerulean'
games { 'gta5' }

version 'v1.0.0-beta' -- Do not modify
lua54 'yes'

author 'Nullified'
Expand Down
4 changes: 4 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ end)

AddEventHandler('onResourceStart', function(resName)
if resourceName == resName then
if Config.UpdateCheck then
UpdateCheck()
end

MySQL.query.await("CREATE TABLE IF NOT EXISTS `vehicles_offroad` (`model` bigint(20) NOT NULL, `comment` longtext DEFAULT NULL, PRIMARY KEY (`model`))")

CreateThread(function()
Expand Down
11 changes: 11 additions & 0 deletions server/update.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function UpdateCheck()
PerformHttpRequest('https://api.github.com/repos/Gittified/null_offroad/releases/latest', function(code, response)
local data = json.decode(response)
local currentVersion = GetResourceMetadata(GetCurrentResourceName(), 'version', 0)

if data.tag_name ~= currentVersion then
print('^3An update is available for null_offroad (current version: ' ..
currentVersion .. ')\r\n' .. data.html_url .. '^0')
end
end, 'GET')
end

0 comments on commit c64480f

Please sign in to comment.