Author Topic: Adding to the NESS.  (Read 415 times)

Legacy_SHOVA

  • Hero Member
  • *****
  • Posts: 893
  • Karma: +0/-0
Adding to the NESS.
« on: December 05, 2012, 03:02:14 pm »


                I am using the NESS system, and love it. However, when it comes to making a mod persistant, there is a funtion the NESS does not have, that I believe would make things much easier. Can new funtions be added to the NESS? What I am looking to add is Month to it. It already had day, and hour, So it should not be terriblly complicated.

Has anyone already done this? can you share your code?

Thanks!
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Adding to the NESS.
« Reply #1 on: December 05, 2012, 05:31:12 pm »


               Are you referring to NESS's GetReal... functions?

Or are you referring to the TAGs which determine at what time a creature spawns? If so... yes, this is possible, but I don't think I've implemented it yet. I am considering this though....

But anway, yes, functions and tags can be added to NESS. I've been tweaking it to serve my purposes without any bad side effects so far.
               
               

               
            

Legacy_SHOVA

  • Hero Member
  • *****
  • Posts: 893
  • Karma: +0/-0
Adding to the NESS.
« Reply #2 on: December 05, 2012, 06:05:50 pm »


               Yes, I am looking to add the TAG of Month, to the NESS.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Adding to the NESS.
« Reply #3 on: December 05, 2012, 07:09:21 pm »


               What version of NESS do you have? And have you made any changes to it?
               
               

               
            

Legacy_SHOVA

  • Hero Member
  • *****
  • Posts: 893
  • Karma: +0/-0
Adding to the NESS.
« Reply #4 on: December 05, 2012, 07:44:46 pm »


               I am running NESS 8.1, with nothing changed.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Adding to the NESS.
« Reply #5 on: December 05, 2012, 07:59:29 pm »


               Thats probably the same as 8.1.3.

As you know I am currently working on PRR and AI, but I should be able to get to this soon enough.
               
               

               
            

Legacy_SHOVA

  • Hero Member
  • *****
  • Posts: 893
  • Karma: +0/-0
Adding to the NESS.
« Reply #6 on: December 06, 2012, 03:09:25 am »


               I am using NESS 8.1.3.
It appears that I figured it out for myself!

I added the following lines, causing the existing ones to move down:
In the script: spawn_defaults
52     // MMn|Tn
53    // SpawnMonth
54    int nSpawnMonthStart = -1;
55    int nSpawnMonthEnd = -1;
233    SetLocalInt(oModule, "df_SpawnMonthStart", nSpawnMonthStart);
234    SetLocalInt(oModule, "df_SpawnMonthEnd", nSpawnMonthEnd);

And in spawn_Functions:

243 int dfSpawnMonthStart = GetLocalInt(oModule, "df_SpawnMonthStart");
244 int dfSpawnMonthEnd = GetLocalInt(oModule, "df_SpawnMonthEnd");
463    int nSpawnMonthStart = GetFlagValue(sSpawnName, "MM", dfSpawnMonthStart);
464    int nSpawnMonthEnd = GetSubFlagValue(sSpawnName, "MM", "T", dfSpawnMonthEnd);
465    if (nSpawnMonthStart > nSpawnMonthEnd)
466   {
467        nSpawnMonthEnd = -1;
468    }

474    SetLocalInt(oSpawn, "f_SpawnMonthStart", nSpawnMonthStart);
475    SetLocalInt(oSpawn, "f_SpawnMonthEnd", nSpawnMonthEnd);
1183// This Function Checks if nCheckMonth is Between Months
1184 int IsBetweenMonths(int nCheckMonth, int nMonthStart, int nMonthEnd)
1185{
1186    if (nMonthEnd > -1)
1187   {
1189        if (nCheckMonth >= nMonthStart && nCheckMonth <= nMonthEnd)
1190        {
1191            return TRUE;
1192        }
1193    }
1194    else
1195    {
1196        if (nCheckMonth == nMonthStart)
1197       {
1198            return TRUE;
1199        }
1200    }

1201   return FALSE;
1202}

3203  int nSpawnMonthStart = GetLocalInt(oSpawn, "f_SpawnMonthStart");
3204  int nSpawnMonthEnd = GetLocalInt(oSpawn, "f_SpawnMonthEnd");

3279   // Check Against Specific Month(s) (_MMnn_)
3278  if (nSpawnMonthStart > 12)
3279 {
3280      int nMonth = GetCalendarMonth();
3281      if (IsBetweenMonths(nMonth, nSpawnMonthStart, nSpawnMonthEnd) == FALSE)
3282      {
3283         nSpawnBlock = TRUE;
3284      }
3285  }
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Adding to the NESS.
« Reply #7 on: December 06, 2012, 02:53:09 pm »


               Good job, Shova. That looks about right, but I haven't tested it yet.
               
               

               
            

Legacy_SHOVA

  • Hero Member
  • *****
  • Posts: 893
  • Karma: +0/-0
Adding to the NESS.
« Reply #8 on: December 07, 2012, 04:24:41 pm »


               Continuing to test this in game, so far it works, In game it is winter, and only winter month spawns are spawning. Since my game time is set to 15 real minutes = 1 game hour, spring is a ways off.
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Adding to the NESS.
« Reply #9 on: January 04, 2013, 01:48:47 pm »


               SHOVA, you probably found the part missing from your above code already, but for those following along at home...

You need to add a section of code in spawn_main which calls isBetweenMonths similar to the one in spawn_functions.

Here is a complete patch which does the Month change from SHOVA including the minor fixes and documentation. It also adds the ability to have the hours wrap which is something I wanted. They just went in together. The hours change allows you to have a child spawn from say 22 to 02 of the next day, useful late night activities.

