I worked on it a bit and added some stuff:
To “veh create” I added so it will delete previous vehicle and you wont have to turn on the engine every time you spawn a car. Plus a notify system to notify the vehicle was spawned and the previous vehicle was deleted.
Added “set vehicle color” for /car and /delveh - #8 by iSheesho
iSheesho’s example: /car elegy red
Changed /delveh to my own /dv command I made a while back
my client.lua
-- made by: DeerMan#2421
-- since it's a simple script you can do whatever you want with it as long as you don't sell it
RegisterCommand('car', function(source, args)
-- don't mess with this
local vehicleName = args[1] or 'adder'
local string = args[2]
local vehiclecolor = tostring(string)
-- check if vehicle actually exists
-- if you want to change the message that pops up if the vehicle model is not recognized change line 9, keep the {""} and type wathever you want
if not IsModelInCdimage(vehicleName) or not IsModelAVehicle(vehicleName) then
TriggerEvent("chat:addMessage", {
args = {config.notrecognised .. vehicleName}
})
return
end
RequestModel(vehicleName)
while not HasModelLoaded(vehicleName) do
Wait(500)
end
--get player position
local playerPed = PlayerPedId()
local pos = GetEntityCoords(playerPed)
--veh create
local vehicle = CreateVehicle(vehicleName, pos.x, pos.y, pos.z, GetEntityHeading(playerPed), true, false)
local handle = GetVehiclePedIsIn(GetPlayerPed(-1), true)
NetworkRequestControlOfEntity(handle)
SetEntityHealth(handle, 100)
SetEntityAsMissionEntity(handle, true, true)
SetEntityAsNoLongerNeeded(handle)
DeleteEntity(handle)
SetPedIntoVehicle(playerPed, vehicle, -1)
SetVehicleEngineOn(vehicle, true, true, false)
SetVehicleNeedsToBeHotwired(vehicle, false)
SetModelAsNoLongerNeeded(vehicleName)
notify("~g~Vehicle Spawned!~s~ ".. vehicleName)
notify("~r~Last Vehicle Deleted~s~, So The Server Doesnt Lag!")
TriggerEvent("chat:addMessage", {
args = {config.recognised .. vehicleName .. '.'}
})
--set vehicle color
if vehiclecolor == "black" then
SetVehicleCustomPrimaryColour(vehicle, 0, 0, 0)
SetVehicleCustomSecondaryColour(vehicle, 0, 0, 0)
end
if vehiclecolor == "red" then
SetVehicleCustomPrimaryColour(vehicle, 255, 0, 0)
SetVehicleCustomSecondaryColour(vehicle, 255, 0, 0)
end
if vehiclecolor == "orange" then
SetVehicleCustomPrimaryColour(vehicle, 255, 125, 0)
SetVehicleCustomSecondaryColour(vehicle, 255, 125, 0)
end
if vehiclecolor == "green" then
SetVehicleCustomPrimaryColour(vehicle, 0, 255, 0)
SetVehicleCustomSecondaryColour(vehicle, 0, 255, 0)
end
if vehiclecolor == "blue" then
SetVehicleCustomPrimaryColour(vehicle, 0, 0, 255)
SetVehicleCustomSecondaryColour(vehicle, 0, 0, 255)
end
if vehiclecolor == "purple" then
SetVehicleCustomPrimaryColour(vehicle, 125, 0, 255)
SetVehicleCustomSecondaryColour(vehicle, 125, 0, 255)
end
if vehiclecolor == "yellow" then
SetVehicleCustomPrimaryColour(vehicle, 255, 255, 0)
SetVehicleCustomSecondaryColour(vehicle, 255, 255, 0)
end
if vehiclecolor == "brown" then
SetVehicleCustomPrimaryColour(vehicle, 42, 25, 17)
SetVehicleCustomSecondaryColour(vehicle, 42, 25, 17)
end
if vehiclecolor == "white" then
SetVehicleCustomPrimaryColour(vehicle, 255, 255, 255)
SetVehicleCustomSecondaryColour(vehicle, 255, 255, 255)
end
if vehiclecolor == "pink" then
SetVehicleCustomPrimaryColour(vehicle, 255, 0, 255)
SetVehicleCustomSecondaryColour(vehicle, 255, 0, 255)
end
if vehiclecolor == "chrome" then
SetVehicleColours(vehicle, 120, 120)
end
end, false)
TriggerEvent('chat:addSuggestion', '/car', 'spawn car by model name and change its color', {
{name = 'model', help = 'car model to spawn'},
{name = 'color', help = 'color to spawn the car in'}
})
--delete vehicle
RegisterCommand("dv", function()
deleteVeh()
notify("~r~Vehicle Deleted!")
end)
function deleteVeh()
local ped = GetPlayerPed(-1)
if (DoesEntityExist(ped) and not IsEntityDead(ped)) then
local pos = GetEntityCoords(ped)
if (IsPedSittingInAnyVehicle(ped)) then
local handle = GetVehiclePedIsIn(ped, false)
NetworkRequestControlOfEntity(handle)
SetEntityHealth(handle, 100)
SetEntityAsMissionEntity(handle, true, true)
SetEntityAsNoLongerNeeded(handle)
DeleteEntity(handle)
end
end
end
--notify
function notify(text)
SetNotificationTextEntry("STRING")
AddTextComponentString(text)
DrawNotification(true, true)
end