From Server_Floatplant (first mod I could think of with RTB prefs that wasn't in a zip):
if(isFile("Add-Ons/System_ReturnToBlockland/server.cs"))
{
if(!$RTB::RTBR_ServerControl_Hook)
exec("Add-Ons/System_ReturnToBlockland/RTBR_ServerControl_Hook.cs");
RTB_registerPref("Minimum Admin Level", "Float plant", "Pref::Server::FloatplantLevel", "list Off 4 Everyone 0 Admin 1 Superadmin 2 Host 3", "Server_Floatplant", 2, 0, 0);
RTB_registerPref("Anti-spam search range", "Float plant", "Pref::Server::FloatplantSearchDist", "int 0 20", "Server_Floatplant", 5, 0, 0);
RTB_registerPref("Floatplant trust level", "Float plant", "Pref::Server::FloatplantTrustLevel", "list Build 1 Full 2 Self 3", "Server_Floatplant", 2, 0, 0);
RTB_registerPref("Baseplate Only", "Float plant", "Pref::Server::FloatplantBaseplateOnly", "boolean", "Server_Floatplant", 1, 0, 0);
}
else
{
if($Pref::Server::FloatplantLevel $= "")
$Pref::Server::FloatplantLevel = 2;
if($Pref::Server::FloatplantSearchDist $= "")
$Pref::Server::FloatplantSearchDist = 5;
if($Pref::Server::FloatplantTrustLevel $= "")
$Pref::Server::FloatplantTrustLevel = 2;
}
Deconstruction:
if(isFile("Add-Ons/System_ReturnToBlockland/server.cs"))
If the RTB add-on exists, use RTB prefs. Otherwise, skip to the else.
if(!$RTB::RTBR_ServerControl_Hook)
exec("Add-Ons/System_ReturnToBlockland/RTBR_ServerControl_Hook.cs");
If the RTB mod hasn't been loaded, load it.
RTB_registerPref("Minimum Admin Level", "Float plant", "Pref::Server::FloatplantLevel", "list Off 4 Everyone 0 Admin 1 Superadmin 2 Host 3", "Server_Floatplant", 2, 0, 0);
Define an RTB pref. Pref name, mod name, global variable minus the "$", variable type and arguments as required, mod path, default value, requires restart, host-only, (update function name).
if($Pref::Server::FloatplantLevel $= "")
$Pref::Server::FloatplantLevel = 2;
IF AND ONLY IF the variable IS NOT DEFINED (by, say, the automatically saved preferences file that everyone else disregards like a handicap), set the variable to its default value.
I hate people who just define the variable every single time the mod starts.
There's a reason the server prefs file exists in the first place.