Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions ulc/client/c_brake.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
--print("[ULC] Brake Extras Loaded")
local realBrakeThreshold = 3
local shouldUseRealBrakes = function()
if not MyVehicleConfig then
print("[ULC:shouldUseRealBrakes] WARNING: Function called but MyVehicleConfig is not loaded. This function should not be called without a valid configuration.")
return false
end
return (MyVehicleConfig.brakeConfig.speedThreshold or 3) <= realBrakeThreshold
end
local braking = false
Expand All @@ -12,6 +16,10 @@ local braking = false
local disabledExtras = {}

local function setBrakeExtras(newState)
if not MyVehicleConfig then
print("[ULC:setBrakeExtras] WARNING: Function called but MyVehicleConfig is not loaded. This function should not be called without a valid configuration.")
return
end
for _, v in pairs(MyVehicleConfig.brakeConfig.brakeExtras) do
local currentState
if IsVehicleExtraTurnedOn(MyVehicle, v) then currentState = 0 else currentState = 1 end
Expand Down Expand Up @@ -63,7 +71,7 @@ if shouldUseRealBrakes then
sleep = 1000
goto continue
end
if not MyVehicleConfig.brakeConfig.useBrakes then
if not MyVehicleConfig or not MyVehicleConfig.brakeConfig.useBrakes then
sleep = 1000
goto continue
end
Expand All @@ -87,7 +95,7 @@ if shouldUseRealBrakes then
Wait(0) -- Nedded as GetEntityFromStateBagName sometimes returns 0 on first frame
mode = "RBL" -- set mode to RBL to disable manual checking
if not MyVehicle then return end
if not MyVehicleConfig.brakeConfig.useBrakes then return end
if not MyVehicleConfig or not MyVehicleConfig.brakeConfig.useBrakes then return end
local vehicle = GetEntityFromStateBagName(bagName)
--print("state changed for vehicle")
if vehicle == 0 or vehicle ~= MyVehicle then return end
Expand All @@ -105,7 +113,7 @@ end
-- pressed brakes
RegisterCommand('+ulc:brakePattern', function()
braking = true
if MyVehicle and MyVehicleConfig.brakeConfig.useBrakes then
if MyVehicle and MyVehicleConfig and MyVehicleConfig.brakeConfig.useBrakes then
if GetVehicleCurrentGear(MyVehicle) == 0 then return end -- disable while reversing
--print("Enabling brakes")
local speed = GetVehicleSpeedConverted(MyVehicle)
Expand All @@ -122,7 +130,7 @@ end)

