Envzones + player persistence.

Author Topic: Envzones + player persistence.  (Read 2260 times)

https://forum.blockland.us/index.php?topic=308861.0

So when creating a persistent zone they do not stay persistent when you log out and log back in even with the default persistence support.

I brought this to Zeblote's attention but he's busy.

I'm not familiar with persistence to edit it myself, is anyone able to allow persistent zones to stay persistent with the persistence support?


I'd do it myself but I'm not familiar with how this works.

I mean, seeing as the author Zeblote is busy, anyone who wants to make significant changes to this mod has to go through the tedious process of learning the code and how it works. This is one of the most annoying processes of modding, so I personally doubt that you will find someone to do it for you.

If you have specific questions about sections of the code or how/why something works then I'd be glad to help however.

Looks like Zeb wrote his own persistence support for this mod instead of using the default persistence support add-on.

After /setEnvZonePersistent Zone Name make sure you /saveEnvZones Save Name
When loading saved zones use /loadEnvZones Save Name

Not sure why Zeb didn't make zones "autoSave" after being set to persistent, but oh well.

Looks like Zeb wrote his own persistence support for this mod instead of using the default persistence support add-on.

After /setEnvZonePersistent Zone Name make sure you /saveEnvZones Save Name
When loading saved zones use /loadEnvZones Save Name

Not sure why Zeb didn't make zones "autoSave" after being set to persistent, but oh well.

Any idea how to fix it?

Any idea how to fix it?
It should already work? Just make sure you save and load the zones respectively

Looks like Zeb wrote his own persistence support for this mod instead of using the default persistence support add-on.

After /setEnvZonePersistent Zone Name make sure you /saveEnvZones Save Name
When loading saved zones use /loadEnvZones Save Name

Not sure why Zeb didn't make zones "autoSave" after being set to persistent, but oh well.
I have a feeling you're misunderstanding the request.

He wants the environment the client is seeing to be persistent, even if they leave and rejoin.

He wants the environment the client is seeing to be persistent, even if they leave and rejoin.

Correct

I have a feeling you're misunderstanding the request.

He wants the environment the client is seeing to be persistent, even if they leave and rejoin.
Oh, woops! Thanks for the clarification. Here is a quick code that should load client environments after the player spawns (using default player persistence) copy and paste this code to the manager.cs

Quote from: manager.cs
   function GameConnection::autoAdminCheck(%this)
   {
      //Check for persistence
      if(isFunction(RegisterPersistenceVar))
      {
         RegisterPersistenceVar("currentEnvironment", false, "");
       }
    }

   function GameConnection::applyPersistence(%client, %gotPlayer, %gotCamera)
    {   
        setupDefaultEnvironment();
        %client.popAllEnvironments();
        %client.setEnvironment(%client.currentEnvironment);
      
      return Parent::applyPersistence(%client, %gotPlayer, %gotCamera);
    }
Alternatively if you do not want to copy the code you can just download the modified .cs attached and replace it with the current one in Server_EnvironmentZones/script

If you haven't already, make sure to enable Script_PlayerPersistence before starting the server.

This should work, although I haven't tested so please let me know

Cool thanks, I'll test it out and let you know.

One problem I can see with that is if the server restarts. The environments are going to have different object IDs when that happens, which can cause some problems.
It would be harder to do, but I think you'd end up having to store all the data about the environment rather than just the object id itself.

One problem I can see with that is if the server restarts. The environments are going to have different object IDs when that happens, which can cause some problems.
It would be harder to do, but I think you'd end up having to store all the data about the environment rather than just the object id itself.
Oh, I see....I thought saving/loading the zones corrected the ID's ?

Quote from: manager.cs
function loadEnvironmentZones(%filename)
{
   // Read all environment zones from a file
   deleteAllEnvZones();

   %file = new FileObject();
   if(!%file.openForRead(%filename))
      return false;

   // If we get a bad number here, it's likely not a zone file
   %num = %file.readLine() * 1;
   if(!%num || %num > 1000)
   {
      messageAll('', "\c0ERROR: Bad number of zones in file.");
      return false;
   }

   messageAll('', "\c6Loading " @ %num @ " environment zones...");
   
   while(!%file.isEOF())
   {
      // Each zone block should start with "ZONE: name"
      %line = %file.readLine();
      if(firstWord(%line) !$= "ZONE:")
      {
         messageAll('', "\c0ERROR: Missing zone start marker.");
         deleteAllEnvZones();
         return false;
      }
      %name = getSubStr(%line, 6, 999);
      if(!strLen(%name))
      {
         messageAll('', "\c0ERROR: Missing zone name.");
         deleteAllEnvZones();
         return false;
      }

      %persistent = !!%file.readLine();
      %line = %file.readLine();
      %point1 = getField(%line, 0);
      %point2 = getField(%line, 1);

      messageAll('', "\c6Loading zone \"" @ %name @ "\".");
      %zone = EnvironmentZone(%name);
      %zone.setSize(%point1, %point2);
      %zone.persistent = %persistent;
      %zone.updateShapeName();
      %skipping = false;

      while(!%file.isEOF() && strLen(%line = %file.readLine()))
      {
         if(%skipping)
            continue;

         %var = getField(%line, 0);
         %value = getField(%line, 1);

         if(%var $= "SimpleMode" && %value == 1)
         {
            // Skip all the advanced settings that follow.
            // Support for broken environments from v1.0
            %skipping = true;
         }

         // Resource ids change between restarts, so find the correct ones
         switch$(%var)
         {
            case "File_Ground":
               %var = "GroundIdx";
               %value = getEnvironmentFileIdx("Ground", %value);
            case "File_Sky":
               %var = "SkyIdx";
               %value = getEnvironmentFileIdx("Sky", %value);
            case "File_Water":
               %var = "WaterIdx";
               %value = getEnvironmentFileIdx("Water", %value);
            case "File_DayCycle":
               %var = "DayCycleIdx";
               %value = getEnvironmentFileIdx("DayCycle", %value);
            case "File_SunFlareBottom":
               %var = "SunFlareBottomIdx";
               %value = getEnvironmentFileIdx("SunFlare", %value);
            case "File_SunFlareTop":
               %var = "SunFlareTopIdx";
               %value = getEnvironmentFileIdx("SunFlare", %value);
         }

         setEnvVariable(%var, %value);
      }

      %zone.environment.postEditCheck();
   }

   %file.delete();
   return true;
}
« Last Edit: April 23, 2018, 03:23:53 PM by Goth77 »

Those are the IDs of assets stored within the environment object itself, not the ID of the environment object.

Oh, I see....I thought saving/loading the zones corrected the ID's ?


Is that code completed?