

Turning tables into stringsĪ text file is basically a string of characters. This is, perhaps, the easiest method for beginners that will circumvent frustration when converting data types such as Color or Vector, so we will start with this method first. For these reasons, it is the recommended method for beginners. File Based Storage does not require any external modules, as it relies solely on the file library and is pretty straightforward. Text files are a simple way of storing data. However, you may be reading this and you think that your data should be saved at the very last minute, or is really not important enough to be saved every time it is altered - in which case, you can use the GM:ShutDown hook at your own risk! About Furthermore, you should not save data during the GM:ShutDown hook, as it may be too late to start saving data as some players will become invalid which means that their precious token count is now lost. Do not wait until the player leaves to save the number of tokens that they have earned whilst playing, as the server may suffer a fatal crash before then. Therefore, you should deal with the data as quickly as possible to avoid losing it. Unfortunately, Garry's mod servers aren't predictable - they can easily crash without warning or become overloaded. In case you couldn't tell, there is an over-arching theme here: Never trust the client. This is why we must use identification such as Player:SteamID's, since they can never be changed by the client. If we wanted to store a client's health when they log off, and we used their steam names as identification, what's stopping them from changing it before they next log on? Nothing. Let's say we started letting clients keep track of their money what's stopping them from adding a few zeros on the end?Īlways use identification that the client can't manipulate.

Keep all data backed up on the server as this is the only way that you can be sure that the data is authentic.
/close-up-of-hand-using-checklist-on-digital-tablet-170410394-577ad27f5f9b585875b8fbb2-5c0e90bc46e0fb0001c2ff9e.jpg)
Never trust data that has been handled by a client. When handling any data, there are some rules that we should follow: In this tutorial, we will go over File Based Storage. There are multiple ways of storing data in Garry's Mod. If you need to give data to the client, make sure to keep a backup of it on the server! Only store, save, change, and load data from the server.