RegisterCommand('-ulc:brakePattern', function()
braking = false
if MyVehicle and MyVehicleConfig.brakeConfig.useBrakes then
if MyVehicle and MyVehicleConfig and MyVehicleConfig.brakeConfig.useBrakes then
local speed = GetVehicleSpeedConverted(MyVehicle)
if shouldUseRealBrakes() and speed < realBrakeThreshold then return end
--print("Disabling brakes")
Expand Down
10 changes: 9 additions & 1 deletion ulc/client/c_buttons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
-------------------

function GetExtraByKey(key)
if not MyVehicleConfig then
print("[ULC:GetExtraByKey] ERROR: MyVehicleConfig is not loaded. This usually means there's a syntax error in your ulc.lua file. Check server console for details.")
return nil
end
local result = nil
for _, v in pairs(MyVehicleConfig.buttons) do
if v.key == key then
Expand All @@ -17,6 +21,10 @@ function GetExtraByKey(key)
end

function GetButtonByExtra(extra)
if not MyVehicleConfig then
print("[ULC:GetButtonByExtra] ERROR: MyVehicleConfig is not loaded. This usually means there's a syntax error in your ulc.lua file. Check server console for details.")
return nil
end
local result = nil
for _, v in pairs(MyVehicleConfig.buttons) do
if v.extra == extra then
Expand Down Expand Up @@ -126,7 +134,7 @@ function ULC:SetStage(extra, action, playSound, extraOnly, repair, forceChange,
----------------------
-- smart stages stuff
local key = button.key
if MyVehicleConfig.stages then
if MyVehicleConfig and MyVehicleConfig.stages then
local keyStage = contains(MyVehicleConfig.stages.stageKeys, key) -- find whether MyVehicleConfig.stages.stageKeys contain the key

-- # TODO we're not getting here for some reason when cycling stages at max stage
Expand Down
16 changes: 14 additions & 2 deletions ulc/client/c_cruise.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ local sbState = 1

-- 0 on, 1 off
local function setCruiseLights(newState)
if not MyVehicleConfig then
print("[ULC:setCruiseLights] WARNING: Function called but MyVehicleConfig is not loaded. This function should not be called without a valid configuration.")
return
end
sbState = newState
for _, v in pairs(MyVehicleConfig.steadyBurnConfig.sbExtras) do
--print("Setting cruise lights extra: " .. v)
Expand All @@ -13,6 +17,10 @@ local function setCruiseLights(newState)
end

local function getSteadyBurnState()
if not MyVehicleConfig then
print("[ULC:getSteadyBurnState] WARNING: Function called but MyVehicleConfig is not loaded. This function should not be called without a valid configuration.")
return 1
end
if IsVehicleExtraTurnedOn(MyVehicle, MyVehicleConfig.steadyBurnConfig.sbExtras[1]) then
return 0
else
Expand All @@ -33,21 +41,25 @@ end)

AddEventHandler('ulc:lightsOn', function()
--print("Lights on")
if MyVehicle and (MyVehicleConfig.steadyBurnConfig.disableWithLights or false) then
if MyVehicle and MyVehicleConfig and (MyVehicleConfig.steadyBurnConfig.disableWithLights or false) then
setCruiseLights(1)
end
end)

AddEventHandler('ulc:lightsOff', function()
--print("Lights off")
if MyVehicle and (MyVehicleConfig.steadyBurnConfig.disableWithLights or false) then
if MyVehicle and MyVehicleConfig and (MyVehicleConfig.steadyBurnConfig.disableWithLights or false) then
TriggerEvent('ulc:CheckCruise')
end
end)

AddEventHandler('ulc:CheckCruise', function()
sbState = getSteadyBurnState()
if not MyVehicle then return end
if not MyVehicleConfig then
print("[ULC:CheckCruise] WARNING: Event handler called but MyVehicleConfig is not loaded. This should not happen.")
return
end

if Entity(MyVehicle).state.ulc_blackout == 0 then
-- print("Blackout is on, disabling cruise lights")
Expand Down
6 changes: 5 additions & 1 deletion ulc/client/c_doors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ end

-- state 1 = closed, state 0 = open
local function onDoorStateChange(door, newDoorState)
if not MyVehicleConfig then
print("[ULC:onDoorStateChange] WARNING: Function called but MyVehicleConfig is not loaded. This function should not be called without a valid configuration.")
return
end
--print("Handling door change", door, newDoorState)
if door == 0 or door == 2 then -- if driver side
for _, v in pairs(MyVehicleConfig.doorConfig.driverSide.enable) do
Expand Down Expand Up @@ -54,7 +58,7 @@ CreateThread(function()
sleep = 1000
goto continue
end
if not MyVehicleConfig.doorConfig or false then
if not MyVehicleConfig or not MyVehicleConfig.doorConfig or false then
sleep = 1000
goto continue
end
Expand Down
4 changes: 2 additions & 2 deletions ulc/client/c_horn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ RegisterCommand('+ulc:horn', function()
--print('horn')
extraStates = {}

if MyVehicle and MyVehicleConfig.hornConfig.useHorn then
if MyVehicle and MyVehicleConfig and MyVehicleConfig.hornConfig.useHorn then
SetHornExtras(0)
end
end)

RegisterCommand('-ulc:horn', function()
if MyVehicle and MyVehicleConfig.hornConfig.useHorn then
if MyVehicle and MyVehicleConfig and MyVehicleConfig.hornConfig.useHorn then
SetHornExtras(1)
end
end)
Expand Down
4 changes: 2 additions & 2 deletions ulc/client/c_park.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ AddEventHandler('ulc:vehPark', function()
--print('[ulc:vehPark] My vehicle is parked.')
parked = true

if MyVehicle and MyVehicleConfig.parkConfig.usePark then
if MyVehicle and MyVehicleConfig and MyVehicleConfig.parkConfig.usePark then
-- enable pExtras
for _, v in pairs(MyVehicleConfig.parkConfig.pExtras) do
ULC:SetStage(v, 0, false, true, false, false, true, false)
Expand Down Expand Up @@ -136,7 +136,7 @@ AddEventHandler('ulc:vehDrive', function()
if Lights then
--print('[ulc:vehDrive] My vehicle is driving.')
parked = false
if MyVehicle and MyVehicleConfig.parkConfig.usePark then
if MyVehicle and MyVehicleConfig and MyVehicleConfig.parkConfig.usePark then
-- disable pExtras
for _, v in pairs(MyVehicleConfig.parkConfig.pExtras) do
ULC:SetStage(v, 1, false, true, false, false, true, false)
Expand Down
5 changes: 5 additions & 0 deletions ulc/client/c_reverse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ local disabledExtras = {}
local timerExpired = false

function setReverseExtras(newState)
if not MyVehicleConfig then
print("[ULC:setReverseExtras] WARNING: Function called but MyVehicleConfig is not loaded. This function should not be called without a valid configuration.")
return
end
-- set enable extras to match the new state
for _, v in ipairs(MyVehicleConfig.reverseConfig.reverseExtras) do
ULC:SetStage(v, newState, false, true, false, false, true, false)
Expand Down Expand Up @@ -36,6 +40,7 @@ AddEventHandler('ulc:StartCheckingReverseState', function()
if not IsPedInAnyVehicle(PlayerPedId()) then return end
-- this feels unncessary, but I think some people may not have .reverseConfig
if not MyVehicle then return end
if not MyVehicleConfig then return end
if not MyVehicleConfig.reverseConfig then return end
if not MyVehicleConfig.reverseConfig.useReverse then return end
local gear = GetVehicleCurrentGear(MyVehicle)
Expand Down
11 changes: 11 additions & 0 deletions ulc/client/c_signals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ local combinedExtrasTable = {}
AddEventHandler("ulc:SetupSignalExtrasTable", function()
print('[ulc:SetupSignalExtrasTable] Setting up signal extras table')

if not MyVehicleConfig then
print("[ULC:SetupSignalExtrasTable] WARNING: Event handler called but MyVehicleConfig is not loaded. This should not happen.")
return
end
if not MyVehicleConfig.signalConfig then return end

local extras = {}


Expand Down Expand Up @@ -41,6 +47,11 @@ IndicatorState = 0
local savedExtraStates = {}

local function saveExtraStates()
if not MyVehicleConfig then
print("[ULC:saveExtraStates] WARNING: Function called but MyVehicleConfig is not loaded. This function should not be called without a valid configuration.")
return
end
if not MyVehicleConfig.signalConfig then return end
-- get states of all extras listed in signalConfig
local extras = {}
for _, side in pairs({ "left", "right", "hazard" }) do
Expand Down
10 changes: 9 additions & 1 deletion ulc/client/c_stages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ currentStage = 0
-- helpers
local function checks()
if not MyVehicle then return false end
if not MyVehicleConfig then return false end
if not MyVehicleConfig.stages then return false end
if not MyVehicleConfig.stages.useStages then return false end
if not MyVehicleConfig.stages.stageKeys then return false end
Expand All @@ -19,6 +20,7 @@ end

function getMaxStage()
if not MyVehicle then return end
if not MyVehicleConfig then return end
if not MyVehicleConfig.stages then return end
if not MyVehicleConfig.stages.stageKeys then return end
return #MyVehicleConfig.stages.stageKeys
Expand Down Expand Up @@ -122,7 +124,9 @@ end)
function getStageFromButton(button)
if not button then return false end
if not MyVehicle then return false end
-- if MyVehicleConfig.stages.stageKeys is nil or doesn't contain the button.key return false
if not MyVehicleConfig then return false end
if not MyVehicleConfig.stages then return false end
-- if stageKeys doesn't exist or doesn't contain the button.key return false
if not MyVehicleConfig.stages.stageKeys then return false end
for i, key in pairs(MyVehicleConfig.stages.stageKeys) do
if key == button.key then
Expand All @@ -134,6 +138,10 @@ end

function setDefaultStages()
-- default stages
if not MyVehicleConfig then
print("[ULC:setDefaultStages] WARNING: Function called but MyVehicleConfig is not loaded. This function should not be called without a valid configuration.")
return
end
if not MyVehicleConfig.defaultStages or false then return end
if not MyVehicleConfig.defaultStages.useDefaults then return end
for _, e in pairs(MyVehicleConfig.defaultStages.enableKeys) do
Expand Down
3 changes: 2 additions & 1 deletion ulc/server/s_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ local function LoadExternalVehicleConfig(resourceName)
local f, err = load(data)
if err then
TriggerEvent("ulc:error",
'^1Could not load external configuration in: "' .. resourceName .. '"; error: "' .. err .. '"^0')
'^1Could not load external configuration in: "' .. resourceName .. '"; SYNTAX ERROR: ' .. err .. '^0')
print("^3[ULC] HINT: Check the ulc.lua file in '" .. resourceName .. "' for syntax errors like missing commas, brackets, or quotes.^0")
return
end
if not f or not f() then
Expand Down