Jump to content

teleporter


Recommended Posts

37 minutes ago, kukimuki said:

How can I do a script when if I write "teleport" then teleport me to a position?

hello @kukimuki welcome the forum , I sent you 2 different pieces of code regarding your question, you can try both, if you want a different way, you can tell me, I can help you
1. code

function onPlayerCommand(command)
  if command == "teleport" then
    -- get the player's current position
    local x, y, z = getElementPosition(getLocalPlayer())
    -- set the new position where you want to teleport the player
    local new_x, new_y, new_z = 123.45, 67.89, 10.11 -- change these values to your desired position
    -- set the player's new position
    setElementPosition(getLocalPlayer(), new_x, new_y, new_z)
  end
end
addEventHandler("onClientCommand", getRootElement(), onPlayerCommand)

2. code
 

function onPlayerCommand(command, arg1, arg2, arg3)
  if command == "teleport" and arg1 and arg2 and arg3 then
    -- get the player's local element
    local player = getLocalPlayer()
    -- get the position to teleport the player to
    local x, y, z = tonumber(arg1), tonumber(arg2), tonumber(arg3)
    -- set the player's new position
    setElementPosition(player, x, y, z)
  end
end
addEventHandler("onClientCommand", getRootElement(), onPlayerCommand)

 

  • Like 1
Link to comment
3 hours ago, kukimuki said:

whats the command? how to use the teleport function? maybe add addCommandHandler?

 

function onTeleportCommand()
  -- get the player's current position
  local x, y, z = getElementPosition(getLocalPlayer())
  -- set the new position where you want to teleport the player
  local new_x, new_y, new_z = 123.45, 67.89, 10.11 -- these values should be changed to your desired position
  -- set the player's new position
  setElementPosition(getLocalPlayer(), new_x, new_y, new_z)
end
addCommandHandler("teleport", onTeleportCommand)

 

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...