Skip to content

Instantly share code, notes, and snippets.

@JJL772
Last active January 8, 2023 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JJL772/d644c402987d26e33bfa231b852ae973 to your computer and use it in GitHub Desktop.
Save JJL772/d644c402987d26e33bfa231b852ae973 to your computer and use it in GitHub Desktop.

Game Rules System

System that helps manage player and map specific configurations.

System Overview

  • Comprised of three layers: player, map and config. Think of this as a stack.
  • Each layer has a different priority, map being the lowest, and player being the highest. Priority determines where and which options may be overridden.
  • Since the player layer has the highest priority, it may override any map-level or config-level option, assuming that option isn't limited to a specific layer(s).
  • The config layer is intended to be used by speedrun or other gameplay altering configs. For example, you'd create a config layer for hl2 to enable suit, disable health regen, enable flashlight, etc. This layer could then be activated on map load when the player selects the hl2 campaign from the start game UI.
  • Some settings may be limited to one or more layers. In general, the player layer is to allow the player to change accessibility options or visuals to tweak the experience. It's not intended to be used as a cheat, so Player.GivePaintGun is limited to the config and map layers.
  • When the game rules system is initialized, it takes a state snapshot of all convars listed in the game rules definition file.
  • When any layer is added or removed, the system performs a full re-execution of the layers. It first restores the initial state snapshot, it then rebuilds the resulting kv3 data structure, and finally re-applies any cvar changes.
  • When the system is unloaded, ie from typing disconnect or quit, the system restores the state snapshot it took.
  • The map layer is unloaded and replaced with the default layer at the end of a map. The system also restores the state snapshot, resetting all convars and such to their pre-game values.

In-game commands for loading/saving/changing values will be provided.

Gamerules definitions file gamerules.kv3

Defines all game rules. Assigns names, type info, defaults and more.

Some of these options are referenced only in code, and appear to do nothing. Having them defined in this file is optional, things will still work as expected code-side, however configs will not be able to set those values.

Game rules config

These are files that just assign values to the defined game rules listed in gamerules.kv3. These will be our speedrun/hl2/whatever configs that the user can select from the UI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment