Teleport to coordinates

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