(let's see if this formatting works - if not and there is interest I can try something else)


diff --git a/spawn_functions.nss b/spawn_functions.nss
index 4f69ac9..c9f28fc 100644
--- a/spawn_functions.nss
+++ b/spawn_functions.nss
@@ -245,6 +245,8 @@ void InitFlags(object oSpawn, string sSpawnName, string sSpawnTag)
     int dfSpawnDayEnd = GetLocalInt(oModule, "df_SpawnDayEnd");
     int dfSpawnHourStart = GetLocalInt(oModule, "df_SpawnHourStart");
     int dfSpawnHourEnd = GetLocalInt(oModule, "df_SpawnHourEnd");
+    int dfSpawnMonthStart = GetLocalInt(oModule, "df_SpawnMonthStart");
+    int dfSpawnMonthEnd = GetLocalInt(oModule, "df_SpawnMonthEnd");
     int dfWanderRange = GetLocalInt(oModule, "df_WanderRange");
     int dfReturnHomeRange = GetLocalInt(oModule, "df_ReturnHomeRange");
     int dfPCCheckDelay = GetLocalInt(oModule, "df_PCCheckDelay");
@@ -451,22 +453,53 @@ void InitFlags(object oSpawn, string sSpawnName, string sSpawnTag)
     // Initialize Day/Hour Spawns
     int nSpawnDayStart = GetFlagValue(sSpawnName, "DY", dfSpawnDayStart);
     int nSpawnDayEnd = GetSubFlagValue(sSpawnName, "DY", "T", dfSpawnDayEnd);
+    if (nSpawnDayStart < 1 || nSpawnDayStart > 28) {
+        nSpawnDayStart = -1;
+    }
+    // TODO - day could be made to wrap into the next month
+    if (nSpawnDayEnd < 1 || nSpawnDayEnd > 28) {
+        nSpawnDayEnd = -1;
+    }
     if (nSpawnDayEnd > nSpawnDayStart)
     {
         nSpawnDayEnd = -1;
     }
+
     int nSpawnHourStart = GetFlagValue(sSpawnName, "HR", dfSpawnHourStart);
     int nSpawnHourEnd = GetSubFlagValue(sSpawnName, "HR", "T", dfSpawnHourEnd);
-    if (nSpawnHourStart > nSpawnHourEnd)
-    {
+    if (nSpawnHourStart < 0 || nSpawnHourStart > 23) {
+        nSpawnHourStart = -1;
+    }
+    if (nSpawnHourEnd < 0 || nSpawnHourEnd > 23) {
         nSpawnHourEnd = -1;
     }
+    // Hours now wrap so you can spwan between 22 and 2 and get 4 valid hours
+    //if (nSpawnHourStart > nSpawnHourEnd)
+    //f (nSpawnHourStart == nSpawnHourEnd)
+    //{
+    //    nSpawnHourEnd = -1;
+    //}
 
+    int nSpawnMonthStart = GetFlagValue(sSpawnName, "MM", dfSpawnMonthStart);
+    int nSpawnMonthEnd = GetSubFlagValue(sSpawnName, "MM", "T", dfSpawnMonthEnd);
+    if (nSpawnMonthStart < 1 || nSpawnMonthStart > 12) {
+        nSpawnMonthStart = -1;
+    }
+    if (nSpawnMonthEnd < 1 || nSpawnMonthEnd > 12) {
+        nSpawnMonthEnd = -1;
+    }
+    // TODO - month > 12 could wrap to next year
+    if (nSpawnMonthStart > nSpawnMonthEnd)
+    {
+        nSpawnMonthEnd = -1;
+    }
     // Record Day/Hour Spawns
     SetLocalInt(oSpawn, "f_SpawnDayStart", nSpawnDayStart);
     SetLocalInt(oSpawn, "f_SpawnDayEnd", nSpawnDayEnd);
     SetLocalInt(oSpawn, "f_SpawnHourStart", nSpawnHourStart);
     SetLocalInt(oSpawn, "f_SpawnHourEnd", nSpawnHourEnd);
+    SetLocalInt(oSpawn, "f_SpawnMonthStart", nSpawnMonthStart);
+    SetLocalInt(oSpawn, "f_SpawnMonthEnd", nSpawnMonthEnd);
 
     // Initialize RandomWalk
     int nRandomWalk = IsFlagPresent(sSpawnName, "RW");
@@ -1160,7 +1193,11 @@ int IsBetweenHours(int nCheckHour, int nHourStart, int nHourEnd)
 {
     if (nHourEnd > -1)
     {
-        if (nCheckHour >= nHourStart && nCheckHour <= nHourEnd)
+        if (nHourStart > nHourEnd) {
+            if (nCheckHour >= nHourStart || nCheckHour <= nHourEnd)
+                return TRUE;
+        }
+        else if (nCheckHour >= nHourStart && nCheckHour <= nHourEnd)
         {
             return TRUE;
         }
@@ -1176,6 +1213,26 @@ int IsBetweenHours(int nCheckHour, int nHourStart, int nHourEnd)
     return FALSE;
 }
 //
+// This Function Checks if nCheckMonth is Between Months
+int IsBetweenMonths(int nCheckMonth, int nMonthStart, int nMonthEnd) {
+    if (nMonthEnd > -1)
+    {
+        if (nCheckMonth >= nMonthStart && nCheckMonth <= nMonthEnd)
+        {
+            return TRUE;
+        }
+    }
+    else
+    {
+        if (nCheckMonth == nMonthStart)
+        {
+            return TRUE;
+        }
+    }
+
+    return FALSE;
+}
+
 
 // This Function Pads an IntToString with 0s
 string PadIntToString(int nInt, int nDigits)
@@ -3174,6 +3231,8 @@ int IsRestoreBlocked(object oSpawn, location lChildLoc, int iExpireTime,
   int nSpawnDayEnd = GetLocalInt(oSpawn, "f_SpawnDayEnd");
   int nSpawnHourStart = GetLocalInt(oSpawn, "f_SpawnHourStart");
   int nSpawnHourEnd = GetLocalInt(oSpawn, "f_SpawnHourEnd");
+  int nSpawnMonthStart = GetLocalInt(oSpawn, "f_SpawnMonthStart");
+  int nSpawnMonthEnd = GetLocalInt(oSpawn, "f_SpawnMonthEnd");
 
   // Initialize Child Lifespan
   int nChildLifespanMax = GetLocalInt(oSpawn, "f_ChildLifespanMax");
@@ -3247,6 +3306,16 @@ int IsRestoreBlocked(object oSpawn, location lChildLoc, int iExpireTime,
       }
   }
 
+  // Check Against Specific Month(s) (_MMnn_)
+  if (nSpawnMonthStart > -1)
+  {
+      int nMonth = GetCalendarMonth();
+      if (IsBetweenMonths(nMonth, nSpawnMonthStart, nSpawnMonthEnd) == FALSE)
+      {
+          nSpawnBlock = TRUE;
+      }
+  }
+
   // Check Lifespan (_CLnn_)
   if (nChildLifespanMax > -1)
   {
diff --git a/spawn_defaults.nss b/spawn_defaults.nss
index 2ed14b7..78d98eb 100644
--- a/spawn_defaults.nss
+++ b/spawn_defaults.nss
@@ -49,6 +49,11 @@ int nSpawnDayEnd = -1;
 int nSpawnHourStart = -1;
 int nSpawnHourEnd = -1;
 
+// MMn|Tn
+// SpawnMonth
+int nSpawnMonthStart = -1;
+int nSpawnMonthEnd = -1;
+
 // RW|Rn
 // RandomWalk
 int nWanderRange = 0;
@@ -225,6 +230,8 @@ void SetGlobalDefaults()
     SetLocalInt(oModule, "df_SpawnDayEnd", nSpawnDayEnd);
     SetLocalInt(oModule, "df_SpawnHourStart", nSpawnHourStart);
     SetLocalInt(oModule, "df_SpawnHourEnd", nSpawnHourEnd);
+    SetLocalInt(oModule, "df_SpawnMonthStart", nSpawnMonthStart);
+    SetLocalInt(oModule, "df_SpawnMonthEnd", nSpawnMonthEnd);
     SetLocalInt(oModule, "df_WanderRange", nWanderRange);
     SetLocalInt(oModule, "df_ReturnHomeRange", nReturnHomeRange);
     SetLocalInt(oModule, "df_PCCheckDelay", nPCCheckDelay);
diff --git a/spawn__readme.nss b/spawn__readme.nss
index dd92e77..e69d094 100644
--- a/spawn__readme.nss
+++ b/spawn__readme.nss
@@ -191,7 +191,16 @@
 //   : Children are Despawned during Invalid Hours
 //   : Optional Flag: T00
 //   :  Spawn from Hour HR00 to Hour T00
+//   : Hours may wrap (e.g. HR22T02 will spawn from 10pm to 2 am of the next day)
+//   : Interactions with DYXX flags may be interesting
 //
+//   MMn|Tn
+//   : Spawn Month
+//   : Spawn Only during Month MM01 to MM12
+//   : Children are Despawned during Invalid Months
+//   : Optional Flag: T00
+//   :  Spawn from Month MMXX to Month TXX
+///
 //   DO|D
 //   : Day Only
 //   : Only Spawns at Day

               
               

               
            

Legacy_Sir Adril

  • Jr. Member
  • **
  • Posts: 96
  • Karma: +0/-0
Adding to the NESS.
« Reply #10 on: January 09, 2013, 11:47:54 pm »


               That's really cool. Any objections if I utilize that in my own module?
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Adding to the NESS.
« Reply #11 on: January 10, 2013, 02:04:56 am »


               No objections on my part. Please use it. That's why I posted it '<img'>