This name can be anything: a string, a number.
#Client side addons for gmod full
The full list is available at the Gamemode Hooks page. There is one for when a player spawns, when a player dies, when someone connects, when someone takes damage, when someone presses a key, etc. The first argument is the "type" of hook. The function hook.Add takes three arguments (please read the Functions section if you haven't already). Hook.Add ( "Think", "My button hook", MyHookFunction ) Local MyHookFunction = function ( ) if LocalPlayer ( ):KeyDown (IN_ATTACK ) then If you wanted to print that message whenever your player presses a key, you would need to use a hook. After that, GMod does not even consider it. This script will run once when you load a game. Msg ( "I'm attackin ya! \n" ) end // end of file a if LocalPlayer ( ):KeyDown (IN_ATTACK ) then // IN_ATTACK is the attack button (usually left mouse) When a script is run, the file is executed and when it reaches the end execution stops.
#Client side addons for gmod mod
The "PrimaryFire" hook on the AK47 will respond to the event by making the weapon shoot bullets, deplete ammo, etc.īecause events play such an important role, Garry's Mod is said to be event driven.Ī "Hook" is a way to make a function run whenever something happens in the game.Ī list of game-related hooks can be found here. He presses his primary fire key, and the game triggers a "primary fire" event on the weapon. This makes practically everything related to Lua in Garry's Mod possible, such as addons, scripted weapons, and scripted entities.įor example, say a player is holding an AK47. If it finds one, the game tries to trigger a "Use" event involving the object.Īnother reason events are important is that they allow scripters to change or add onto Garry's Mod. The hook checks that the key was pressed, and looks for an object in front of "player 5". Information that gets passed with this event is the player who pressed the key, and the key he pressed. One reason that events are so important is because they make interactions between players and the game world possible.įor example, one kind of event is "player presses key". The important thing to keep in mind is that events "happen", and any number of hooks (including 0 hooks) can "respond" to this event.Įvents are an important programming topic in general, but especially so in Garry's Mod.
So, what's the difference between an event and a hook? Hooks are functions that are "hooked up" to an event. Lua responds to an event by running hooks. Whenever an event occurs, Garry's Mod tells Lua that the event has happened. For example, if a player died, then the event might also carry information about which player died. Sometimes, events even carry associated information. There are even some events for non-game world things, such as drawing graphics on the Heads Up Display (or HUD, for short). More examples are when a player spawns, takes damage, or disconnects. One example of an event is when a player dies. This article will teach you the basics of a couple important concepts in Garry's Mod Lua scripting: events and hooks.Įvents are specific happenings in the game world.