Skip to content

Commit

Permalink
Update v1.1
Browse files Browse the repository at this point in the history
➥ Improved performance [idle resmon now 0.00 ms]
➥ Implemented msk_core [https://github.com/MSK-Scripts/msk_core]
  • Loading branch information
Musiker15 committed Dec 10, 2022
1 parent b1732d3 commit c06606d
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 81 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Changeable Vehicle Headlights with an Item
## Requirements ##
* ESX 1.2 and above
* NativeUI
* oxmysql
* oxmysql
* msk_core
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0
1.1
56 changes: 27 additions & 29 deletions client.lua
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
ESX = exports["es_extended"]:getSharedObject()

MSK = exports.msk_core:getCoreObject()

CreateThread(function()
while true do
Wait(1000)
local sleep = 1000
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false) -- false = CurrentVehicle, true = LastVehicle

if DoesEntityExist(vehicle) then
local headlight = GetVehicleXenonLightsColor(vehicle)
local plate = GetVehicleNumberPlateText(vehicle)

ESX.TriggerServerCallback("msk_rgbHeadlights:getHeadlightColor", function(color)
if not color then return end
local color = MSK.TriggerCallback("msk_rgbHeadlights:getHeadlightColor", plate)
if not color then return end

if color ~= headlight then
debug('Set headlight to ' .. color)
ToggleVehicleMod(vehicle, 22, true) -- toggle xenon
SetVehicleHeadlightsColour(vehicle, color)
ESX.Game.SetVehicleProperties(vehicle, {
xenonColor = color
})
end
end, plate)
if color ~= headlight then
logging('debug', 'Set headlight to ' .. color)
ToggleVehicleMod(vehicle, 22, true) -- toggle xenon
SetVehicleHeadlightsColour(vehicle, color)
ESX.Game.SetVehicleProperties(vehicle, {
xenonColor = color
})
end
end

Wait(sleep)
end
end)

---- NativeUI ----
_menuPool = NativeUI.CreatePool()
local mainMenu

Citizen.CreateThread(function()
CreateThread(function()
while true do
local sleep = 200
if _menuPool:IsAnyMenuOpen() then
sleep = 0
_menuPool:ProcessMenus()
end
Citizen.Wait(1)
Wait(sleep)
end
end)
---- NativeUI ----
Expand All @@ -46,7 +49,7 @@ AddEventHandler('msk_rgbHeadlights:checkHeadlights', function()
end)

function openHeadlightsMenu()
if mainMenu ~= nil and mainMenu:Visible() then
if mainMenu and mainMenu:Visible() then
mainMenu:Visible(false)
end

Expand Down Expand Up @@ -99,10 +102,10 @@ function setVehicleHeadlight(color)
})
end
TriggerServerEvent('msk_rgbHeadlights:setHeadlights', color, plate)
Config.Notification(source, 'client', nil, Translation[Config.Locale]['new_headlight'] .. color.label)
Config.Notification(nil, 'client', nil, Translation[Config.Locale]['new_headlight'] .. color.label)
setColor = true
else
Config.Notification(source, 'client', nil, Translation[Config.Locale]['not_in_distance'])
Config.Notification(nil, 'client', nil, Translation[Config.Locale]['not_in_distance'])
end
end

Expand Down Expand Up @@ -131,19 +134,14 @@ function setVehicleHeadlight(color)
})
end
TriggerServerEvent('msk_rgbHeadlights:setHeadlights', color, plate)
Config.Notification(source, 'client', nil, Translation[Config.Locale]['new_headlight'] .. color.label)
Config.Notification(nil, 'client', nil, Translation[Config.Locale]['new_headlight'] .. color.label)
end
end
end

function debug(msg, msg2, msg3)
if Config.Debug then
if msg3 then
print('[DEBUG]', msg, msg2, msg3)
elseif msg2 and not msg3 then
print('[DEBUG]', msg, msg2)
else
print('[DEBUG]', msg)
end
end
logging = function(code, msg, msg2, msg3)
if Config.Debug then
local script = "[^2"..GetCurrentResourceName().."^0]"
MSK.logging(script, code, msg, msg2, msg3)
end
end
10 changes: 5 additions & 5 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Config.Debug = true
----------------------------------------------------------------
-- !!! This function is clientside AND serverside !!!
-- Look for type == 'client' and type == 'server'
Config.Notification = function(src, type, xPlayer, message)
if type == 'client' then -- clientside
ESX.ShowNotification(message) -- replace this with your Notify
elseif type == 'server' then -- serverside
xPlayer.showNotification(message) -- replace this with your Notify
Config.Notification = function(src, action, xPlayer, message)
if action == 'client' then -- clientside
MSK.Notification(message) -- replace this with your Notify
elseif action == 'server' then -- serverside
MSK.Notification(src, message) -- replace this with your Notify
end
end
----------------------------------------------------------------
Expand Down
10 changes: 3 additions & 7 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@ games { 'gta5' }
author 'Musiker15 - MSK Scripts'
name 'msk_rgbheadlights'
description 'Changeable Vehicle Headlights with an Item'
version '1.0'
version '1.1'

lua54 'yes'

escrow_ignore {
'config.lua',
'locales/*.lua'
}

