Hello FiveM community,
I’m doing some experiments scripting with LUA, before doing my first script.
So I’m trying to create a livery changer script, that should work as follows:
When a player presses L (182), it changes the livery of the car to the next one.
I commented the code to make it easier to understand (although it’s really simple and clear).
function changeLivery(vehicle) -- Function to change the livery
-- It changes the livery between the first one (0) and 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
else if 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)
SetVehicleLivery(vehicle, livery) -- Native function to set the livery of the vehicle to the above specified livery
DisplayHelpText("~b~Livery ~g~Changed.") -- Success message
while true do -- Loop that triggers the livery changer function
ped = GetPlayerPed(-1)
if IsPedInAnyVehicle(ped, false) then -- Only be able to change the livery if the player is in a vehicle
vehicle = GetVehiclePedIsUsing(ped) -- Get the player vehicle's entity
livery = GetVehicleLivery(vehicle) -- Current livery
if IsControlJustPressed(1, 182) then -- If player presses the L key
changeLivery(vehicle) -- The livery changer function gets triggered, on the player's vehicle
DisplayHelpText("~b~You must be in a vehicle in order to change your livery!") -- Error message
Thanks so much in advance for your help, cause I would be really happy as well as infinitely thankful if someone could help me out!