Found the issue. It apparently was a syntax error. See line 5? I typed else if instead of elseif, cause I come from JavaScript…
Now it works, and even detects when I enter a vehicle, BUT it does not detect when I press L…
Some help would still be highly appreciated!
Updated code below:
print('Script loaded')
function changeLivery(vehicle) -- Function to change the livery
print('changeLivery function loaded')
-- It changes the livery between the first one (0), to the 10th one (9)
if livery < 9 then -- If the current livery is between 0 and 8 (we are still able to go further)
livery = livery + 1 -- So we change to the next one
elseif livery == 9 then -- If the current livery is the last one (9)
livery = 0 -- Since we can't change to the nexxt one (cause the next is 10, which does not exist), we change it back to 0 (first one)
end
SetVehicleLivery(vehicle, livery) -- Native function to set the livery of the vehicle to the above specified livery
print('Livery should have been changed now')
end
Citizen.CreateThread(function()
while true do -- Loop that triggers the livery changer function
print('The script is OK')
Wait(0)
ped = GetPlayerPed(-1)
if IsPedInAnyVehicle(ped, false) then -- Only be able to change the livery if the player is in a vehicle
print('Vehicle enter event TRIGGERED')
vehicle = GetVehiclePedIsUsing(ped) -- Get the player vehicle's entity
livery = GetVehicleLivery(vehicle) -- Current livery
if IsControlJustPressed(1, 7) then -- If player presses the L key
print('L key press event TRIGGERED')
changeLivery(vehicle) -- The livery changer function gets triggered, on the player's vehicle
end
end
end
end)