shared_script {
'config.lua',
'translation.lua'
Expand All @@ -30,5 +25,6 @@ server_scripts {

dependencies {
'es_extended',
'oxmysql'
'oxmysql',
'msk_core'
}
75 changes: 37 additions & 38 deletions server.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
ESX = exports["es_extended"]:getSharedObject()
MSK = exports.msk_core:getCoreObject()

AddEventHandler('onResourceStart', function(resource)
if resource == GetCurrentResourceName() then
local alterTable = MySQL.query.await("ALTER TABLE owned_vehicles ADD COLUMN IF NOT EXISTS `headlight` varchar(255) DEFAULT NULL;")
local item = MySQL.query.await("SELECT * FROM items WHERE name = @name", {['@name'] = Config.Item.name})

if alterTable and alterTable.warningStatus < 1 then
debug('^2 Successfully ^3 altered ^2 table ^3 owned_vehicles ^0')
if alterTable and alterTable.warningStatus == 0 then
logging('debug', '^2 Successfully ^3 altered ^2 table ^3 owned_vehicles ^0')
end

if not item[1] then
debug('^1 Item ^3 ' .. Config.Item.name .. ' ^1 not exists, inserting item... ^0')
logging('debug', '^1 Item ^3 ' .. Config.Item.name .. ' ^1 not exists, inserting item... ^0')
local insertItem = MySQL.query.await("INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES ('" .. Config.Item.name .. "', '" .. Config.Item.label .. "', 1, 0, 1);")
if insertItem then
debug('^2 Successfully ^3 inserted ^2 Item ^3 ' .. Config.Item.name .. ' ^2 in ^3 items ^0')
logging('debug', '^2 Successfully ^3 inserted ^2 Item ^3 ' .. Config.Item.name .. ' ^2 in ^3 items ^0')
end
end
end
Expand All @@ -30,7 +31,7 @@ RegisterServerEvent('msk_rgbHeadlights:setHeadlights')
AddEventHandler('msk_rgbHeadlights:setHeadlights', function(color, plate)
local src = source
local xPlayer = ESX.GetPlayerFromId(src)
debug('Set Headlight to ' .. color.color .. ' from Plate ' .. plate)
logging('debug', 'Set Headlight to ' .. color.color .. ' from Plate ' .. plate)

if color.color == -1 or color.color == 'xenon' then
MySQL.query('UPDATE owned_vehicles SET headlight = @headlight WHERE plate = @plate', {
Expand All @@ -49,7 +50,7 @@ AddEventHandler('msk_rgbHeadlights:setHeadlights', function(color, plate)
end
end)

ESX.RegisterServerCallback("msk_rgbHeadlights:getHeadlightColor", function(source, cb, plate)
MSK.RegisterCallback("msk_rgbHeadlights:getHeadlightColor", function(source, cb, plate)
local owned_vehicles = MySQL.query.await("SELECT * FROM owned_vehicles WHERE plate = @plate", {['@plate'] = plate})

if owned_vehicles[1] and owned_vehicles[1].headlight then
Expand All @@ -59,40 +60,38 @@ ESX.RegisterServerCallback("msk_rgbHeadlights:getHeadlightColor", function(sourc
end
end)

function debug(msg, msg2, msg3)
if Config.Debug then
if msg3 then
print('[DEBUG]', msg, msg2, msg3)
elseif msg2 and not msg3 then
print('[DEBUG]', msg, msg2)
else
print('[DEBUG]', msg)
end
end
logging = function(code, msg, msg2, msg3)
if Config.Debug then
local script = "[^2"..GetCurrentResourceName().."^0]"
MSK.logging(script, code, msg, msg2, msg3)
end
end

---- GitHub Updater ----

function GetCurrentVersion()
return GetResourceMetadata( GetCurrentResourceName(), "version" )
end

local CurrentVersion = GetCurrentVersion()
local resourceName = "^4["..GetCurrentResourceName().."]^0"
GithubUpdater = function()
GetCurrentVersion = function()
return GetResourceMetadata( GetCurrentResourceName(), "version" )
end

local CurrentVersion = GetCurrentVersion()
local resourceName = "^4["..GetCurrentResourceName().."]^0"

if Config.VersionChecker then
PerformHttpRequest('https://raw.githubusercontent.com/MSK-Scripts/msk_rgbHeadlights/main/VERSION', function(Error, NewestVersion, Header)
print("###############################")
if CurrentVersion == NewestVersion then
print(resourceName .. '^2 ✓ Resource is Up to Date^0 - ^5Current Version: ^2' .. CurrentVersion .. '^0')
elseif CurrentVersion ~= NewestVersion then
print(resourceName .. '^1 ✗ Resource Outdated. Please Update!^0 - ^5Current Version: ^1' .. CurrentVersion .. '^0')
print('^5Newest Version: ^2' .. NewestVersion .. '^0 - ^6Download here: ^9https://github.com/MSK-Scripts/msk_rgbHeadlights/releases/tag/v'.. NewestVersion .. '^0')
end
print("###############################")
end)
else
print("###############################")
print(resourceName .. '^2 ✓ Resource loaded^0')
print("###############################")
end
if Config.VersionChecker then
PerformHttpRequest('https://raw.githubusercontent.com/MSK-Scripts/msk_rgbHeadlights/main/VERSION', function(Error, NewestVersion, Header)
print("###############################")
if CurrentVersion == NewestVersion then
print(resourceName .. '^2 ✓ Resource is Up to Date^0 - ^5Current Version: ^2' .. CurrentVersion .. '^0')
elseif CurrentVersion ~= NewestVersion then
print(resourceName .. '^1 ✗ Resource Outdated. Please Update!^0 - ^5Current Version: ^1' .. CurrentVersion .. '^0')
print('^5Newest Version: ^2' .. NewestVersion .. '^0 - ^6Download here:^9 https://github.com/MSK-Scripts/msk_rgbHeadlights/releases/tag/v'.. NewestVersion .. '^0')
end
print("###############################")
end)
else
print("###############################")
print(resourceName .. '^2 ✓ Resource loaded^0')
print("###############################")
end
end
GithubUpdater()

0 comments on commit c06606d

Please sign in to comment.