Making a car spawn

how or what would i place into my menu to trigger a car spawn? - WL9 is the spawn name - its for a menu

local hash = GetHashKey(“wl9”)

RequestModel(hash)

while not HasModelLoaded(hash) do
RequestModel(hash)
Citizen.Wait(0)
end

local x, y, z = table.unpack(GetEntityCoords(GetPlayerPed(-1), false))
local vehicle = CreateVehicle(hash, x + 2, y + 2, z + 1, 0.0, true, false)

would it be


AddEventHandler("chatMessage",function(Source,Name,Msg)
	if Msg:sub(1,6) == "/wl9" then
		TriggerClientEvent("Event",Source,Msg:sub(5))
		CancelEvent()
	end
end)
-- Client
RegisterNetEvent("Event")
AddEventHandler("Event",function(Vehicle)
	-- Code
end

Try

RegisterCommand('wl9', function(source, args, rawCommand)
    local x,y,z = table.unpack(GetOffsetFromEntityInWorldCoords(PlayerPedId(), 0.0, 8.0, 0.5))
    vehiclehash = "wl9"
    RequestModel(vehiclehash)
    
    Citizen.CreateThread(function() 
        CreateVehicle(vehiclehash, x, y, z, GetEntityHeading(PlayerPedId())+90, 1, 0)
    end)
end)

Might not work idk, just wrote it in about 10 seconds :slight_smile:

Also in future to format code use the (`) symbol to format it. :slight_smile:

View the below to see more, I kinda based mine off of it, but this is a script you might like :slight_smile:

cheers thanks alot i shall give it ago

nope shame,
i was trying to get it to work with this great menu -

ui.css (548 Bytes)
README.md (633 Bytes)
cl_toolbox.lua (65.8 KB)
LICENSE (34.4 KB)
ui.html (13.5 KB)
ui.js (2.5 KB)
__resource.lua (881 Bytes)
sv_toolbox.lua (4.8 KB)

so still this in and it will work or chance the “red” bits

would you know how to spawn Cones and barriers with a trigerevent?

There’s scripts that have been released for this :slight_smile:

yes but none work and woundered what i did wrong,
would you mind pointing the error out - pretty please
cl_toolbox.lua (98.0 KB)

I use one that works.

Pull some code from it…

cheers i shall have a look

1 Like