You will want to choose a way to store the data. The four main ones are:
- Database NPC flags
- Files
- SQLite
- Player flags
The first one should be thrown out in this case as all information you store will be kept in memory. When Era used flags like this, we were using almost 250 MB of memory just for the database, which caused a lot of problems for the rest of the server.
I would also throw out the last one since the data would still be kept in memory as long as the player was online, and RC will truncate any player flags to ~255 characters in length. In addition, if the player were to be reset, they would lose all of their mail.
Both files and SQLite are acceptable in this case. I would recommend SQLite for this instance, but it has a far larger learning curve, and if you use it without understanding it you can cause major problems. If you're interested in taking the SQL route, there are some tutorials available on the internet. I started on a guide
here—it's lacking a lot of stuff right now, though.
Graal data files are very simple. They are simply a set of variables and values, one per line, that looks like this:
PHP Code:
foo=bar
baz="a","b"
test=92
If we pretend that this file is located at
data/test.txt, then we can use the following code to access it:
PHP Code:
temp.vars.loadVars("data/test.txt");
echo(temp.vars.foo); // echoes "bar"
echo(temp.vars.baz[0]); // echoes "a"
echo(temp.vars.test + 9); // echoes "101"
Saving variables is equally simple:
PHP Code:
// defining the variable like this may or may not be necessary;
// I do it to clarify my purpose
temp.vars = null;
temp.vars.stringExample = "one";
temp.vars.arrayExample = {"a", "b", 76};
temp.vars.numberExample = 47;
// first parameter is location to save to
// second parameter is whether or not to append
// false = erase the existing file, replace it with this
// true = add these values to the existing file
temp.vars.saveVars("data/test.txt", false);
Note that in order to allow scripts to access files, you need to give the NPC-server rights to those files, just like if it were a staff member. Open the rights of
(npcserver) and add to their folder rights:
Quote:
rw data/*
rw data/*/*
rw data/*/*/*
rw data/*/*/*/*
|
(I like to keep all the script data inside a data directory and organized into subdirectories—you can choose your own structure, though)
Be careful not to give the NPC-server rights to scripts or levels unless you trust everyone on RC. Anyone with script or level rights could then download them.
Either way you choose for storing data, be sure to think about how you plan to structure it first. If you use files, my recommendation would be to use a file for each player rather than one file for every player. Otherwise, it will still be loading all of that data into memory every time you check the player's mail.
If you have any questions I'm happy to answer them.