I am trying to create a livery command, got it about 1/2 way working right now.
-- Livery --
AddEventHandler('chatMessage',function(player, playerName, message)
local msg = string.lower(message)
if msg == '/livery' then
TriggerClientEvent('VehicleLivery', player)
CancelEvent()
end
end)
It is changing the livery but only to the first livery in the file. Anyone wanna help me set this up so I could cycle through or even do /livery 1 or /livery 2
There are better solutions for this to count liveries and do cycling, but this will enable you to do your /livery 0 /livery 1 /livery etc thing. Are you using a custom chat and cannot register commands?
-- Livery Server--
AddEventHandler('chatMessage',function(player, playerName, message)
local msg = split(message, ' ')
if msg[1] == '/livery' then
TriggerClientEvent('VehicleLivery', player, msg[2])
CancelEvent()
end
end)
function split(s, delimiter)
result = {};
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match);
end
return result;
end
-- Livery Client--
RegisterNetEvent('VehicleLivery')
AddEventHandler('VehicleLivery', function(livery)
local Veh = GetVehiclePedIsIn(GetPlayerPed(-1))
SetVehicleLivery(Veh, livery) --CHANGE livery(id)
end)
We can use commands, was just going to put this code into our vehicle control script but I will try out what you sent, then I get to have the fun of doing extras for police vehicles lol
Ok Above is working perfect, thanks man! Appreciate it
Extras are a bit trickier but you can come up with some function that loops through a static range from x=0 to x<something (can’t recall how many slots was observed as a max) calling DoesExtraExist(vehicle, x) and then placing those results into an indexed table. From there the same approach of /extra 0, /extra 1, /extra 2 could be used to toggle on and off if you also use IsVehicleExtraTurnedOn(vehicle, x) to decide how to toggle.
Yeah, figured it would be. Found someone he made a menu for it but would rather then menu show up when I type /extras or something, for now it is bound to f6 which wont work at the moment
You are probably using a customized chat resource that does not recognize CFX registered commands. If the script I posted above works for you then try with other vehicles. A lot of them do not have any liveries, some only have 1 or 2. Try the “PONY” model, there is a livery for plain, one for sprunk, one for cleaners, and one for GoPostal. That should show you if it works more than once. /livery 0, /livery 1, /livery 2, /livery 3.
I have a car called the 2015polstang, It has multiple liveries, what I did was do /livery 2 but it went to the last livery, So I used what was posted above and it works completely fine just in the f8 menu sadly.