diff --git a/interactionMenu/lua/client/interact.lua b/interactionMenu/lua/client/interact.lua index d3a8eea..82fc755 100644 --- a/interactionMenu/lua/client/interact.lua +++ b/interactionMenu/lua/client/interact.lua @@ -333,6 +333,7 @@ local function METADATA(t) playerPedId = t.entity, playerIndex = NetworkGetPlayerIndexFromPed(t.entity), } + metadata.player.serverId = GetPlayerServerId(metadata.player.playerIndex) end diff --git a/interactionMenu/lua/client/menuContainer.lua b/interactionMenu/lua/client/menuContainer.lua index 4dcbfbe..5a05124 100644 --- a/interactionMenu/lua/client/menuContainer.lua +++ b/interactionMenu/lua/client/menuContainer.lua @@ -18,6 +18,9 @@ local interactionAudio = Config.interactionAudio or { } } +local IsPedAPlayer = IsPedAPlayer +local GetPlayerServerId = GetPlayerServerId +local NetworkGetPlayerIndexFromPed = NetworkGetPlayerIndexFromPed local SpatialHashGrid = Util.SpatialHashGrid local grid = SpatialHashGrid:new(100) local StateManager = Util.StateManager() @@ -43,6 +46,7 @@ Container = { indexes = { models = {}, entities = {}, + players = {}, bones = {}, globals = { bones = {}, @@ -196,6 +200,11 @@ local function classifyMenuInstance(instance) models[model] = models[model] or {} table.insert(models[model], instance.id) + elseif instance.player then + local players = indexes.players + players[instance.player] = players[instance.player] or {} + + table.insert(players[instance.player], instance.id) end end @@ -251,6 +260,12 @@ function Container.create(t) if t.position then instance.position = { x = t.position.x, y = t.position.y, z = t.position.z, id = id } grid:insert(instance.position) + elseif t.player then + if type(t.player) ~= 'number' then + warn('Player id must a integer value') + return + end + instance.player = t.player elseif t.entity then if not DoesEntityExist(t.entity) then local message = ( @@ -480,6 +495,14 @@ local function populateMenus(container, combinedIds, id, bones, closestBoneName, return container end +local function IdentifyPlayerServerId(entityType, entity) + return entityType == 1 and IsPedAPlayer(entity) and GetPlayerServerId(NetworkGetPlayerIndexFromPed(entity)) +end + +local function isPedAPlayer(entityType, entity) + return entityType == 1 and IsPedAPlayer(entity) +end + function Container.getMenu(model, entity, menuId) local id local combinedIds = {} @@ -506,6 +529,12 @@ function Container.getMenu(model, entity, menuId) end end + local playerId = IdentifyPlayerServerId(GetEntityType(entity), entity) + + if playerId then + Util.table_merge(combinedIds, Container.indexes.players[playerId] or {}) + end + -- bone local bones = Container.indexes.bones[entity] if bones and closestBoneName then @@ -521,7 +550,7 @@ local function globalsExistsCheck(entity, entityType) if not entityType or entityType == 0 then return false end local globals = Container.indexes.globals local specificGlobals = globals[set[entityType]] - local isPlayer = entityType == 1 and IsPedAPlayer(entity) + local isPlayer = isPedAPlayer(entityType, entity) if isPlayer and globals['players'] and next(globals['players']) then return true @@ -531,8 +560,6 @@ local function globalsExistsCheck(entity, entityType) return true end - - if specificGlobals and next(specificGlobals) then return true end @@ -540,17 +567,20 @@ local function globalsExistsCheck(entity, entityType) return false end + function Container.getMenuType(t) local model = t.model local entity = t.entity local entityType = t.entityType local entities = Container.indexes.entities local models = Container.indexes.models + local players = Container.indexes.players + local playerId = IdentifyPlayerServerId(entityType, entity) if t.closestPoint and next(t.closestPoint) then -- onPosition return MenuTypes['ON_POSITION'] - elseif (entityType == 3 or entityType == 2) and models[model] or entities[entity] or globalsExistsCheck(entity, entityType) then + elseif (entityType == 3 or entityType == 2) and models[model] or entities[entity] or players[playerId] or globalsExistsCheck(entity, entityType) then -- onModel / onEntity / onBone return MenuTypes['ON_ENTITY'] else diff --git a/interactionMenu/lua/examples/onPlayers.lua b/interactionMenu/lua/examples/onPlayers.lua new file mode 100644 index 0000000..e146b25 --- /dev/null +++ b/interactionMenu/lua/examples/onPlayers.lua @@ -0,0 +1,31 @@ +-- _ +-- | | +-- _____ _| | _____ ___ _ __ +-- / __\ \ /\ / / |/ / _ \/ _ \ '_ \ +-- \__ \\ V V /| < __/ __/ |_) | +-- |___/ \_/\_/ |_|\_\___|\___| .__/ +-- | | +-- |_| +-- https://github.com/swkeep + +if not DEVMODE then return end + +CreateThread(function() + exports['interactionMenu']:create { + player = 2, + offset = vec3(0, 0, 0), + maxDistance = 1.0, + options = { + { + label = 'Just On Player Id: 2', + icon = 'fa fa-person', + action = { + type = 'sync', + func = function(data) + Util.print_table(data) + end + } + } + } + } +end)