The Flux gamemode table: the handlers of GMod's gamemode hooks that turn Flux into a
gamemode derived from sandbox.
The handlers set players up when they join and spawn, check sandbox actions such as
spawning props against the Flux permissions, play the animations defined by the
Flux.Anim tables, draw the HUD and save the data. While doing so they run Flux's own
hooks (PlayerInitialized, PostPlayerSpawn, PlayerThink, LazyTick, FLHUDPaint
and so on, listed on the Hooks page), which are what plugins and schemas are meant to
implement instead of overriding the GM functions.
Plugin and schema handlers of a hook are called before the handlers added with
hook.Add and before the GM handler. The first handler that returns a non-nil value
ends the call, so the remaining handlers, including the gamemode's, do not run: only
return a value from a handler when the hook's documentation gives it a meaning. Hooks
that are run with Plugin.call never reach the GM handlers.
The handlers are split by realm. The shared ones cover initialization, player animations,
the noclip and physics gun checks and the timers behind the periodic hooks (LazyTick,
HalfSecond, OneSecond, OneMinute); the server and the client ones are in the sv_
and cl_ hook files.
Summary
Hooks
Hooks
Does nothing, so that the default death notices are never added.
Prevents players from picking entities up with the use key.
Parameters
- _actor Player
- _entity Entity
Returns
- Boolean always false
Picks the base activity of a player (idle, walking or running), updates their move_yaw pose parameter and plays the landing gesture when they touch the ground. An animation forced with Player#set_animation takes priority. The run threshold comes from the animation table and has a small hysteresis so that the animation does not flicker when moving at about that speed.
Parameters
- actor Player
- velocity Vector velocity of the player
Returns
- Number activity (ACT_ enum, or -1 for a forced animation)
- Number sequence to play instead of the activity, or -1 for none
Prevents players from killing themselves through the console.
Parameters
- _actor Player
Returns
- Boolean always false
Creates the context menu if the local player has the context_menu permission and removes it if they do not.
Returns
- Boolean always true
Plays the attack and reload gestures of the player's hold type, with their crouched variants where the animation table has them, handles the jump and reload cancel events and plays the gestures sent with Player#play_gesture. Models without an animation table use the default player gestures.
Parameters
- actor Player
- event Number animation event, PLAYERANIMEVENT_ enum
- data Number data of the event; the activity or sequence of a custom gesture
Returns
- Number activity for the view model or ACT_INVALID; nil for unhandled events
Does nothing, which disables the default handling of a player's death.
Parameters
- _victim Player the player who died
- _attacker Entity
- _damage_info CTakeDamageInfo
Does nothing, which removes the default death notices from the HUD.
Implements hook DrawPlayerTargetID
Collects the target ID lines of a player through the GetDrawPlayerInfo hook and draws them in order of priority, fading out between 500 and 640 units of distance. Nothing is drawn if the PreDrawPlayerInfo hook returns false.
Parameters
- target Player the player being looked at
- x Number screen x of the horizontal center of the text
- y Number screen y of the first line
- distance Number distance to the player in units
Clears the networked variables of the removed entity before passing the event on to the base gamemode.
Parameters
- entity Entity
Runs the PlayerTakeDamage hook when the damaged entity is a player.
Parameters
- ent Entity the entity taking damage
- damage_info CTakeDamageInfo
Implements hook FLHUDPaint
Draws the circular action progress indicator in the middle of the screen if a percentage was set with Flux.set_circle_percent.
Parameters
- _cur_time Number current CurTime()
- _scrw Number screen width
- _scrh Number screen height
Implements hook FLSaveData
Saves the config and runs the SaveData hook, then the PostSaveData hook.
Implements hook FluxPackageLoaded
Writes the files that get sent to clients (shared data, settings, language phrases and whatever the FLWriteClientFiles handlers add) into lua/_flux/client.
Implements hook GetDrawPlayerInfo
Adds the name of the player to the lines shown in their target ID.
Parameters
- target Player the player being looked at
- _x Number screen x of the target ID
- _y Number screen y of the target ID
- _distance Number distance to the player in units
- lines Map lines to draw, keyed by ID. Each one is a table with the text and priority fields, and optionally font, color, offset_x and offset_y
Returns the fall damage of a player: the result of the FLGetFallDamage hook if it returns one, otherwise a value calculated from the fall speed.
Parameters
- actor Player
- speed Number fall speed
Returns
- Number damage to deal
Returns the gamemode name shown in the server browser: name_override if it is a string, otherwise 'FL - ' followed by the schema name.
Returns
- String
Does nothing, which disables the default ear grab animation while chatting.
Does nothing, which disables the default ammo pickup notification.
Parameters
- _item_name String
- _amount Number
Does nothing, which disables the default pickup history on the HUD.
Draws the loading screen with its status text and progress bar while the local player is not initialized yet or the ShouldDrawLoadingScreen hook returns true.
Finds the entity the local player is looking at, or the one closest to the crosshair within a narrow cone, and draws its target ID through the DrawPlayerTargetID hook, the entity's own DrawTargetID method or the DrawEntityTargetID hook. The local player is never a target, even when the camera of the third person view sees them.
Does nothing, which disables the default item pickup notification.
Parameters
- _item_name String
Draws the Flux HUD once the local player is initialized: the damage flash, the death screen while dead or the info displays and the top bars while alive (unless FLHUDPaint returns a truthy value), and the white respawn fade. Skipped when the ShouldHUDPaint hook returns false.
Implements hook HUDPaintDeathBackground
Draws the red blood overlay behind the death screen.
Parameters
- _cur_time Number current CurTime()
- w Number screen width
- h Number screen height
Hides the default HUD elements that Flux replaces, such as health, armor, ammo, the crosshair and the damage indicators.
Parameters
- element String name of the HUD element
Returns
- Boolean false for the hidden elements, true for everything else
Removes unused sandbox hooks and, on the server, imports the configuration from the settings, loads the config, connects to the database and registers the Discord webhooks. Runs the FLInitialize hook when done.
On the server
Registers the Flux tools with the tool gun and runs the LoadData and FLInitPostEntity hooks.
On the client
Stores the local player in the PLAYER global, sends the client's language to the server, reports to the server that the player has been created and runs the client-side loading hooks (PlayerModelChanged for every player, SynchronizeTools, LoadData, FLInitPostEntity).
Defined in
Implements hook LanguageChanged
Keeps the language setting in step when the language of the client changes for another reason than the setting itself, such as the fl_language console variable.
Parameters
- _new_lang String new language code
- _old_lang String previous language code
Does nothing, which disables the default mouth movement while using voice chat.
Implements hook OnConfigSet
Applies changes of the walk_speed, run_speed, crouched_speed and jump_power configs to every player.
Parameters
- key String key of the config that has changed
- _old_value Any
- new_value Any
Implements hook OneSecond
Runs the FLSaveData hook every data_save_interval seconds, unless FLShouldSaveData returns false. Also checks every half an hour whether the server is empty and reloads the map if it is, unless ShouldServerAutoRestart returns false.
Lets the base gamemode freeze the entity if the player has the physgun_freeze permission or a PlayerCanPhysgunFreeze handler allows it. Plugins that want to refuse a freeze return false from OnPhysgunFreeze before this handler runs.
Parameters
- weapon Weapon the physics gun
- phys_obj PhysObj the physics object being frozen
- entity Entity the entity the physics object belongs to
- actor Player the player trying to freeze it
Returns
- Boolean false if the entity has been frozen, nil otherwise
After a Lua refresh, registers the Flux tools with the tool gun again and, in development, reapplies the animation table of every player.
hook.Add id: FLWriteClientFiles
Writes the files that get sent to clients again after a Lua refresh.
Implements hook OnWeaponRaised
Plays the raise or lower gesture of the weapon's hold type when the raised state of the player's weapon changes. Only runs on the server, where the state is changed.
Parameters
- actor Player
- weapon Weapon weapon that was raised or lowered
- raised Boolean new state
Lets players with the physgun_pickup permission pick entities up with the physics gun, and players without it when a PlayerCanPhysgunPickup handler allows it. Plugins that want to refuse a pickup return false from PhysgunPickup; they do not return true from it, as that would keep the other handlers from refusing.
Parameters
- actor Player
- entity Entity the entity being picked up
Returns
- Boolean true if the player may pick the entity up, nil otherwise
Intercepts the undo bind and blocks it when the SoftUndo hook returns a value.
Parameters
- client Player
- bind String the bind that was triggered
- pressed Boolean whether the key was pressed rather than released
Returns
- Boolean true to block the bind, nil otherwise
Stores the time at which the player may respawn, based on the respawn_delay config.
Parameters
- victim Player the player who died
- _inflictor Entity
- _attacker Entity
Mutes the default death sound.
Parameters
- _victim Player
Returns
- Boolean always true
Implements hook PlayerDeathThink
Respawns a dead player once their respawn time has passed.
Parameters
- actor Player
Returns
- Boolean always false
Implements hook PlayerDisconnected
Saves the data of the player unless their should_save_data field is false, tells all clients about the disconnect and logs it.
Parameters
- actor Player
Decides whether a player may give themselves a weapon. Requires the spawn_sweps permission and that the FLPlayerGiveSWEP hook does not return false. Invalid players are always allowed.
Parameters
- actor Player
- weapon String class of the weapon
- swep Map information about the weapon from the weapon list
Returns
- Boolean whether giving the weapon is allowed
Implements hook PlayerInitialized
On the server
Marks the player as initialized and, shortly after, runs PlayerInitialized on their client.
Parameters
- actor Player
On the client
Rebuilds the spawn menu and the tool menu once the server has initialized the local player.
Parameters
- actor
Defined in
Implements hook PlayerInitialSpawn
Sets up a newly connected player: assigns the flux_player class and the 'user' group, restores their saved data and announces the spawn to all clients. Bots are marked as initialized right away instead.
Parameters
- actor Player
Implements hook PlayerModelChanged
Assigns the compiled animation table of the new model to the player and, on the client, disables inverse kinematics for them. Does nothing if no new model is given.
Parameters
- target Player
- new_model String path of the new model
- _old_model String path of the previous model
Decides whether a player may toggle noclip by asking the plugins through the PlayerEnterNoclip and PlayerExitNoclip hooks. If no plugin returns a value, leaving noclip is allowed and entering it requires the 'noclip' permission.
Parameters
- actor Player
- state Boolean true when entering noclip, false when leaving it
Returns
- Boolean whether the change is allowed
Implements hook PlayerOneSecond
Runs the PlayerPositionChanged hook if the player has moved since the previous check.
Parameters
- actor Player
- cur_time Number current CurTime()
Implements hook PlayerSay
Passes chat messages that start with a command prefix to the command interpreter and hides them from the chat.
Parameters
- actor Player
- text String the chat message
- _team_chat Boolean whether the message was sent to the team chat
Returns
- String an empty string if the message was a command, nil otherwise
Implements hook PlayerSetModel
Sets the model of a player. A string returned by the PrePlayerSetModel hook is used as the model, and false defers to the base gamemode. Otherwise bots and initialized players get the model from their 'model' networked variable (a citizen model if it is not set), and anyone else is left to the base gamemode.
Parameters
- actor Player
Asks the FLPlayerShouldTakeDamage hook whether a player can be damaged. The damage is only blocked when the hook returns false.
Parameters
- victim Player
- attacker Entity
Returns
- Boolean false if the hook has returned false, true otherwise
Resets the state of a spawning player (model, collisions, visibility and the movement speeds from the config), runs the PostPlayerSpawn hook and creates their hands model.
Parameters
- actor Player
Decides whether a player may spawn an effect. Requires the spawn_entities permission and that the FLPlayerSpawnEffect hook does not return false. Invalid players are always allowed.
Parameters
- actor Player
- model String model of the effect
Returns
- Boolean whether spawning is allowed
Decides whether a player may spawn an NPC. Requires the spawn_npcs permission and that the FLPlayerSpawnNPC hook does not return false. Invalid players are always allowed.
Parameters
- actor Player
- npc String type of the NPC
- weapon String class of the weapon given to the NPC
Returns
- Boolean whether spawning is allowed
Decides whether a player may spawn a prop, ragdoll or effect. Requires the spawn_entities permission and that the FLPlayerSpawnObject hook does not return false. Invalid players are always allowed.
Parameters
- actor Player
- model String model of the object
- skin Number skin of the object
Returns
- Boolean whether spawning is allowed
Decides whether a player may spawn a prop. Requires the spawn_props permission and that the FLPlayerSpawnProp hook does not return false. Invalid players are always allowed.
Parameters
- actor Player
- model String model of the prop
Returns
- Boolean whether spawning is allowed
Decides whether a player may spawn a ragdoll. Requires the spawn_ragdolls permission and that the FLPlayerSpawnRagdoll hook does not return false. Invalid players are always allowed.
Parameters
- actor Player
- model String model of the ragdoll
Returns
- Boolean whether spawning is allowed
Decides whether a player may spawn a scripted entity. Requires the spawn_entities permission and that the FLPlayerSpawnSENT hook does not return false. Invalid players are always allowed.
Parameters
- actor Player
- class String class of the entity
Returns
- Boolean whether spawning is allowed
Decides whether a player may spawn a weapon. Requires the spawn_sweps permission and that the FLPlayerSpawnSWEP hook does not return false. Invalid players are always allowed.
Parameters
- actor Player
- weapon String class of the weapon
- swep Map information about the weapon from the weapon list
Returns
- Boolean whether spawning is allowed
Decides whether a player may spawn a vehicle. Requires the spawn_vehicles permission and that the FLPlayerSpawnVehicle hook does not return false. Invalid players are always allowed.
Parameters
- actor Player
- model String model of the vehicle
- name String name of the vehicle in the vehicle list
- tab Map vehicle table from the vehicle list
Returns
- Boolean whether spawning is allowed
Lets the PlayerSwitchedFlashlight hook decide whether a player may toggle their flashlight, and leaves the decision to the base gamemode when no handler returns anything. Plugin and schema handlers of PlayerSwitchFlashlight run before this one and replace it when they return a value.
Parameters
- actor Player
- on Boolean whether the flashlight is being turned on
Returns
- Boolean whether the flashlight may be toggled
Implements hook PlayerTakeDamage
Notifies the client of the damaged player, which shows the damage flash on their HUD.
Parameters
- victim Player
- _damage_info CTakeDamageInfo
Implements hook PlayerThink
Runs the current action of the player, unless it is 'idle' or 'spawning'.
Parameters
- actor Player
- _cur_time Number current CurTime()
Tells the client of the player to open the interaction menu for the player or entity they pressed the use key on, at most once a second.
Parameters
- activator Player
- target Entity the entity being used
Implements hook PopulateToolMenu
Adds every registered Flux tool to the tool list of the spawn menu, then runs the SynchronizeTools hook.
Implements hook PostPlayerLoadout
Strips the weapons of the player, gives them the default loadout and selects the first weapon of it, then runs the PlayerLoadoutGiven hook for the weapons that plugins add.
Parameters
- actor Player
- default_loadout List<String> weapon classes to give
Implements hook PostPlayerSpawn
Gives the player their loadout, plus the tool gun and the physics gun if they have the toolgun and physgun permissions, then runs PostPlayerSpawn on their client.
Parameters
- actor Player
Implements hook RegisterClientSettings ยท hook.Add id: FLLanguageSetting
Registers the language setting when the Settings plugin collects the settings, which
it does while the schema is being included. On the first load the gamemode is not
registered yet at that point and a GM method would not be called, which is why the
handler is added with hook.Add instead.
Updates the blurred copy of the screen used by draw.blur_box and draw.blur_panel. Only does so while something has requested the blur, and no more often than the blur update interval unless Flux.blur_update_fps is 0.
Implements hook ServerRestart
Saves the data of every player before the server restarts.
Does nothing, which disables the default help menu.
Parameters
- _actor Player
Saves everything when the server shuts down or changes the map: runs the FLSaveData hook and saves the data of every player. Flux.shutting_down is true from the start, so that the save handlers and the code which runs while the map unloads (an entity's OnRemove, for example) can tell.
Implements hook SoftUndo
Asks the server to undo the last Flux undo entry of the local player.
Parameters
- _client Player unused, the local player is always used
Returns
- Boolean true if the local player has entries in their undo queue, nil otherwise
Removes the sandbox hint timer about saving spawnlists.
Removes the sandbox hint timers and allows the spawn menu to open.
Returns
- Boolean always true
Implements hook SynchronizeTools
Copies every registered Flux tool into the tool table of the tool gun.
Updates the global UI offset from the rotation of the local player's view, so that HUD elements using it sway and settle back. Skipped while the player is frozen.
On the server
Runs the PlayerThink hook for every player eight times a second and the PlayerOneSecond hook once a second.
On the client
Checks once a second whether the screen resolution has changed and runs the OnResolutionChanged hook if it has.
Defined in
Translates an activity into the animation that the Flux animation tables define for the player's model, weapon hold type and weapon state. On the ground this is the lowered or raised movement animation, in the air the jump, glide, swim or noclip animation and in a vehicle the sitting animation. Models without an animation table are handled by the base gamemode.
Parameters
- actor Player
- act Number activity to translate, ACT_ enum
Returns
- Number translated activity or sequence ID, or nil if the tables have no match
GM:UpdateAnimation(actor, velocity, max_seq_ground_speed)
shared packages/flow/hooks/sh_hooks.lua:379Keeps the playback rate handling of the base gamemode and, on the server, plays one of the idle fidget gestures of the animation table every once in a while when the player stands still on the ground. Does nothing for tables without fidgets.
Parameters
- actor Player
- velocity Vector velocity of the player
- max_seq_ground_speed Number ground speed of the current sequence