An useful system to obtain the player's id by clicking on them.
You can easily customize the marker on the player head, or remove it. You can change:
- Change the max distance for interacting with the player
- Select Control for selecting the player
- Disabled Controls during the raycasting
- Exit Controls for leaving the raycasting
In addition to the players you can select the peds to obtain their entity
I didn't find many resources on the forum or on GitHub that would allow you to do this, to be honest I didn't search in depth, the idea obviously didn't come from me but I think this script could be useful to many people.
🎬 Preview
After you have downloaded the latest release of the resource:
- Put the
targeting
folder into your resource foleder - Add
ensure targeting
to yourserver.cfg
or put the folder into a[collection]
already started in theserver.cfg
exports.targeting:StartTargeting(data)
data: table
- npc:
boolean
enable raycasting on npc's
An example with npc raycasting disabled
RegisterCommand("getId", function (source, args, raw)
local id = exports.targeting:StartTargeting({
npc = false
})
print(id)
end)
This is equivalent to:
RegisterCommand("getId", function (source, args, raw)
local id = exports.targeting:StartTargeting({})
print(id)
end)
At this line of @ox_inventory/client.lua you can replace all the code of the callback with this
RegisterNUICallback('giveItem', function(data, cb)
cb(1)
TriggerEvent('ox_inventory:closeInventory')
local id = exports.targeting:StartTargeting({})
giveItemToTarget(id, data.slot, data.count)
end)