General > Developers Corner

Hooks not working?

(1/1)

eriikok:
Hello.

So I have this problem, there seems to be a problem with the hooks on the current Github version of ULib. I have these spawn hooks to prevent players from spawning stuff, it gets called and I return false, but the entity still spawns.

This is a normal PlayerSpawnSENT:

--- Code: ---hook.Add( "PlayerSpawnSENT", "asdasdawefdasdgrgdsfsretASGRS", function(ply,sent)
ply:ChatPrint("MEEP MEEP")
return false
end, -2 )
--- End code ---

Obviously, the player should not be able to spawn a Bouncy ball. But:

*Notice bottom left corner.

Has anyone else experienced this? Is it a known problem. Is it something I somehow missed? (Been looking at this for days man)

Timmy:
hook.Add() only takes 3 arguments. You gave 4.

eriikok:

--- Quote from: Timmy on October 22, 2015, 04:39:04 AM ---hook.Add() only takes 3 arguments. You gave 4.

--- End quote ---

ULib adds a 4th argument. https://github.com/Nayruden/Ulysses/blob/master/ulib/lua/ulib/shared/hook.lua

Timmy:
Oh, I see. Sorry about that. I didn't know ULib added hook priorities.

This behaviour is caused by the following if-statement: https://github.com/Nayruden/Ulysses/blob/master/ulib/lua/ulib/shared/hook.lua#L111-L113

Hook priorities:
HOOK_MONITOR_HIGH = -2
HOOK_HIGH = -1
HOOK_NORMAL = 0
HOOK_LOW = 1
HOOK_MONITOR_LOW = 2

The 4th argument, the priority, can't be a monitor priority if you want to return something. It has to be either -1, 0 or 1 — or the return value won't be registered.

Edit: Fix grammar

eriikok:
Aw man, that was the issue. Thank you so much man, been scratching my head with this on several occasions, often several hours. :p

Navigation

[0] Message Index

Go to full version