Facepunch / garrysmod-issues

Garry's Mod issue tracker
145 stars 56 forks source link

PlayerUse not returning any value causes use to never work. #3330

Open ZehMatt opened 6 years ago

ZehMatt commented 6 years ago

Details

As the title suggests, not returning specifically true won't allow the player to have +use. Probably better to only disable it if something returns false?

robotboy655 commented 6 years ago

Not exactly surprising, this also goes for any hook that does something when you return false.

thegrb93 commented 6 years ago

Yeah it is surprising. Other hooks use default behavior when nil is returned. This one is using false instead of default.

robotboy655 commented 6 years ago

This behavior happens to all engine hooks that use false as a return to do something.

thegrb93 commented 6 years ago

Ok, then it seems the problem is your gamemode doesn't have a PlayerUse hook or it's returning false.

It should be using this if your hooks don't return anything. https://github.com/Facepunch/garrysmod/blob/master/garrysmod/gamemodes/base/gamemode/player.lua#L126

ZehMatt commented 6 years ago

I'm not exactly having issues because now I know I have to actually return true or false and not nil. I just wanted to bring up the issue since its a little weird and easy to miss. Those hooks should consider nil to use defaulted values imho.

thegrb93 commented 6 years ago

The default is nil which is equivalent to false in an if statement. If you want the default to be true when your hooks return nil then you need GM:PlayerUse to return true.

ZehMatt commented 6 years ago

The engine should not use nil as false rather as undefined and should stick to the defaults whenever this happens.

thegrb93 commented 6 years ago

You can have nil default to true by using the gamemode hook like I mentioned earlier. Don't bother asking to change how the engine works because I doubt that'll ever change.

robotboy655 commented 6 years ago

It's definitely a problem with the game/engine and needs fixing as far as I can tell, just not for the next update, because it needs a lot of testing for those addons that rely on this behavior.

Kefta commented 6 years ago

Could this be implemented for the next update so we have time to test? I honestly don't think it will affect anything since PlayerUse already returns true in the base gamemode by default.

ZehMatt commented 6 years ago

I think this leaves a bigger trail of functions that needs this kind of fix, its not just PlayerUse

robotboy655 commented 6 years ago

I have put in a fix for this, no other hooks are affected yet, so leaving this open.