hey. Is there any way to create new hooks? I’m asking cause in fretta there are hooks that are used only there and the only thing which is used to create them is “function GM:SomeHook( some_args )”. I want to be able to use hook.Add to my personal hooks.
I don’t need to call the hook. I need to create a new one, that isn’t in the list which contains the default hooks( http://wiki.garrysmod.com/?title=Gamemode_Hooks ).
That’s how you create a new hook, you use that to make all hooks that have been added with hook.Add get called with optional specified parameters.
Example how you could create your own hook: (A function like this is completely unnecessary)
hook.Add(“5sechook”, “example”, function()
local t = 0
hook.Add(“Think”, “example5sechook”, function()
if CurTime() > t then
t = CurTime() + 5
Ok thanks. It’s nbeen nder my nose for so long . But to be honest I didn’t find anything about hook.Add besides that it can hook your functions to specified events so thanks for telling me.
local scrw, scrh, allowed = ScrW(), ScrH(), true;
hook.Add(“Tick”, “CallScreenSizeUpdateHook”, function()
if( ScrW() != scrw && ScrH() != scrh && allowed ) then
hook.Call(“ScreenSizeUpdate”, nil, scrw, scrh, ScrW(), ScrH());
scrw, scrh, allowed = ScrW(), ScrH(), false; elseif( ScrW() == scrw && ScrH() == scrh ) then allowed = true; end
hook.Add(“ScreenSizeUpdate”, “GetScreenParameters”, function(oldw, oldh, neww, newh)
MsgN(“Oi! Your screen resolution has changed from “…oldw…“x”…oldh…” to “…neww…“x”…newh…”!”);
Thanks a lot. So basicly I need hook.Add not function GM:Hookname( args )?
function GM:Hook( args ) only works if the hook is part of the GM table, so on line 5 of that guys code you would need to replace nil with GM if you wanted to do function GM:ScreenSizeUpate( args ), otherwise yes you need to use hook.Add.