A way to ensure hook is called last

I need my hook added with hook.Add to be called after all other hooks. Like a way to make them the lowest priority. Any ideas?

Not with the current hook system, it uses pairs to loop through the stored hooks so the order is undefined. ulx modifies the hook system https://github.com/Nayruden/Ulysses/blob/master/ulib/lua/ulib/shared/hook.lua to add a priority argument to group hooks, I’m not sure on other admin addons.

This might work:

[lua]local oldhookfunc = GAMEMODE.PlayerDeath – obviously replace PlayerDeath with the hook you need

function GAMEMODE:PlayerDeath(victim, inflictor, attacker, whatever)
local ret = nil
if oldhookfunc then ret = oldhookfunc(victim, inflictor, attacker, whatever) end

-- Your code here

return ret

end[/lua]

Untested, YMMV.

Hm well I can’t modify the hook system myself because then it might conflict with ulx. I don’t want to detour gamemode functions if I don’t have to since there’s no telling what problems that might cause. Lua orders it’s keys by their hash value right? What if I can find a string with a high hash value.

[editline]13th April 2016[/editline]

I guess this is my solution.
[lua]
–Ensure that SF hooks are called after all other hooks.
local detour = GAMEMODE[ hookname ]
if detour then
GAMEMODE[ hookname ] = function ( self, … )
local a, b, c, d, e, f = detour( self, … )
if ( a != nil ) then
return a, b, c, d, e, f
else
return run( lower, customfunc, … )
end
end
else
GAMEMODE[ hookname ] = function ( self, … )
return run( lower, customfunc, … )
end
end

[/lua]