CreateVehicle

From Onset Developer Wiki
Revision as of 10:33, 23 February 2019 by BlueMountains (talk | contribs)

Syntax

CreateVehicle(modelid, x, y, z [, heading])

Return Value

On Success: Returns identifier to the new vehicle. On Error: Returns false.

Example

function cmd_v(player, model)
	if (model == nil) then
		return AddPlayerChat(player, "Usage: /v <model>")
	end

	model = tonumber(model)

	if (model < 1 or model > 12) then
		return AddPlayerChat(player, "Vehicle model "..model.." does not exist.")
	end

	if (PlayerData[player].vehicle ~= 0) then
		DestroyVehicle(PlayerData[player].vehicle)
		PlayerData[player].vehicle = 0
	end

	local x, y, z = GetPlayerLocation(player)
	local h = GetPlayerHeading(player)

	local vehicle = CreateVehicle(model, x, y, z, h)
	if (vehicle == false) then
		return AddPlayerChat(player, "Failed to spawn your vehicle")
	end

	PlayerData[player].vehicle = vehicle

	-- Do not change color of the taxi or police car
	if (model ~= 2 and model ~= 3) then
		--local color = RGB(math.random(1, 220), math.random(1, 220), math.random(1, 220))
		--SetVehicleColor(vehicle, NiceColors[ math.random( #NiceColors ) ])
	end

	SetVehicleLicensePlate(vehicle, "HORIZON")
	AttachVehicleNitro(vehicle, true)

	if (model == 8) then
		-- Ambulance
		SetVehicleColor(vehicle, RGB(0.0, 60.0, 240.0))
		SetVehicleLicensePlate(vehicle, "EMS-02")
	end

	SetPlayerInVehicle(player, vehicle)

	AddPlayerChat(player, "Vehicle spawned! (New ID: "..vehicle..")")
end
AddCommand("v", cmd_v)