/car and /delveh

What it does:
type /car (vehicle model)
if the vehicle model does exist it will spawn, if it doesn’t then it won’t

type /delveh
deletes current vehicle.

How to install:
drag and drop and then start the resource in server.cfg

preview: /car
preview1

Preview: /delveh
preview2

What’s new:
Added a config where you can change any messages.

Install here:
cardelveh.zip (1.3 KB) V1
cardelveh.zip (1.9 KB) V2

V1 is the original version with just the simple /car and /delveh
V2 is the perfected version with more commands edited by KrimsinS15

2 Likes

Very simple script :frowning:
<50 lines

but does exactly what it’s supposed to do

Yes but that is only because it isn’t a very complicated script.

Sure, I’m just saying this because of the rules that exist about posting free scripts on the forum.

  • Few Lines. Releases with minimal code (such as only one script file that contains less than 50 lines) are considered too simple and is not allowed. We want users to release meaningful, configurable and complete scripts. Everyone starts somewhere, but not every little script you create needs to be shared.

I guess it’s a solution for standalone users as this exists for ESX and QB frameworks

Does that also count the fxmanifest?

Perhaps you could make the script a bit more “advanced” and create a config file and have the user determine if the /car causes their character to be inside the vehicle when it is created or spawn in front of them.

Perhaps you could create a second argument where you can choose the color of the vehicle (Example: /car elegy red). This will make your script more valuable and different than what already exists.

1 Like

I’ll do that thanks for the idea!

If you need a script like this you should not run your own server cause you know nothing about coding lmao. Simple to insert it to es_extended without extra script

1 Like

Not everyone uses ESX or QBCore, this is a standalone release

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
1 Like

Colors are:
black
red
orange
green
blue
purple
yellow
brown
white
pink
chrome

I posted a version with color chooser in it. /car and /delveh - #13 by KrimsinS15

Do you mind if I take snippets of you’re code and integrate them with my original code, I’ll give you credit?

I dont mind, just helping out use any code you want.