AllowPlayerPickup Usage Issue

I’m trying to figure out how to limit who can pick up a glowstick ammo entitiy and so far I have the code below inside a lua file in autorun/server:

local weptable = { "blue", "green", "aqua", "purple", "yellow", "red" }
function GM:AllowPlayerPickup( ply, "ent_glowstick_fly")
	for num = 1,6,1 do 
		if ply:HasWeapon( "holster_glowstick_".. weptable[num] ) then
			return true
			return false

However, it doesn’t seem to be effective. What have I done wrong and how can I fix it? Thanks in advance :smiley:


Yeah, where do you think I’ve been looking? If it was simple as reading a wiki entry and everything clicking into place, I wouldn’t be on here asking for help.

Unless you’re making a gamemode, don’t override GM functions. Also, you can use substrings to match general classes.

hook.Add( "AllowPlayerPickup", "GlowstickPickup", function( pPlayer, pEntity )
   if ( pEntity:GetClass() == "ent_glowstick_fly" ) then
      local tWeapons = pPlayer:GetWeapons()
      for i = 1, #tWeapons do
         if ( tWeapons*:GetClass():sub(1, 18) == "holster_glowstick_" ) then
            return true
      return false
end )

Alternatively, you can do table key lookups for the class, like:

local tGlowsticks = {
   ["holster_glowstick_blue"] = true,
   -- etc.


if ( tGlowsticks[tWeapons*:GetClass()] ) then

brb sacrificing my first-born in your name, thank you <3