I tried to learn the garry's mod sql library so I made a thing

So I’ve tried to teach myself about the SQL library in gmod a bit so I made a in-game time played counter,
the code is probably terrible but I though I would share it anyways.

Here’s the code:

I would appreciate any feedback and improvement tips!

This is a neat learning project, I’d recommend going back and redoing it with what you know now to see how you can better optimize. Some things to take into consideration:

  • You update the database and network to clients pretty frequently- The performance hit in this case is negligible but it’s worth thinking about how you can reduce that frequency or possibly even remove the Think hook entirely.
  • Extending your networking to include all connected players’ data would enable you to make a little leaderboard GUI client-side.
  • Consider grouping your addon’s functions under a global table, such as twog.get_client or twog.db.get_client in order to avoid populating the global scope with relatively generic function names like just get_client.

Keep at it!

1 Like

Thanks for the tips!
I updated the code to make sql OO, and removed the Think hook to make a timer for every connected player,
also instead of updating the database every second, I update it every minute and update client every second separately.