From a77ee4ce201de757ce4c5958d9e499a65b2cf416 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Wed, 28 Feb 2018 09:32:08 -0500 Subject: Generalize the ply:Has() function Allow ply:Has() to accept functions (it already did, but now the documentation matches to explicitly allow it), and the variable names are not misleading. --- gamemode/core/inventory/sv_invtracker.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gamemode/core/inventory/sv_invtracker.lua b/gamemode/core/inventory/sv_invtracker.lua index 88de42e..257410b 100644 --- a/gamemode/core/inventory/sv_invtracker.lua +++ b/gamemode/core/inventory/sv_invtracker.lua @@ -207,13 +207,13 @@ end local plymeta = FindMetaTable("Player") ---A shortcut to check if a player has an item. --- Checks if a player has an item ---@metamethod player:HasItem(str) ---@tparam string str The name of the item to look for +-- Checks if a player has an item. This method will only return the position of the FIRST item found that matches. The player MAY have other items which match. +--@metamethod player:HasItem(ptr) +--@tparam (string|function) ptr If ptr is a string, looks for an item with the same name, ptr may also be a function that takes 1 argument (an item) and returns true if the item is what you're looking for. --@treturn table|false Returns the position if the player has the item, false if they don't -function plymeta:HasItem(str) +function plymeta:HasItem(ptr) for k,v in pairs(self.data.inventories) do - local p = v:Has(str) + local p = v:Has(ptr) if type(p) == "table" then return {k,p} end -- cgit v1.2.3-70-g09d2