Trigger a function by entering a marker and pressing "e"

Hello,

I looking for trigger a function by entering a marker and pressing “e”

function OpenShowroomMenu()
  IsInShopMenu = true

  ESX.UI.Menu.CloseAll()

  local playerPed = PlayerPedId()

  FreezeEntityPosition(playerPed, true)
  SetEntityVisible(playerPed, false)
  SetEntityCoords(playerPed, Config.Zones.ShopInside.Pos.x, Config.Zones.ShopInside.Pos.y, Config.Zones.ShopInside.Pos.z)

  local vehiclesByCategory = {}
  local elements           = {}
  local firstVehicleData   = nil

  for i=1, #Categories, 1 do
    vehiclesByCategory[Categories[i].name] = {}
  end

  for i=1, #Vehicles, 1 do
    table.insert(vehiclesByCategory[Vehicles[i].category], Vehicles[i])
  end

  for i=1, #Categories, 1 do
    local category         = Categories[i]
    local categoryVehicles = vehiclesByCategory[category.name]
    local options          = {}

    for j=1, #categoryVehicles, 1 do
      local vehicle = categoryVehicles[j]

      if i == 1 and j == 1 then
        firstVehicleData = vehicle
      end

      table.insert(options, vehicle.name .. ' <span style="color: green;">$' .. vehicle.price .. '</span>')
    end

    table.insert(elements, {
      name    = category.name,
      label   = category.label,
      value   = 0,
      type    = 'slider',
      max     = #Categories[i],
      options = options
    })
  end

  DeleteShopInsideVehicles()

  ESX.Game.SpawnLocalVehicle(firstVehicleData.model, Config.Zones.ShopInside.Pos, Config.Zones.ShopInside.Heading, function (vehicle)
    table.insert(LastVehicles, vehicle)
    TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
    FreezeEntityPosition(vehicle, true)
  end)
end

This is the function to call (from esx_vehicleshop)

I wan’t to create a showroom like the one in but without buying ability

do you mean something like this?

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
		local playerPed = PlayerPedId()
		local coords = GetEntityCoords(playerPed)

		if GetDistanceBetweenCoords(coords, 261.87, 223.13, 106.28, true) < 0.5 then
			if not IsHackingDoor and not IsDoorHacked then
				ESX.ShowHelpNotification('~h~Press ~INPUT_CONTEXT~ to hack the door!')
			end
			if IsControlJustReleased(0, Keys['E']) and not IsHackingDoor and not IsDoorHacked then
				TriggerServerEvent('bankrob:HasGotRaspDoor')
			end
		end
	end
end)

That’s it but how to replace TriggerServerEvent('HasGotRaspDoor') by something wich open the menu/trigger the function

You replace it by calling your function name, OpenShowroomMenu()

I tried this :

local place = {
    {x = -48.715, y = -1111.821, z = 25.435}
}

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        for k in pairs(place) do
            DrawMarker(27, place[k].x, place[k].y, place[k].z, 0, 0, 0, 0, 0, 0, 1.001, 1.0001, 0.5001, 0, 255, 50, 200, 0, 0, 0, 0)
        end
    end
end)

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        for k in pairs(place) do
            local plyCoords = GetEntityCoords(GetPlayerPed(-1), false)
            local dist = Vdist(plyCoords.x, plyCoords.y, plyCoords.z, place[k].x, place[k].y, place[k].z)

            if dstCheckEnter <= 1.2 then
            ESX.ShowHelpNotification('~h~Appuie sur ~INPUT_CONTEXT~ pour ouvrir le catalogue!')
              if IsControlJustPressed(0, 38) then
                TriggerServerEvent(OpenCatalogueMenu())
              end
            end  
        end         
    end
end)

The marker appear but when you go on it nothing happen, no message in to left corner, or action when pressing “e”

Any idea ?

Also tried with

if dstCheckEnter <= 1.2 then
            ESX.ShowHelpNotification('~h~Appuie sur ~INPUT_CONTEXT~ pour ouvrir le catalogue!')
              if IsControlJustPressed(0, 38) then
                OpenCatalogueMenu()
              end
            end

First,

dstCheckEnter doesn’t exist.
The condition will never be true.

To do a proper distance check you could do someting like this :

if GetDistanceBetweenCoords(plyCoords , place[k].x, place[k].y, place[k].z, true) < 1.2 then

end

Is wrong too, here you should simply use OpenCatalogueMenu()not TriggerServerEvent(OpenCatalogueMenu())

This is some basic stuff, I highly recommend you to learn the basics of programming/scripting, we won’t always be here to help you.

1 Like

Well,
First of all thanks for the help it work ^^

About de the TriggerServerEvent(OpenCatalogueMenu()) I knew I just copy/paste the wrong file. Because desperately I tried it xd

No problem, have a good day.