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..." |
No edit summary |
||
Line 1: | Line 1: | ||
{{Info|Function|Server|1.0}} | {{Info|Function|Server|1.0}} | ||
{{FuncDescription| | {{FuncDescription|Teleports a vehicle to a specified location.}} | ||
{{FuncSyntax|SetVehicleLocation(vehicle, x, y, z)}} | {{FuncSyntax|SetVehicleLocation(vehicle, x, y, z)}} | ||
{{FuncParameters}} | {{FuncParameters}} | ||
{{FuncParam|vehicle| | {{FuncParam|vehicle|The vehicle identifier.}} | ||
{{FuncParam|x| | {{FuncParam|x|World X location.}} | ||
{{FuncParam|y| | {{FuncParam|y|World Y location.}} | ||
{{FuncParam|z| | {{FuncParam|z|World Z location.}} | ||
{{FuncReturnValue| | {{FuncReturnValue|Returns '''true''' on success. '''false''' if the vehicle does not exist.}} | ||
== Example == | == Example == | ||
<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__ | __EDIT_ME__ |
Revision as of 10:08, 8 October 2019
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
__EDIT_ME__