PlayerBindPressed question

This disables the flashlight just fine, but returns and error when blocking slot1.



local function BlockCommands(ply, bind, pressed)

	if LocalPlayer():GetNWBool( "BlockCommands" ) then
		if string.find(bind, "impulse 100") then return true end
		if string.find(pressed, "slot1") then return true end
	end
end
hook.Add( "PlayerBindPress", "BlockCommands", BlockCommands )



Error:
Line4: bad argument #1 to ‘find’ (string expected, got boolean)

you’re using the arguments wrong.

‘pressed’ is whether the bind was pressed or released.

Why are you using PlayerBindPress when you can use PlayerSwitchFlashlight?
[lua]
local function BlockFlashlight(ply, state)
return false
end
hook.Add( “PlayerSwitchFlashlight”, “BlockFlashlight”, BlockFlashlight )
[/lua]

Sorry Luni thats the same example I looked at, I still couldn’t get it working properly.

The flashlight was just the example on the wiki, I want to block slots 1-9 and lastinv.

[lua]if string.match(bind, “slot%d+”) or string.match(bind, “lastinv”) then return true end[/lua]

Thanks Luni, I see what you did there to get it working.

I know what its doing but any info on %d+ ?

you just blew my mind.

Awesome, I’ve seen these used before and I couldn’t really understand what was going on. Thanks for the lesson boss :slight_smile: