You’re missing the point, read the code closer. See functions as variables. Without parenthesis after them, they’re just values representing the function. If you put parenthesis after the functions (or use them on another variable as a method), you call that function. The “return” command in a function determines what value you get from running a function.
In hooks, the regular way to hook a function is by defining the function, and then supplying the function itself to the hook, not by calling the function. A function “variable” is defined like so;
local function DoStuffOnInit()
local ididthis = "I did stuff"
Now you have a variable called “DoStuffOnInit”, which is of the function type of value. If you run print( tostring( DoStuffOnInit ) ) (note: didn’t put any parenthesis after the function, therefore didn’t call/run it), it’ll print something like “function: 00414FB0”. Running print( tostring( DoStuffOnInit( ) ) ) (note: parenthesis after function; I called it) will print “I did stuff”.
Hooking this function to an event is done by supplying the hook.Add function with the function you want to hook, as a value. That is, you give it the function, not whatever the function returns. Hooked functions are then called when the function they’re hooked to is called; that is, functions hooked to the “Initialize” hook are called when the function GM:Initialize() is called (remember that calling a function is the same as running it).
What Shadow did above was hook a function to Initialize which overwrites the GM:GetFallDamage function with a new one. All he did was define the function inside the hook.Add call, instead of putting it in a variable before. The equivalent to that would be writing ‘return “I did stuff”’ in my function above, instead of first setting a variable with the same value.
In short, he did this:
local function GetFallDamageInit()
function GAMEMODE:GetFallDamage( ply, speed ) -- overwrite GAMEMODE:GetFallDamage
hook.Add("Initialize", "GetFallDamage Init", GetFallDamageInit)
Also, as far as I know, the source engine is event driven, or at least the Lua engine in Garry’s mod. This means that hooks aren’t called when a condition is met per sé (as in checking if the condition is met every tick; did player touch ground last tick? Apply fall damage. Has damage been applied? Reduce health. Has health been reduced? Bloody screen), but rather that it runs as soon as something which would mean the condition is met happens (like player touches ground -> apply fall damage -> reduce health -> bloody screen… SO REAL), which in my opinion is a much better technique.