CreateVehicle: Difference between revisions

From Onset Developer Wiki
No edit summary
No edit summary
Line 1: Line 1:
CreateVehicle
CreateVehicle


<syntaxhighlight lang="Lua" line='line'>
<syntaxhighlight lang="Lua" line>
function cmd_v(player, model)
function cmd_v(player, model)
if (model == nil) then
if (model == nil) then

Revision as of 22:11, 22 February 2019

CreateVehicle

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)