SetPlayerLocation: Difference between revisions
From Onset Developer Wiki
Created page with "{{Info|Function|Server|1.0}} {{FuncDescription|__EDIT_ME__}} {{FuncSyntax|SetPlayerLocation(player, x, y, z)}} {{FuncParameters}} {{FuncParam|player|__EDIT_ME__}} {{FuncPar..." |
|||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
{{Info|Function|Server|1.0}} | {{Info|Function|Server|1.0}} | ||
{{FuncDescription| | {{FuncDescription|Set the specified client's location.}} | ||
{{FuncSyntax|SetPlayerLocation(player, x, y, z)}} | {{FuncSyntax|SetPlayerLocation(player, x, y, z)}} | ||
{{FuncParameters}} | {{FuncParameters}} | ||
{{FuncParam|player| | {{FuncParam|player|The client identifier}} | ||
{{FuncParam|x| | {{FuncParam|x|The X coordinate of position to put the player at.}} | ||
{{FuncParam|y| | {{FuncParam|y|The Y coordinate of position to put the player at.}} | ||
{{FuncParam|z| | {{FuncParam|z|The Z coordinate of position to put the player at.}} | ||
{{FuncReturnValue| | {{FuncReturnValue|Returns '''true''' on success.}} | ||
== Example == | == Example == | ||
<syntaxhighlight lang="Lua"> | |||
AddCommand("town", function(player) | |||
SetPlayerLocation(player, -182821.00, -41675.00, 1160.00) | |||
AddPlayerChat(player, "Teleported to town.") | |||
end) | |||
</syntaxhighlight> | |||
(server) '''Teleport function example:''' | |||
<syntaxhighlight lang="Lua"> | |||
function TeleportTo(player, x, y, z, h) | |||
-- if the player is in a vehicle it will teleport the vehicle with them. | |||
-- h = player heading | |||
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}} | ||
* [[GetPlayerLocation]] |
Latest revision as of 18:19, 19 December 2019
Description
Set the specified client's location.
Syntax
SetPlayerLocation(player, x, y, z)
Parameters
- player
The client identifier - x
The X coordinate of position to put the player at. - y
The Y coordinate of position to put the player at. - z
The Z coordinate of position to put the player at.
Return Value
- Returns true on success.
Example
AddCommand("town", function(player)
SetPlayerLocation(player, -182821.00, -41675.00, 1160.00)
AddPlayerChat(player, "Teleported to town.")
end)
(server) Teleport function example:
function TeleportTo(player, x, y, z, h)
-- if the player is in a vehicle it will teleport the vehicle with them.
-- h = player heading
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