Livery command


#1

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)
-- Livery --
RegisterNetEvent('VehicleLivery')
AddEventHandler('VehicleLivery', function()
	local Veh = GetVehiclePedIsIn(GetPlayerPed(-1))

	SetVehicleLivery(Veh, livery) --CHANGE livery(id)
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


#3

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)

#4

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


#5

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.


#6

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


#7

You should use RegisterCommand :wink:


#8
RegisterCommand('livery', function(source, args, rawCommand)
	local Veh = GetVehiclePedIsIn(GetPlayerPed(-1))
  local livery = tonumber(args[1])

  SetVehicleLivery(Veh, livery) --CHANGE livery(id)
  drawNotification("Vehicle Livery ~r~"..livery.."~s~ loaded!")
end)

function drawNotification(Notification)
	SetNotificationTextEntry('STRING')
	AddTextComponentString(Notification)
	DrawNotification(false, false)
end

That should work, and its just a client file :stuck_out_tongue: