I’m looking for a script for non-economy servers that will create a location for people to spawn vehicles.

No money or databases involved, just straight up go here to spawn a car.

Thanks for any suggestions.

Based on command or a menu?

I made this real quick. It should be a start. Don’t know if it actually works though but it should.

--- Variables & Etc. ---
AddTextEntry("dealership", "Do /car 'name' to spawn a vehicle!")

local coords = {
	{x = 1180.0,y = 2648.0,z = 38.0}, -- Route 68 LSC
}

RegisterCommand("car", function(source, args, raw)
	local car = args[1] or "ADDER"

	if IsModelAVehicle(car) then
		TriggerEvent("opencarshop", car)
	end

end)

RegisterNetEvent("opencarshop")
AddEventHandler("opencarshop", function(car)
	for s in pairs(coords) do
		local ped = GetPlayerPed(-1)
		local playercoord = GetEntityCoords(ped, false)
		local distance = GetDistanceBetweenCoords(playercoord.x, playercoord.y, playercoord.z, coord[s].x, coord[s].y, coord[s].z)
		if distance <= 12.0 then
			if not IsPedInAnyVehicle(ped, false) then
				DisplayHelpTextThisFrame("dealership", false)
					if IsControlJustPressed(0,311) then
					Citizen.Wait(10)
						spawnCar(car)
						TriggerEvent('chatMessage', "Car", {255,255,255}, "Vehicle " .. GetLabelText(car).. " spawned!")
						break;
					end
				end
			end
		else
			TriggerEvent('chatMessage', "Car", {255,255,255}, " You are not a dealership")
		end
	end
end)

function spawnCar(n)
	local ped = GetPlayerPed(-1)
	local vehicle = GetHashKey(n)
	RequestModel(vehicle)
	while not HasModelLoaded(vehicle) do
		Citizen.Wait(1)
	end
	local heading = GetEntityHeading(ped)
	local coords = GetOffsetFromEntityInWorldCoords(ped, 0, 5.0, 0)
	local car = CreateVehicle(vehicle, coords.x, coords.y, coords.z, heading, true, false)
	SetVehicleOnGroundProperly(car)
	SetVehicleNumberPlateText(car, " RENTED ")
	SetPedIntoVehicle(ped, car, -1)
	SetModelAsNoLongerNeeded(vehicle)
end

I’d prefer something menu based but that would be much more involved I imagine? I’ll explore how this could be implemented as a command in the meantime.

Not really no

NativeUI?

Never used NativeUI, So I dont know

What would you recommend for a menu? Would it be able to just open the vMenu spawner somehow lol

I would recommend NativeUI because in my opinion it looks better, But WarMenu is easier to use.

Doesn’t need to be pretty especially if it can be setup easily. Problem is people wouldn’t be able to spawn their spawned stuff that they have in vMenu :thinking: Didn’t even think of this.

What if they could still use vMenu spawning but spawning was disabled except for at coordinates?

That would make it harder. Then you would need to grab the source code from vMenu and edit it so you can only spawn vehicles at certain locations

What if it was the opposite, and just deletes any vehicle immediately after it’s spawned anywhere except at those spots, just like faxes permissions for vehicles, but based on location instead of permissions?

Because then it would delete any car unless vMenu trigger an event that can be picked up by your code

Okay just looked over the fax core and saw the “GetVehiclePedIsIn” i didnt realize it scanned constantly, though it used spawns.

Could you point me toward setting up a menu for the stuff you already wrote then?

Or if you have any other ideas for how to pull this off without Essentialmode stuff?

Also just want to confirm this is correct


Exactly what you sent is in client.lua so far

Looks good, Also. I dont know how you make it so it can read of a table into NativeUI but I do know in WarMenu.

Warmenu should be fine if you approve of it lol, I could just figure out NativeUI another time.

This is an example of how you could do it in WarMenu.


local cars = { -- This is the table where you enter the cars you want to be able to be an option of spawning
"car1",
"car2",
"car3",
}

Citizen.CreateThread(function()

	WarMenu.CreateMenu("test", "test")

	while true do
			if WarMenu.IsMenuOpened("test") then
				for _, k in pairs(cars) do -- This grabs the table data
					if WarMenu.Button(k, GetLabelText(k)) then -- This displays the vehicle. If there is two cars up in the table then there will be 2 buttons.
						TriggerEvent("eventtospawnvehicle", k) -- this is the event of the vehicle being spawned
					end
				end
             end
			 WarMenu.Display()
			if  IsControlJustReleased(0, 244) then
				WarMenu.OpenMenu("test")
			end

		Citizen.Wait(0)

		end

	end)

Try something like this

Any way to do categories for vehicle types, also any way to keep spawn by name as a button option?
And where exactly does the code you sent go? In the resource using it right? (so v-buying in my case)

Sorry for my incompetence, promise i’ll only have to ask once :sweat_smile:

Yea, Its possible. Add another submenu and add your cars in that submenu. Also, If you want a “spawn by name” option you could do this.

if WarMenu.Button("Spawn By Name") then
spawnbyname("Spawn Vehicle by name", "adder", 25)
end
function spawnbyname(TextEntry, ExampleText, MaxStringLength) -- this is a modified version of I think @Flatracer onscreen Keyboard function
	AddTextEntry('FMMC_KEY_TIP1', TextEntry)
	DisplayOnscreenKeyboard(1, "FMMC_KEY_TIP1", "", ExampleText, "", "", "", MaxStringLength)
	blockinput = true

	while UpdateOnscreenKeyboard() ~= 1 and UpdateOnscreenKeyboard() ~= 2 do
		Citizen.Wait(0)
	end

	if UpdateOnscreenKeyboard() ~= 2 then
		local result = GetOnscreenKeyboardResult()
		Citizen.Wait(500)
		blockinput = false
		spawncar(result)
        return
	else
		Citizen.Wait(500)
		blockinput = false
		return nil
	end
end
function spawncar(veh)
  local ped = GetPlayerPed(-1)
  local vehicle = GetHashKey(veh)
  RequestModel(vehicle)
  while not HasModelLoaded(vehicle) do
    Citizen.Wait(1)
  end
  local coords = GetOffsetFromEntityInWorldCoords(GetPlayerPed(-1), 0, 5.0, 0)
  local spawnedcar = CreateVehicle(vehicle, coords, GetEntityHeading(ped), true, false)
  SetVehicleOnGroundProperly(spawnedcar)
  SetModelAsNoLongerNeeded(vehicle)
end

Yes, Inside the client.lua