Skip to content

Commit

Permalink
Add config settings for reverse timer
Browse files Browse the repository at this point in the history
  • Loading branch information
Flohhhhh committed Sep 18, 2024
1 parent d2f1374 commit c60f0bb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
15 changes: 10 additions & 5 deletions ulc/client/c_reverse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ end)

-- handle disabling lights after some time
function startTimer()
-- if disabled in config, don't start timer , if enabled or missing config, start timer
if Config and Config.ReverseSettings and not Config.ReverseSettings.useRandomExpiration then return end
-- timer thread
CreateThread(function()
local speed
local duration
local duration = math.random(3, 8) * 1000
local expirationTime

while true do
Expand All @@ -79,7 +82,12 @@ function startTimer()
if timerExpired then
goto continue
end
duration = math.random(3000, 8000)
if Config and Config.ReverseSettings then
duration = math.random(
(Config.ReverseSettings.minExpiration or 3) * 1000,
(Config.ReverseSettings.maxExpiration or 8) * 1000
)
end
expirationTime = GetGameTimer() + duration
while GetGameTimer() < expirationTime do
Wait(500)
Expand All @@ -89,17 +97,14 @@ function startTimer()
-- print("[ULC] Reverse: Moving, breaking timer")
break
end

if not reversing then
-- print("[ULC] Reverse: Not reversing, breaking timer")
break
end

if not IsPedInAnyVehicle(PlayerPedId()) then
-- print("[ULC] Reverse: Not in vehicle, breaking timer")
break
end

if GetGameTimer() > expirationTime then
print("[ULC] Reverse: Timer expired, disabling extras")
timerExpired = true
Expand Down
14 changes: 14 additions & 0 deletions ulc/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ Config = {
-- temporarily empty as of v1.3.0
BrakeSettings = {},

-- Reverse Extras/Patterns Config;
-- introduced in v1.8.0
ReverseSettings = {
-- these options control the expiration of the reverse extras
-- if enabled, reverse extras will turn off after a random time between min and max
-- this is to simulate more realistic behavior where the vehicle would shifted out of reverse
-- after being stopped for some time
useRandomExpiration = true,
-- minimum time in seconds extras will stay on after stopping
minExpiration = 3,
-- maximum time in seconds extras will stay on after stopping
maxExpiration = 8,
},

-- Import confiurations here
-- Add the resource names of vehicle resources that include a ulc.lua config file
ExternalVehResources = {
Expand Down
31 changes: 15 additions & 16 deletions ulc/server/s_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,24 +184,23 @@ local function CheckData(data, resourceName)
resourceName ..
'" uses Default Stages, but no keys were specified to enable (enableKeys = {}) or disable (disableKeys = {}).')
else
for _, v in pairs(data.defaultStages.enableKeys) do
if v > 9 then
TriggerEvent("ulc:error",
'A config in "' ..
resourceName .. '" has an invalid key in enableKeys = {}. Value must be 1-9 representing numpad keys.')
if #data.defaultStages.enableKeys > 0 then
for _, v in pairs(data.defaultStages.enableKeys) do
if v > 9 then
TriggerEvent("ulc:error",
'A config in "' ..
resourceName ..
'" has an invalid key in enableKeys = {}. Value must be 1-9 representing numpad keys.')
end
end
end
end
if #data.defaultStages.disableKeys == 0 then
TriggerEvent("ulc:warn",
'A config in "' ..
resourceName .. '" uses Default Stages, but no keys were specified to disable (disableKeys = {}).')
else
for _, v in pairs(data.defaultStages.disableKeys) do
if v > 9 then
TriggerEvent("ulc:error",
'A config in "' ..
resourceName .. '" has an invalid key in disableKeys = {}. Value must be 1-9 representing numpad keys.')
if #data.defaultStages.disableKeys > 0 then
for _, v in pairs(data.defaultStages.disableKeys) do
if v > 9 then
TriggerEvent("ulc:error",
'A config in "' ..
resourceName .. '" has an invalid key in disableKeys = {}. Value must be 1-9 representing numpad keys.')
end
end
end
end
Expand Down

0 comments on commit c60f0bb

Please sign in to comment.