Handling Interactions - LiamDormon/bt-target GitHub Wiki

Client Event

When an option is clicked the event defined in the options parameter will be triggered with no arguments. It is generally advised to add distance and job checks to your events, preferably server-authenticated, to secure them from hackers. This is a good practice to follow for all events, not just events from this particular resource.

Example

The following example will be based on the example used for AddTargetModel

RegisterNetEvent("dumpster:search")
AddEventHandler("dumpster:search", function()
	if IsNearDumpster() then
		-- Code to search a dumpster
	end
end)

For this example you can use a simple function to check for objects in range such as:

function IsNearDumpster()
	local ped = PlayerPedId()
	local coords = GetEntityCoords(ped)
	for _, object in pairs(objects) do
		if GetClosestObjectOfType(coords.x, coords.y, coords.z, 2.5, object, false, false, false) then
			return true
		end
	end
	return false
end

For Box Zones & Circle Zones you can do a simple distance check.