hook.Add

From GMod Wiki

Revision as of 15:38, 18 April 2011 by Lexi (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Function
Syntax hook.Add( String hook, String unique_name, Function hook_func )
Where is this used?
Description:
Hook an event to a function
Returns: nil
Part of Library: Hook
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Hook.Add]Hook.Add [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionThis hooks a bogus function to "Think"
Used onNewerShared.png
Code
 
function onThink()
   //this is the bogus function's body, this function does nothing :/
end
hook.Add( "Think", "Some unique name", onThink )
//The second argument is to prevent you from hooking something more than once.
 
OutputN/A


DescriptionTells victims who killed them in chat.
Used onNewerServer.png
Code
 
function sayThatName(victim,inflictor,killer) //Use the same arguments as the original function you're hooking to
	victim:PrintMessage(HUD_PRINTTALK,killer:Nick().." killed you!\n")
end
hook.Add("PlayerDeath","Inform Murder Victims",sayThatName)
 
Output"Pwnd has killed you!" in the victim's chat (assuming that the killer was named Pwnd)


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox