Author Topic: Server Prefs Reseting  (Read 680 times)

Hi, my script has some kind of error that the server prefs keep reseting every time I restart the server...

Please download this CS file and tell me what is wrong.

iban asked me to post this, so as much as i hate the fact you're generating random useless scripts that you should really probably keep for yourself (except for that cash mod banking system, which is not too bad) i'm still gonna pass on the message.

Quote
Unless you shut down the game properly by using quit(), $Pref::Server::* will not export and you will lose any changes to those variables.

However, you should be exporting your own branch of preferences instead of fogging up prefs.cs - Here is how you would do that.

First, change all preferences in there to something like $Club::CashMod::* instead of $Pref::Server::CashMod::* - This will be your own trademark.

Then, at regular intervals (perhaps at the end of every function that makes changes to your preferences), export your globals to your own file using export(). For example...

Code: [Select]
export("$Club::*", "config/server/clubmods.cs");
Just be sure everything that exports to clubmods.cs has $Club::* as its search string so you don't completely overwrite the file with just one mod.

Then, to load the preferences, simply have this at the very start of your server.cs, outside of any function. This will cause it to load your prefs when the script executes.

Code: [Select]
exec("config/server/clubmods.cs");
Good luck.

« Last Edit: April 25, 2009, 12:26:47 AM by Bushido »

If you have either this or another Add-On with an error in the server preference name, it will not be able to execute the file from syntax errors when restarting the game.

For instance, if I created a new storage from a brick event or commandtoserver called "Space Guy's Storage", this will then be saved as:
$Pref::Server::CashStore::storeOwnerSpace Guy's Storage = 2137;

Which has two syntax errors (the space and the quote), and is storing the ID of an object which will not exist when you restart the server - it'd be better to store peoples' BL_IDs, and the storage name.

$Pref::Server::CashStore::storeName[0] = "Space Guy's Storage";
$Pref::Server::CashStore::storeOwner[0] = 130;

then do a loop through all existing storages to find Space Guy's Storage and the brickgroup or client with BL_ID 130. (mine)

Ok, I changed the 2 events to commands, and now it saves perfectly. Thanks for all your help.
« Last Edit: April 25, 2009, 11:12:24 AM by Club559 »

... Unless I go to your server and do commandtoserver('setStorage',"Space Guy's Storage",1");, which would totally erase everyone's storages until you removed all traces of mine from the file.

Ok, now i'm having BIG problems. Whenever the cash in a storage goes to 1.333e+007 or something like that, it says i'm not the owner of the storage anymore.

... Unless I go to your server and do commandtoserver('setStorage',"Space Guy's Storage",1");, which would totally erase everyone's storages until you removed all traces of mine from the file.

Umm, wouldn't a hacker be the only one wanting to do that? :/

Umm, wouldn't a hacker be the only one wanting to do that? :/

I have yet to meet someone who designs a program on the assumption that the human race is full of nice people who don't want to break stuff.