kukimuki Posted May 6, 2023 Share Posted May 6, 2023 How can I do a script when if I write "teleport" then teleport me to a position? Link to comment
Shady1 Posted May 6, 2023 Share Posted May 6, 2023 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) 1 Link to comment
kukimuki Posted May 6, 2023 Author Share Posted May 6, 2023 whats the command? how to use the teleport function? maybe add addCommandHandler? Link to comment
Shady1 Posted May 6, 2023 Share Posted May 6, 2023 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) 1 Link to comment
Shady1 Posted May 6, 2023 Share Posted May 6, 2023 44 minutes ago, kukimuki said: Thank you so much! Please, if it worked, you can give a like to my comment. 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now