Author Topic: RTB Preferences for maps?  (Read 1126 times)

Could RTB preferences be used to enable/disable content within a map assuming the settings were changed before the map was loaded? For instance, could you have an option to disable loading a certain interior or set of shapes? Perhaps a way to comment out or disable entire portions of a mission file?

If this is possible, would anyone be willing to create the necessary code and help me integrate it into my map?

You just need to change the particular interior to be conditionally loaded. For example in your .mis file:

Code: [Select]
// Standard map objects
new Blah(Map)
{
    Blah blah
};

// Register the pref
RTB_registerPref(...)

// Load optional things
if($Pref::MyMap::Whatever)
{
    %interior = new InteriorInstance(blah)
    {
        somestuff
    };
    Map.add(%interior);
}

So, something like this?

Code: [Select]
//--- OBJECT WRITE BEGIN ---
new SimGroup(MissionGroup) {

   new ScriptObject(MissionInfo) {
         saveName = "Worlds";
         name = "Worlds";
   };
   new MissionArea(MissionArea) {
      Area = "-360 -648 720 1296";
         locked = "true";
         flightCeiling = "300";
         flightCeilingRange = "20";
   };
   new Sky(Sky) {
      position = "336 136 0";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      materialList = "./astroskies/gal.dml";
      cloudHeightPer[0] = "0.349971";
      cloudHeightPer[1] = "0.3";
      cloudHeightPer[2] = "0.199973";
      cloudSpeed1 = "0.0005";
      cloudSpeed2 = "0.001";
      cloudSpeed3 = "0.0003";
      visibleDistance = "600";
      fogDistance = "2000";
      fogColor = "0.000000 0.000000 0.000000 1.000000";
      fogStorm1 = "0";
      fogStorm2 = "0";
      fogStorm3 = "0";
      fogVolume1 = "0 0 0";
      fogVolume2 = "0 0 0";
      fogVolume3 = "0 0 0";
      fogVolumeColor1 = "192.000000 128.000000 128.000000 -222768174765569860000000000000000000000.000000";
      fogVolumeColor2 = "128.000000 128.000000 128.000000 0.000000";
      fogVolumeColor3 = "128.000000 128.000000 128.000000 -170698929442160050000000000000000000000.000000";
      windVelocity = "1 1 0";
      windEffectPrecipitation = "1";
      SkySolidColor = "0.000000 0.000000 0.100000 1.000000";
      useSkyTextures = "1";
      renderBottomTexture = "1";
      noRenderBans = "1";
         locked = "true";
   };
   new Sun() {
      azimuth = "180";
      elevation = "90";
      color = "0.700000 0.650000 0.500000 1.000000";
      ambient = "0.300000 0.250000 0.200000 1.000000";
         direction = "0 0 0";
         locked = "false";
         position = "0 0 120";
         scale = "1 1 1";
         rotation = "1 0 0 0";
   };
   new SimGroup(PlayerDropPoints) {

      new SpawnSphere() {
         position = "0 0 20";
         rotation = "0 0 1 130.062";
         scale = "0.940827 1.97505 1";
         dataBlock = "SpawnSphereMarker";
         canSetIFLs = "0";
         radius = "50";
         sphereWeight = "1";
         indoorWeight = "1";
         outdoorWeight = "1";
            RayHeight = "150";
      };
   };
   new InteriorInstance() {
      position = "500 400 0";
      rotation = "0 0 1 180";
      scale = "1 1 1";
      interiorFile = "./Lava.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
 
if($Pref::Worlds::Slate On)

new InteriorInstance() {
      position = "0 0 0";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      interiorFile = "~/Map_Slate/slate.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
};
//--- OBJECT WRITE END ---

Is the Map.add(%interior) a different kind of function? Does that automatically create the option under RTB Preferences?

More like this:

Code: [Select]
//--- OBJECT WRITE BEGIN ---
new SimGroup(MissionGroup) {

   new ScriptObject(MissionInfo) {
         saveName = "Worlds";
         name = "Worlds";
   };
   new MissionArea(MissionArea) {
      Area = "-360 -648 720 1296";
         locked = "true";
         flightCeiling = "300";
         flightCeilingRange = "20";
   };
   new Sky(Sky) {
      position = "336 136 0";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      materialList = "./astroskies/gal.dml";
      cloudHeightPer[0] = "0.349971";
      cloudHeightPer[1] = "0.3";
      cloudHeightPer[2] = "0.199973";
      cloudSpeed1 = "0.0005";
      cloudSpeed2 = "0.001";
      cloudSpeed3 = "0.0003";
      visibleDistance = "600";
      fogDistance = "2000";
      fogColor = "0.000000 0.000000 0.000000 1.000000";
      fogStorm1 = "0";
      fogStorm2 = "0";
      fogStorm3 = "0";
      fogVolume1 = "0 0 0";
      fogVolume2 = "0 0 0";
      fogVolume3 = "0 0 0";
      fogVolumeColor1 = "192.000000 128.000000 128.000000 -222768174765569860000000000000000000000.000000";
      fogVolumeColor2 = "128.000000 128.000000 128.000000 0.000000";
      fogVolumeColor3 = "128.000000 128.000000 128.000000 -170698929442160050000000000000000000000.000000";
      windVelocity = "1 1 0";
      windEffectPrecipitation = "1";
      SkySolidColor = "0.000000 0.000000 0.100000 1.000000";
      useSkyTextures = "1";
      renderBottomTexture = "1";
      noRenderBans = "1";
         locked = "true";
   };
   new Sun() {
      azimuth = "180";
      elevation = "90";
      color = "0.700000 0.650000 0.500000 1.000000";
      ambient = "0.300000 0.250000 0.200000 1.000000";
         direction = "0 0 0";
         locked = "false";
         position = "0 0 120";
         scale = "1 1 1";
         rotation = "1 0 0 0";
   };
   new SimGroup(PlayerDropPoints) {

      new SpawnSphere() {
         position = "0 0 20";
         rotation = "0 0 1 130.062";
         scale = "0.940827 1.97505 1";
         dataBlock = "SpawnSphereMarker";
         canSetIFLs = "0";
         radius = "50";
         sphereWeight = "1";
         indoorWeight = "1";
         outdoorWeight = "1";
            RayHeight = "150";
      };
   };
   new InteriorInstance() {
      position = "500 400 0";
      rotation = "0 0 1 180";
      scale = "1 1 1";
      interiorFile = "./Lava.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
};
//--- OBJECT WRITE END ---

if($Pref::Worlds::SlateOn)
{
    %interior = new InteriorInstance() {
          position = "0 0 0";
          rotation = "1 0 0 0";
          scale = "1 1 1";
          interiorFile = "~/Map_Slate/slate.dif";
          useGLLighting = "0";
          showTerrainInside = "0";
    };
    MissionGroup.add(%interior);
}

You'll still need to look at the RTB Documentation (http://returntoblockland.com/files/RTB_Documentation.pdf) to learn about how to register a pref for RTB. "Adding" the interior just adds it to the mission instead of having it floating around in oblivion.

Maps don't usually have a "server.cs" file, so is that something I just add to the main folder of the add_on?

Is this what I put in it?

Code: [Select]
RTB_registerPref(
"Slate On?",
"Worlds",
"$Worlds::SlateOn",
"bool",  //boolean?
"Map_Worlds",
"0",  //That means by default it is off?
1,
1, ); //host only?

I omitted the callback name as I don't think I need that.

That'd be fine. Put it at the bottom of the .mis - a .mis is exactly the same as a .cs file. You'll need to change the code to use $Worlds::SlateOn since you've registered that instead of $Pref::Worlds::SlateOn.

I tried it out, but no preference appears under the in the GUI. Is part of the code incorrect?

Code: [Select]
//--- OBJECT WRITE BEGIN ---
new SimGroup(MissionGroup) {

   new ScriptObject(MissionInfo) {
         saveName = "Worlds";
         name = "Worlds";
   };
   new MissionArea(MissionArea) {
      Area = "-360 -648 720 1296";
         flightCeilingRange = "20";
         locked = "true";
         flightCeiling = "300";
   };
   new Sky(Sky) {
      position = "336 136 0";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      materialList = "./astroskies/gal.dml";
      cloudHeightPer[0] = "0.349971";
      cloudHeightPer[1] = "0.3";
      cloudHeightPer[2] = "0.199973";
      cloudSpeed1 = "0.0005";
      cloudSpeed2 = "0.001";
      cloudSpeed3 = "0.0003";
      visibleDistance = "600";
      fogDistance = "2000";
      fogColor = "0.000000 0.000000 0.000000 1.000000";
      fogStorm1 = "0";
      fogStorm2 = "0";
      fogStorm3 = "0";
      fogVolume1 = "0 0 0";
      fogVolume2 = "0 0 0";
      fogVolume3 = "0 0 0";
      fogVolumeColor1 = "192.000000 128.000000 128.000000 -222768174765569860000000000000000000000.000000";
      fogVolumeColor2 = "128.000000 128.000000 128.000000 0.000000";
      fogVolumeColor3 = "128.000000 128.000000 128.000000 -170698929442160050000000000000000000000.000000";
      windVelocity = "1 1 0";
      windEffectPrecipitation = "1";
      SkySolidColor = "0.000000 0.000000 0.100000 1.000000";
      useSkyTextures = "1";
      renderBottomTexture = "1";
      noRenderBans = "1";
         locked = "true";
   };
   new Sun() {
      azimuth = "180";
      elevation = "90";
      color = "1.000000 1.000000 1.000000 1.000000";
      ambient = "0.300000 0.250000 0.200000 1.000000";
         direction = "0 0 0";
         locked = "false";
         position = "0 0 120";
         scale = "1 1 1";
         rotation = "1 0 0 0";
   };
   new SimGroup(PlayerDropPoints) {

      new SpawnSphere() {
         position = "0 0 20";
         rotation = "0 0 1 130.062";
         scale = "0.940827 1.97505 1";
         dataBlock = "SpawnSphereMarker";
         canSetIFLs = "0";
         radius = "50";
         sphereWeight = "1";
         indoorWeight = "1";
         outdoorWeight = "1";
            RayHeight = "150";
      };
   };
   new InteriorInstance() {
      position = "500 400 0";
      rotation = "0 0 1 180";
      scale = "1 1 1";
      interiorFile = "./Lava.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
   new InteriorInstance() {
      position = "0 0 0";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      interiorFile = "./Grass.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
   new InteriorInstance() {
      position = "500 -400 -50";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      interiorFile = "./Water.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
   new InteriorInstance() {
      position = "350 600 20";
      rotation = "0 0 -1 90";
      scale = "1 1 1";
      interiorFile = "./asteroid.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
   new InteriorInstance() {
      position = "391 527 52";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      interiorFile = "./asteroid2.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
   new InteriorInstance() {
      position = "311 522 19";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      interiorFile = "./asteroid3.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
   new InteriorInstance() {
      position = "330 515 30";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      interiorFile = "./asteroid2.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
   new InteriorInstance() {
      position = "331 506 10";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      interiorFile = "./asteroid2.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
   new InteriorInstance() {
      position = "414 630 69";
      rotation = "0 0 -1 90";
      scale = "1 1 1";
      interiorFile = "./asteroid3.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
   new InteriorInstance() {
      position = "366 607 77";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      interiorFile = "./asteroid2.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
   new InteriorInstance() {
      position = "-500 -400 0";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      interiorFile = "./Desert.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
   new InteriorInstance() {
      position = "600 -240 65";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      interiorFile = "./moon.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
   new InteriorInstance() {
      position = "-500 400 0";
      rotation = "0 0 1 90";
      scale = "1 1 1";
      interiorFile = "./snow.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
   new InteriorInstance() {
      position = "0 130 30";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      interiorFile = "./buildpad.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
   new InteriorInstance() {
      position = "0 -130 30";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      interiorFile = "./buildpad.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
   new InteriorInstance() {
      position = "130 0 30";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      interiorFile = "./buildpad.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
   new InteriorInstance() {
      position = "-130 0 30";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      interiorFile = "./buildpad.dif";
      useGLLighting = "0";
      showTerrainInside = "0";
   };
};
//--- OBJECT WRITE END ---

if($Pref::Worlds::SlateOn)
{
    %interior = new InteriorInstance() {
          position = "0 0 0";
          rotation = "1 0 0 0";
          scale = "1 1 1";
          interiorFile = "~/Map_Slate/slate.dif";
          useGLLighting = "0";
          showTerrainInside = "0";
    };
    MissionGroup.add(%interior);
}

RTB_registerPref(
"Slate On?",
"Worlds",
"$Pref::Worlds::SlateOn",
"bool",
"Map_Worlds",
"0",
1,
1, );
« Last Edit: September 25, 2010, 03:07:25 AM by Reactor Worker »

Syntax error at the end, you can't have:

Code: [Select]
, );

Thanks! It works now.

A side question; is it possible to include a save with the map?

Not really. You can hax it to write a save file into the save folder but that's pretty cheap and it won't go away when they remove the map.

What would I need to alter to use this with DTS shapes?

Specifically to work with shapes enabled through this kind of code...

Code: [Select]
datablock StaticShapeData(grassatmosphere)
{
   category = "Reactor_Worker";
   shapeFile = "Add-Ons/Map_Worlds/grassatmosphere.dts";
};

function grassatmosphere:: onAdd(%this,%obj)
{
   %obj.playThread(0,"ambient");
}

datablock StaticShapeData(lavaatmosphere)
{
   category = "Reactor_Worker";
   shapeFile = "Add-Ons/Map_Worlds/lavaatmosphere.dts";
};

function lavaatmosphere:: onAdd(%this,%obj)
{
   %obj.playThread(0,"ambient");
}

The code is just so that transparency works on the shapes.