Teleport to coordinates

Hello. Can someone create a simple script that teleports to coordinates or show me a guide? Thanks :slight_smile:

2 Likes

You can find one in my pack under vrp_basic_menu/server.lua

3 Likes

Use SetEntityCoords.

2 Likes

Use SetPedCoordsKeepVehicle(Ped ped, float x, float y, float z); if you want to teleport the player including their vehicle :wink:
https://runtime.fivem.net/doc/reference.html#_0x9AFEFF481A85AB2E

3 Likes

client.lua


local hintIsShowed        = false
local hasAlreadyEnteredMarker = false
local isInMarker              = false
local isInPublicMarker        = false

AddEventHandler('esx_jobs:publicTeleports', function(position)
  SetEntityCoords(GetPlayerPed(-1), position.x, position.y, position.z)
end)


-- Show top left hint
Citizen.CreateThread(function()
  while true do
    Wait(0)
    if hintIsShowed == true then
      SetTextComponentFormat("STRING")
      AddTextComponentString(hintToDisplay)
      DisplayHelpTextFromStringLabel(0, 0, 1, -1)
    end
  end
end)

-- Display public markers
Citizen.CreateThread(function()
  while true do
    Wait(0)
    local coords = GetEntityCoords(GetPlayerPed(-1))
    for k,v in pairs(Config.PublicZones) do
      if(v.Marker ~= -1 and GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then
        DrawMarker(v.Marker, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false)
      end
    end
  end
end)

-- Activate public marker
Citizen.CreateThread(function()
  while true do
    Wait(0)
    local coords      = GetEntityCoords(GetPlayerPed(-1))
    local position    = nil
    local zone        = nil
	

    if IsControlJustReleased(0, 38) and isInPublicMarker then
      TriggerEvent('esx_jobs:publicTeleports', position)
    end
	
    for k,v in pairs(Config.PublicZones) do
      if(GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x) then
        isInPublicMarker = true
        position = v.Teleport
        zone = v
        break
      else
        isInPublicMarker  = false
      end
    end

    -- hide or show top left zone hints
    if isInPublicMarker then
      hintToDisplay = zone.Hint
      hintIsShowed = true
    else
      if not isInMarker then
        hintToDisplay = "No Hint to Display!"
        hintIsShowed = false
      end
    end
  end
end)

config.lua

Config              = {}
Config.DrawDistance = 1000.0

Config.PublicZones = {
  EnterBuilding = {
    Pos   = { x = 1394.8719482422, y = 1141.9404296875, z = 114.62250518799 },
    Size  = {x = 1.5, y = 1.5, z = 1.0},
    Color = {r = 0, g = 0, b = 0},
    Marker= 0,
    Blip  = false,
    Name  = "Name",
    Type  = "teleport",
    Hint  = "Press ~INPUT_PICKUP~ to go out.",
    Teleport = { x = 1397.0953369141, y = 1141.6251220703, z = 114.33366394043 }
  },

  ExitBuilding = {
    Pos   = { x = 1397.0953369141, y = 1141.6251220703, z = 114.33366394043 }, -- marker entrada 
    Size  = {x = 1.5, y = 1.5, z = 1.0},
    Color = {r = 0, g = 0, b = 0},
    Marker= 0,
    Blip  = false,
    Name  = "Name",
    Type  = "teleport",
    Hint  = "Press ~INPUT_PICKUP~ to go out.",
    Teleport = { x = 1394.8719482422, y = 1141.9404296875, z = 114.62250518799 }, -- onde spawna depois de entrar
  },
}
2 Likes

why is there a pos and a teleport?

1 Like

The pos is the marker. The teleport is where it warps you to.

can you help me im trying to make a teleport marker in the sandy shores pd and i have a ymap jail under the pd and im trying make a telport marker that telports me down there i have tried everything and everytime i try to the cords the marker never appears in game please help can we talk on discord?
Outlawzs#6047

Do you use esx_ambulancejob? Theres a nice teleport system in that script that can be manipulated to add more coords. Im at work right now, but later tonight I’ll see what i can do for you. I reworked the esx_jobs teleport to enter bahama mamas. The same can be done with esx_ambulancejob. Add the coords to the config and the zone in the client.

yes i use ambulance job

can we talk on discord?

so i edit the ambulance job config and client? ok

can you add me on discord real quick o its easier to talk to u?

located in the config

HospitalInteriorEntering1 = {
    Pos  = { x = 1151.447, y = -1529.491, z = 34.375 },
    Size = { x = 1.5, y = 1.5, z = 1.0 },
    Type = 1
  },

  HospitalInteriorInside1 = {
    Pos  = { x = 251.464, y = -1369.770, z = 28.648 },
    Size = { x = 1.5, y = 1.5, z = 1.0 },
    Type = -1
  },

  HospitalInteriorOutside1 = {
    Pos  = { x = 1153.364, y = -1525.731, z = 33.843 },
    Size = { x = 1.5, y = 1.5, z = 1.0 },
    Type = -1
  },

  HospitalInteriorExit1 = {
    Pos  = { x = 253.612, y = -1371.66, z = 28.647 },
    Size = { x = 1.5, y = 1.5, z = 1.0 },
    Type = 1
  },

  HospitalInteriorEntering2 = {
    Pos  = { x = 1137.181, y = -1597.504, z = 33.692 },
    Size = { x = 1.5, y = 1.5, z = 1.0 },
    Type = 1
  },

  HospitalInteriorInside2 = {
    Pos  = { x = 240.508,  y = -1360.565, z = 28.647 },
    Size = { x = 1.5, y = 1.5, z = 1.0 },
    Type = -1
  },

  HospitalInteriorOutside2 = {
    Pos  = { x = 1137.922, y = -1601.434, z = 33.692 },
    Size = { x = 1.5, y = 1.5, z = 1.0 },
    Type = -1
  },

  HospitalInteriorExit2 = {
    Pos  = { x = 238.587,  y = -1359.113, z = 28.647 },
    Size = { x = 1.5, y = 1.5, z = 1.0 },
    Type = 1
  },

located in the client

if zone == 'HospitalInteriorEntering1' then
		TeleportFadeEffect(GetPlayerPed(-1), Config.Zones.HospitalInteriorInside1.Pos)
	end

	if zone == 'HospitalInteriorExit1' then
		TeleportFadeEffect(GetPlayerPed(-1), Config.Zones.HospitalInteriorOutside1.Pos)
	end

	if zone == 'HospitalInteriorEntering2' then
		TeleportFadeEffect(GetPlayerPed(-1), Config.Zones.HospitalInteriorInside2.Pos)
	end

	if zone == 'HospitalInteriorExit2' then
		TeleportFadeEffect(GetPlayerPed(-1), Config.Zones.HospitalInteriorOutside2.Pos)
	end

for example make a hopspital interior entering, inside, outside and exit all ending with 3. add the coords you want and then add another zone to the client. you should be able to copy/pasta and just change the names and coords. give it a try and let me know.

1 Like

Could you do it if I sent you the cords?

I can’t test it on can’t be on till Friday

Hello . I’m new to this, can you help me create a teleport?

How Can i use the comand tp, what shut i Put exactly.

Hi, could you help me do that? And another question I have? Via discodd?

It basically just tells you in the post of HST.

YourLocationToGoTo = {
    Pos  = { x = 1151.447, y = -1529.491, z = 34.375 },
    Size = { x = 1.5, y = 1.5, z = 1.0 },
    Type = 1
  },

and in the client file you make a zone or location, where if the player pressed E or gets into the defined area (distance < 1 ?) it triggers

		TeleportFadeEffect(GetPlayerPed(-1), Config.Zones.YourLocationToGoTo.Pos)