Sd dynamic rooms and sd dynamic exit
From NWNWiki
sd_dynamic_rooms and sd_dynamic_exit allows a builder to create one area as a template. Then, just by naming the door and attaching the first script, it will load predefined objects into the room, and delete them when the player exits. It basically allows an infinite amount of areas to be created in the one area. The idea was to make the multiple houses in a town easier to use, but still able to have different characters and objects in the house without creating 10 or 20 areas.
Contents |
[edit] Area and Door Requirements
- An area must be created. Since the door's tag has to have the area's name in it, I suggest very simple, short names... "House" or "Cave" or "Blagh", etc.
- The area must have 5 waypoints called "general_spawn1" to "general_spawn5".
- The door must have the "Area Transition" option under the "Area Transition" tab set to "Door". Leave the "Destination Tag" box empty, however.
- The door must have the "sd_dynamic_exit" script attached to the "OnAreaTransitionClick" on the Script tab.
[edit] Entrance to the Area Door and Door Naming
- The door must have the "Area Transition" option under the "Area Transition" tab set to "Door". Leave the "Destination Tag" box empty, however.
- The door's name must be as follows:
- Example: If your area was called "House", the door's tag must start with "House_"
- Now you need to put the ResRef of each object or NPC that you want to be created when the player enters the room.
- Now set the door's "OnAreaTransitionClick" to the "sd_dynamic_rooms" script.
[edit] Extra Options
- If you want an NPC or object to spawn in a specific spot, create a waypoint named "<npc ResRef>_spawn"
- Example: "sylvia_spawn" and "Sylvia Cross" will be at that waypoint when she is created.
[edit] Trouble Shooting
IF the script is NOT working, check these things:
- Make sure the NPC or object being added has the EXACT same ResRef and tag! They must also be the same (including case-sensitivity) as the reference in the door's name!
- Example: *House_sylvia_ted_bob_Zilla* will load the Area named "House" and load the object with a ResRef of "sylvia", "ted", "bob" and "Zilla" to random (or specified) locations! It will also LOAD objects with ResRefs of "Sylvia", "Ted", "Bob", "ZiLLA", etc., but it will NOT remove "Sylvia" or "Ted" or "Bob" or "ZiLLA" as their tags, only the objects with tags "sylvia" "ted" "bob" "zilla".
[edit] The Scripts
[edit] sd_dynamic rooms
Save this as "sd_dynamic_rooms" and attach it to the door that enters into the room.
/*
.---------------------------------------------------------.
| Neverwinter Nights Room Generator |
|---------------------------------------------------------|
| Author: Skye Darkangel |
| Date: 8/14/2002 |
| Purpose: Easy to create and reuse a single room temp- |
| late to spawn a cities worth of inside houses. |
'---------------------------------------------------------'
*/
void main()
{
/* Get the door and it's Tag. */
string sFullString = GetTag(OBJECT_SELF);
object oPC = GetClickingObject();
/* Set the counter for parsing the string, and the */
/* Length of the string to be parsed. */
SetLocalInt(OBJECT_SELF, "counter", 0);
SetLocalInt(OBJECT_SELF, "length", GetStringLength(sFullString));
/* Get the first character into the subString vari- */
/* able and declare the roomTemplate variable. */
string subString = GetSubString(sFullString,(GetLocalInt(OBJECT_SELF,"counter")),1);
string sRoomTemplate;
/* Now read in the second part, which is the room's */
/* templates name. */
while(subString != "_" && GetLocalInt(OBJECT_SELF,"counter") < GetStringLength(sFullString))
{
sRoomTemplate = sRoomTemplate + subString;
SetLocalInt(OBJECT_SELF, "counter", (GetLocalInt(OBJECT_SELF,"counter")+1));
subString = GetSubString(sFullString,(GetLocalInt(OBJECT_SELF,"counter")),1);
}
/* Now grab the remainer, which is the identifier */
/* for the objects to be spawned in this new room. */
//int lengthIn = GetLocalInt(OBJECT_SELF,"counter");
//string sCustomTag = GetSubString(sFullString, (lengthIn + 1), (GetLocalInt(OBJECT_SELF,"length")-lengthIn));
/* Load all of the possible Objects to add to the */
/* room template. */
string sHabitant;
int i;
for(i = 1; subString == "_"; i++)
{
SetLocalInt(OBJECT_SELF, "counter", (GetLocalInt(OBJECT_SELF,"counter")+1));
subString = GetSubString(sFullString,(GetLocalInt(OBJECT_SELF,"counter")),1);
while(subString != "_" && GetLocalInt(OBJECT_SELF,"counter") < GetStringLength(sFullString))
{
sHabitant = sHabitant + subString;
SetLocalInt(OBJECT_SELF, "counter", (GetLocalInt(OBJECT_SELF,"counter")+1));
subString = GetSubString(sFullString,(GetLocalInt(OBJECT_SELF,"counter")),1);
}
SetLocalString(oPC,("npc" + IntToString(i)), sHabitant);
sHabitant = "";
}
/* Get your current location so you can get back! */
SetLocalLocation(oPC, "entrance", GetLocation(OBJECT_SELF));
/* Get the next location necessary to load at. */
object oTarget = GetObjectByTag((sRoomTemplate + "_entrance"));
location lTarget = GetLocation(oTarget);
/* Force a move to that location. */
AssignCommand(oPC,ActionJumpToLocation(lTarget));
/* Now create each object loaded onto the player at */
/* either the created location, or at a random one. */
for(i = 1; GetLocalString(oPC,("npc" + IntToString(i))) != ""; i++)
{
location lSpawn;
object oSpawnPoint = GetWaypointByTag(GetLocalString(oPC,("npc" + IntToString(i))) + "_spawn");
if(oSpawnPoint != OBJECT_INVALID)
{
lSpawn = GetLocation(GetWaypointByTag(GetLocalString(oPC,("npc" + IntToString(i))) + "_spawn"));
}
else
{
lSpawn = GetLocation(GetWaypointByTag("general_spawn" + IntToString(Random(4)+1)));
}
object oTemp = CreateObject(OBJECT_TYPE_CREATURE, GetLocalString(oPC,("npc" + IntToString(i))), lSpawn);
}
}
[edit] sd_dynamic_exit
Save this one as "sd_dynamic_exit" and attach it to the door in the area that's being used as a Template.
/*
.---------------------------------------------------------.
| Neverwinter Nights Room Generator Exit Script |
|---------------------------------------------------------|
| Author: Skye Darkangel |
| Date: 8/14/2002 |
| Purpose: Easy to create and reuse a single room temp- |
| late to spawn a cities worth of inside houses. |
'---------------------------------------------------------'
*/
void main()
{
/* Get the door and it's Tag. */
/* Get the player, and then where he entered from. */
object oClicker = GetClickingObject();
location lEntrance = GetLocalLocation(oClicker,"entrance");
/* Now remove all the objects we added upon entering */
/* the room! */
int i;
object oToDelete;
for(i = 1; GetLocalString(oClicker,("npc" + IntToString(i))) != ""; i++)
{
oToDelete = GetNearestObjectByTag(GetLocalString(oClicker,("npc" + IntToString(i))));
DestroyObject(oToDelete);
}
/* Send the player back to where he entered from */
AssignCommand(oClicker,ActionJumpToLocation(lEntrance));
}
