Description
A developer/admin /car <model> command that spawns any vehicle and drops the player straight into the driver's seat. It is the single most-requested starter script and the foundation every other vehicle mod builds on — get the model-streaming pattern right here and everything downstream is easier.
Prompt Template
You are writing a client-side FiveM Lua script (no framework required). Create a
single client.lua that registers a chat command "/[COMMAND — e.g. car]" taking
one argument: a vehicle model name (default "[DEFAULT_MODEL — e.g. adder]").
Hard requirements (pre-empt the common bugs):
1. Compute the model hash with GetHashKey(modelName).
2. VALIDATE the model first: bail with a chat error if not IsModelInCdimage(hash)
or not IsModelAVehicle(hash).
3. Stream the model correctly: RequestModel(hash), then
`while not HasModelLoaded(hash) do Wait(0) end` with a ~10s timeout guard so a
bad model never hangs the thread.
4. Use PlayerPedId() (NOT GetPlayerPed(-1)). Read coords with GetEntityCoords and
heading with GetEntityHeading.
5. CreateVehicle(hash, x, y, z, heading, true, false), then SetPedIntoVehicle(ped,
veh, -1), SetVehicleOnGroundProperly(veh), SetEntityAsMissionEntity(veh,true,true).
6. ALWAYS call SetModelAsNoLongerNeeded(hash) after spawning.
7. Register a chat suggestion via TriggerEvent("chat:addSuggestion", ...).
Return only the Lua plus a one-line fxmanifest client_script note. Modern natives
only. No placeholder comments.
Expected Output
The reference Lua at content/expected-outputs/vehicles/01-vehicle-spawner-command.lua implements a validated, timeout-guarded /car command entirely client-side; the fxmanifest lists it as a single client_script 'client.lua' with no server side.
-- Resource: vehspawner
-- Vehicle spawner command with safe model loading.
-- Single client-side file (no server side needed for a basic admin/dev spawner).
-- ===== client.lua =====
local function loadModel(hash)
if not IsModelInCdimage(hash) or not IsModelAVehicle(hash) then
return false
end
RequestModel(hash)
local timeout = GetGameTimer() + 10000
while not HasModelLoaded(hash) do
Wait(0)
if GetGameTimer() > timeout then
return false
end
end
return true
end
RegisterCommand("car", function(_, args)
local modelName = args[1] or "adder"
local hash = GetHashKey(modelName)
if not loadModel(hash) then
TriggerEvent("chat:addMessage", {
args = { "^1Spawner", ("Invalid or unloadable model: %s"):format(modelName) }
})
return
end
local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
local heading = GetEntityHeading(ped)
local veh = CreateVehicle(hash, coords.x, coords.y, coords.z, heading, true, false)
SetPedIntoVehicle(ped, veh, -1)
SetVehicleOnGroundProperly(veh)
SetEntityAsMissionEntity(veh, true, true)
SetModelAsNoLongerNeeded(hash)
TriggerEvent("chat:addMessage", {
args = { "^2Spawner", ("Spawned %s"):format(modelName) }
})
end, false)
TriggerEvent("chat:addSuggestion", "/car", "Spawn a vehicle by model name", {
{ name = "model", help = "Vehicle model (e.g. adder, sultan)" }
})
Known Failure Modes
- No load loop — Claude calls
CreateVehicleimmediately afterRequestModel; the model isn't resident yet so nothing spawns. Force thewhile not HasModelLoaded(hash) do Wait(0) endloop. - Deprecated ped native — it emits
GetPlayerPed(-1); requirePlayerPedId()explicitly. - No model validation — spawning an invalid hash hard-fails silently. Demand
IsModelInCdimage/IsModelAVehiclechecks up front. - Model leak — omitting
SetModelAsNoLongerNeededafter repeated spawns leaks memory; state it as mandatory.
Integration Notes
Drop the file in a resource folder as client.lua. In fxmanifest.lua add fx_version 'cerulean', game 'gta5', and client_script 'client.lua'. No es_extended/qb-core dependency. Test on a dev server with ensure <resource> then /car sultan — you should spawn inside a Sultan that sits flat on the ground.
Profit Potential
$80–$900/mo on Tebex (expected ~$260). [INFERRED] A free-everywhere commodity spawner barely sells standalone; the band assumes a handful of bundle and lead-magnet conversions inside the $50-389 corpus.
Trend Signal
↗ rising — vehicle modding/tuning niche-selection 3.75; corpus ox_fuel active.
Sales Angle
A standalone /car spawner is given away free on every server, so run it as a lead-magnet that funnels buyers toward your paid vehicle scripts. If packaged, floor it at $50 inside a starter bundle on Tebex.
Difficulty & Ship Time
beginner · ships in 2-3h.