Author Topic: Transitioning with a summons crashes server  (Read 544 times)

Legacy_Tassie Wombat

  • Jr. Member
  • **
  • Posts: 78
  • Karma: +0/-0
Transitioning with a summons crashes server
« on: March 24, 2011, 01:52:04 am »


               I am having trouble with my server crashing when PC's transition with a summons.   I have narrowed it down to my area cleanup script.   Can someone please point out to me what I've done wrong with my script? 

The script is supposed to destroy leftover encounter creatures and reset the encounters.   I don't want to touch loot bags or placeables.

void main()
{
    object oTarget = GetFirstObjectInArea();
    object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, oTarget);

    if (GetIsObjectValid(oPC) == TRUE) return;

    while (GetIsObjectValid(oTarget) == TRUE)
    {
        if (GetIsEncounterCreature(oTarget) == TRUE)
        {
            DestroyObject(oTarget);
        }
        if (GetObjectType(oTarget) == OBJECT_TYPE_ENCOUNTER)
        {
            SetEncounterActive(TRUE, oTarget);
        }
        oTarget = GetNextObjectInArea();
    }
}
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Transitioning with a summons crashes server
« Reply #1 on: March 24, 2011, 02:24:22 am »


               I can see only one error now and thats:

    object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, oTarget);

since some patch probably 1.69 this behaves differently than it used to, in past this returned any PC dead or alive but now this line acts as you would set the second parameter to IS_ALIVE and TRUE

to be sure that there is nobody in area you must also try is there is any dead PC using IS_ALIVE and FALSE in second parameter

but i dont know if this fixes your crashing problem, I didnt even though its possible to crash a server via nwscript anymore...
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Transitioning with a summons crashes server
« Reply #2 on: March 24, 2011, 02:43:45 am »


               The only thing I see is that there is no check to see if the exiting object is a PC.  Therefore when the PC leaves the area with his summons it may be trying to destroy the encounter creatures twice.  There is a small delay from the time the scripts finishes running and the destruction of te encounter creatures.  And the PC and summons are leaving at the same time.  

A check will not hurt even if it is not what is causing your crash.  The way the script is currently written it is checking for a clean every time you kill a creature in the area.  It is a total waste of cpu time.
               
               

               
            

Legacy_Tassie Wombat

  • Jr. Member
  • **
  • Posts: 78
  • Karma: +0/-0
Transitioning with a summons crashes server
« Reply #3 on: March 24, 2011, 03:09:19 am »


               Thanks for the responses.  Lightfoot8 I completely missed that I had removed the check for oPC being the exiting object ... that's what I get for cobbling several scripts together at 2am.

Is this version any better?

void main()
{
   object oExiting = GetExitingObject();
   object oTarget = GetFirstObjectInArea();

   if (GetIsPC(oExiting))
   {
       while (GetIsObjectValid(oTarget) == TRUE)
       {
           if (GetIsPC(oTarget))
           {
               return;
           }

           if (GetIsEncounterCreature(oTarget) == TRUE)
           {
               DestroyObject(oTarget);
           }

           if (GetObjectType(oTarget) == OBJECT_TYPE_ENCOUNTER)
           {
               SetEncounterActive(TRUE, oTarget);
           }
       }
       oTarget = GetNextObjectInArea();
   }
}
               
               

               
            

Legacy_Tassie Wombat

  • Jr. Member
  • **
  • Posts: 78
  • Karma: +0/-0
Transitioning with a summons crashes server
« Reply #4 on: March 24, 2011, 03:11:18 am »


               

ShaDoOoW wrote...
I didnt even though its possible to crash a server via nwscript anymore...


Nice to know I can achieve the impossible :innocent:
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Transitioning with a summons crashes server
« Reply #5 on: March 24, 2011, 04:36:26 am »


               

Tassie Wombat wrote...

Thanks for the responses. Lightfoot8 I completely missed that I had removed the check for oPC being the exiting object ... that's what I get for cobbling several scripts together at 2am.

Is this version any better?

void main()
{
  object oExiting = GetExitingObject();
  object oTarget = GetFirstObjectInArea();

  if (GetIsPC(oExiting))
  {
     while (GetIsObjectValid(oTarget) == TRUE)
     {
         if (GetIsPC(oTarget))
         {
              return;
         }

          if (GetIsEncounterCreature(oTarget) == TRUE)
         {
                DestroyObject(oTarget);
         }

         if (GetObjectType(oTarget) == OBJECT_TYPE_ENCOUNTER)
         {
               SetEncounterActive(TRUE, oTarget);
         }
    }
    oTarget = GetNextObjectInArea();
  }
}



Nope, That one is worse. 

You will get a TMI error when the script runs.  The changing of oTarget is out side of the while loop.
It will destroy encounter creatures untill it hits a PC even if the oTarget is inside of the loop.  You need to verify that a PC is not in the area before you start destroying any creatures.
               
               

               
            

Legacy_Tassie Wombat

  • Jr. Member
  • **
  • Posts: 78
  • Karma: +0/-0
Transitioning with a summons crashes server
« Reply #6 on: March 24, 2011, 05:35:17 am »


               Thanks for the help guys, unfortunately I think this one is just over my head for now.  
Finally managed to find a script on the old forums by Axe Murderer.   I'll stick that in and give it a whirl.   If everything suddenly works perfectly fine (as I suspect it now will) then I will pull the script apart line by line and figure out how it's done.

Again, thank you for your help.