SetVehicleLocation: Difference between revisions

From Onset Developer Wiki
Created page with "{{Info|Function|Server|1.0}} {{FuncDescription|__EDIT_ME__}} {{FuncSyntax|SetVehicleLocation(vehicle, x, y, z)}} {{FuncParameters}} {{FuncParam|vehicle|__EDIT_ME__}} {{Func..."
 
28days (talk | contribs)
No edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{Info|Function|Server|1.0}}
{{Info|Function|Server|1.0}}


{{FuncDescription|__EDIT_ME__}}
{{FuncDescription|Teleports a vehicle to a specified location.}}


{{FuncSyntax|SetVehicleLocation(vehicle, x, y, z)}}
{{FuncSyntax|SetVehicleLocation(vehicle, x, y, z)}}


{{FuncParameters}}
{{FuncParameters}}
{{FuncParam|vehicle|__EDIT_ME__}}
{{FuncParam|vehicle|The vehicle identifier.}}
{{FuncParam|x|__EDIT_ME__}}
{{FuncParam|x|World X location.}}
{{FuncParam|y|__EDIT_ME__}}
{{FuncParam|y|World Y location.}}
{{FuncParam|z|__EDIT_ME__}}
{{FuncParam|z|World Z location.}}


{{FuncReturnValue|__EDIT_ME__}}
{{FuncReturnValue|Returns '''true''' on success. '''false''' if the vehicle does not exist.}}


== Example ==
== Example ==
__EDIT_ME__
<syntaxhighlight lang="Lua">
function TeleportTo(player, x, y, z, h)
h = h or -1.0
 
if (GetPlayerVehicleSeat(player) == 1) then
local vehicle = GetPlayerVehicle(player)
SetVehicleLocation(vehicle, x, y, z)
if (h ~= -1.0) then
SetVehicleHeading(vehicle, h)
end
 
-- Reset velocity
SetVehicleLinearVelocity(vehicle, 0.0, 0.0, 0.0, true)
SetVehicleAngularVelocity(vehicle, 0.0, 0.0, 0.0, true)
local rx, ry, rz = GetVehicleRotation(vehicle)
-- Reset pitch and roll, leave yaw alone
SetVehicleRotation(vehicle, 0.0, ry, 0.0)
else
SetPlayerLocation(player, x, y, z)
if (h ~= -1.0) then
SetPlayerHeading(player, h)
end
end
 
ResetPlayerCamera(player)
end
</syntaxhighlight>


{{RelatedFunctions}}
{{RelatedFunctions}}
__EDIT_ME__
{{Template:VehicleFunctions}}

Latest revision as of 09:58, 12 December 2019

SetVehicleLocation

Type: Function
Context: Server
Introduced: v1.0

Description

Teleports a vehicle to a specified location.

Syntax

SetVehicleLocation(vehicle, x, y, z)

Parameters

  • vehicle
    The vehicle identifier.
  • x
    World X location.
  • y
    World Y location.
  • z
    World Z location.

Return Value

  • Returns true on success. false if the vehicle does not exist.

Example

function TeleportTo(player, x, y, z, h)
	h = h or -1.0

	if (GetPlayerVehicleSeat(player) == 1) then
		local vehicle = GetPlayerVehicle(player)
		SetVehicleLocation(vehicle, x, y, z)
		if (h ~= -1.0) then
			SetVehicleHeading(vehicle, h)
		end

		-- Reset velocity
		SetVehicleLinearVelocity(vehicle, 0.0, 0.0, 0.0, true)
		SetVehicleAngularVelocity(vehicle, 0.0, 0.0, 0.0, true)
		local rx, ry, rz = GetVehicleRotation(vehicle)
		-- Reset pitch and roll, leave yaw alone
		SetVehicleRotation(vehicle, 0.0, ry, 0.0)
	else
		SetPlayerLocation(player, x, y, z)
		if (h ~= -1.0) then
			SetPlayerHeading(player, h)
		end
	end

	ResetPlayerCamera(player)
end

See also