ULX

Author Topic: Hooks not working?  (Read 1897 times)

0 Members and 2 Guests are viewing this topic.

Offline eriikok

  • Newbie
  • *
  • Posts: 24
  • Karma: 14
Hooks not working?
« on: October 22, 2015, 04:01:08 AM »
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: [Select]
hook.Add( "PlayerSpawnSENT", "asdasdawefdasdgrgdsfsretASGRS", function(ply,sent)
ply:ChatPrint("MEEP MEEP")
return false
end, -2 )

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)

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Re: Hooks not working?
« Reply #1 on: October 22, 2015, 04:39:04 AM »
hook.Add() only takes 3 arguments. You gave 4.

Offline eriikok

  • Newbie
  • *
  • Posts: 24
  • Karma: 14
Re: Hooks not working?
« Reply #2 on: October 22, 2015, 04:57:10 AM »

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Re: Hooks not working?
« Reply #3 on: October 22, 2015, 05:33:00 AM »
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
« Last Edit: October 22, 2015, 06:05:29 AM by Timmy »

Offline eriikok

  • Newbie
  • *
  • Posts: 24
  • Karma: 14
Re: Hooks not working?
« Reply #4 on: October 22, 2015, 10:29:01 AM »
Aw man, that was the issue. Thank you so much man, been scratching my head with this on several occasions, often several hours. :p