Making a car spawn


#1

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)


#2

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

#3

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:


#4

cheers thanks alot i shall give it ago


#5

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)


#6

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