Author Sticky: Post Working Scripts Here
Northernshadows Posted: Wednesday, 03 July 09:02PM
Hello, its another NWN scripting newbie here... here's the first script I'm really satisfied with, and that might prove useful to someone else.

The issue of scripting sitting people has been almost done to death I guess, but here's one more of those: a mass-sitting sript. This is for one of those areas where you mostly need static people, sitting and staring into their drinks. A way-inn where players spend only a short time, for example.

This is placed into area's OnEnter. No need to create custom OnSpawns for each NPC just to have them sit down. Just insert the tags of NPCs and chairs into string 'SitString', separate with commas, and let the magic happen. Look at the example to see how its done.

The chairs, naturally, need the generic scrip that allows them to be sat upon. I've included it at the bottom just in case.

NWScript:
//:////

//

// A generic script to sit down a bunch of creatures. Place this to

// area's OnEnter - no more hassle with custom onSpawns just to have

// a character sit. ^_^

//

//:////

//

// The string SitString is a comma-separated list alternating the tagnames

// of characters to sit and chairs they will sit upon. See the code for

// a short example.

//

//:////

//

// Scripted by Northernshadows on 3.7.2002, version 1.0

//

//:////



void main()

{

   string SitString = "npc_01,chair_01,elf_mage,stool_10";

   int Pos = 0;

   int Pos_prev = 0;

   int Length = GetStringLength (SitString);

   string This_pos = "";

   string Npc = "";

   string Chair = "";

   while (Pos < Length) {

      This_pos = GetSubString (SitString, Pos, 1);

      if (This_pos == "," && Npc == "")

      {

         Npc = GetSubString (SitString, Pos_prev, (Pos - Pos_prev));

         Pos_prev = Pos+1;

      }

      else if (This_pos == "," && Chair == "" || Pos == Length -1)

      {

         if (Pos != Length -1) Chair = GetSubString (SitString, Pos_prev, (Pos - Pos_prev));

         if (Pos == Length -1) Chair = GetSubString (SitString, Pos_prev, (Pos - Pos_prev)+1);

         Pos_prev = Pos+1;

      }

      if (Npc != "" && Chair != "") {

         AssignCommand (GetObjectByTag (Npc), ActionInteractObject (GetObjectByTag (Chair)));

         Npc = "";

         Chair = "";

      }

      Pos++;

   }

}



NWScript:
// Generic sittable chair script

void main()

{

   object oChair = OBJECT_SELF;

   if (GetIsObjectValid(oChair) && !GetIsObjectValid (GetSittingCreature (oChair))) AssignCommand (GetLastUsedBy(), ActionSit(oChair));

}