--[[
	-USAGE-
	
	p"Willox":Kill()
	p"*":Kill()

	local steamid = p"skooch":SteamID()

	Will return last result after calling method on all matching players
]]

local function MetaCallIterator(func, objects)
	return function(_, ...)
		for k, obj in ipairs(objects) do
			if k == #objects then
				return func(obj, ...)
			else
				func(obj, ...)
			end
		end
	end
end


local plyMeta = FindMetaTable("Player")

local pMeta = {}
pMeta.__index = function(self, key)
	local func = plyMeta.__index({}, key) -- This will also check the Entity metatable

	if type(func) == "function" then
		return MetaCallIterator(func, self.Players)
	end
end

function p(name)
	local obj = {}

	if name == "*" then
		obj.Players = player.GetAll()
	else
		obj.Players = {}

		for _, ply in pairs(player.GetAll()) do
			if string.find(string.lower(ply:Nick()), string.lower(name), nil, true) then
				table.insert(obj.Players, ply)
			end
		end
	end

	setmetatable(obj, pMeta)
	return obj
end
