How nightmoon1996/knm-save works
Project type and purpose
• This is a server-side plugin/script for Garry’s Mod (specifically the DarkRP gamemode).
• Its sole purpose is to persist player data (job, ammo, health, shield) into an SQLite database on various events (spawn, disconnect, shutdown) and reload it when they rejoin.
File structure
• Top level:
• README.md (documentation)
• sv_knmsave.lua (the single entrypoint Lua script)
• No separate frontend/backend folders – everything lives in one server-script file.
• No build or deployment scripts; installation is a simple file drop.
README for additional insights
• Hooks used: PlayerInitialSpawn, PlayerDisconnected, ShutDown
• SQL module: built-in Garry’s Mod SQLite interface
• Operational flow:
a. On PlayerInitialSpawn → read data from database → apply to player
b. On PlayerDisconnected / ShutDown → collect current data → write to database
Main components and interactions
a. Components:
1. Game Client (the player running Garry’s Mod)
2. Garry’s Mod Server (running DarkRP gamemode)
3. sv_knmsave.lua plugin
4. SQLite Database (local file on the server)
b. Interactions:
• The Game Client connects to the Garry’s Mod Server.
• DarkRP triggers PlayerInitialSpawn → the plugin issues “SELECT” queries to SQLite to load saved state → plugin updates the Player object.
• During gameplay, state is held in memory by DarkRP.
• On PlayerDisconnected or on Server ShutDown → plugin reads in-memory state from DarkRP’s Player object → issues “INSERT/UPDATE” queries to SQLite.
c. Architectural patterns/design principles:
• Event-driven architecture (hook into lifecycle events)
• Single responsibility: plugin only handles persistence
• Direct database access via built-in SQL module (no ORM, no external service)
d. Key technologies:
• Lua (sv_knmsave.lua)
• Garry’s Mod hook system (PlayerInitialSpawn, PlayerDisconnected, ShutDown)
• SQLite (built-in Garry’s Mod sql module)