So simple and yet


#1

I was trying to make a script that will spawn a guard captain in the barracks in the daytime. It wasn’t working so I stripped it down to where it should spawn the captain when the PC enters the barracks regardless of time. Still doesn’t work! It’s such a simple script I can’t figure out why it isn’t working. I have double checked the tags of the captain and the spawn waypoint, they are correct. Any ideas?

void main()
{
int nObjectType = OBJECT_TYPE_CREATURE;
string sCaptain = “manuskess”;
location lTarget = GetLocation(GetWaypointByTag(“MANUS_DAY”));
int bUseAppearAnimation = FALSE;
int iTime = GetTimeHour();
int iIsPC = GetIsPC(GetEnteringObject());
if(iIsPC)
{
SpawnScriptDebugger();
PrintString(“Running manus day spawn”);
PrintInteger(iTime);
CreateObject(nObjectType, sCaptain, lTarget, bUseAppearAnimation);

}

}

I added the debug code to try to figure it out and it prints the string and time to the log so it’s running, it just doesn’t create the captain.


#2

Double check that the waypoint tag is correct and the resref for the captain is correct. If they are try this modified version of your code.

void main()
{
	location lTarget = GetLocation(GetWaypointByTag("MANUS_DAY"));
	int iTime = GetTimeHour();
	int iIsPC = GetIsPC(GetEnteringObject());
	object oCaptain;

	if(iIsPC)
	{
//		SpawnScriptDebugger();
		PrintString("Running manus day spawn");
		PrintInteger(iTime);

		oCaptain = CreateObject(OBJECT_TYPE_CREATURE, "manuskess", lTarget, FALSE);

		if(oCaptain == OBJECT_INVALID)
			PrintString("Problem with CreateObject");
	}
}

When you run it, does the “Problem with CreateObject” text show up in your log file?

BTW Please look at this stickied thread. Unless you mark your code as code the forum software “prettifies” quotation marks. This in turn means that your code has to be fixed before it will run correctly in NwN.

TR


#3

Good idea but I had it too. I tried this and got no error message so the object is valid. I triple checked the tags too. I have no idea why it doesn’t work.


#4

In that case how many areas have you got? Make sure that you haven’t accidentally given more than one waypoint that tag. I would also check what if any script runs in the captains OnSpawn script too.

TR


#5

Definitely a unique tag, and captain has only the default nwn scripts so far. Going to try changing the tag to some other creature to see if it spawns ok, we will see…


#6

You mention the creature “tag”. You need to use its resref, which is not the same thing.


#7

This is a good point, I wish it was the answer. I have in the past gotten the two confused so I make it a habit to match my tags and resrefs. In this case they are both “manuskess” for example. I did try the script with my town dog, spot, and he spawns so something is up with the captain. I’ll mess with it some more, see if I can figure it out. Thanks.


#8

Ok when I tested with spot I just commented out a line and added a new one. I just went in and left the original line commented out and changed the resref from spot to manuskess and the damn thing works. Am I crazy, can anyone see a difference in these two lines besides the commenting out?

// string sCaptain = “manuskess”;
string sCaptain = “manuskess”;


#9

I can’t see any difference (as rendered on this webpage) but in nwscript the first line might contain a non-printing character, perhaps?

One way to check would be to open the .nss file in Notepad++ then View > Show Symbol > Show All Characters.


#10

I guess it doesn’t really matter since its fixed but I am curious. I did a copy paste from the resref to make sure I got it right, something could have gone awry there. I’ll try that, thanks.


#11

No need to open the whole file in notepad++ (hereafter referred to as npp). Instead open a new document in npp Copy the offending line and paste into npp removing the ‘//’. Highlight that line and from the menu select Edit/Blank Operations/TAB to Space. Then cut that line from npp and paste it back into position in your script. Finally comment out the working version. See if that runs.

In my experience the NWScript compiler doesn’t like TABs although it will often compile without complaint.

TR


#12

Everything looked fine in notepad++ so no idea what was up but hey it works now. I added the rest of the code to only spawn the captain from dawn to dusk in the barracks and it works great. I did have to add an onexit script to despawn him so if the player enters, exits, then enters again there won’t be multiple captains running around my barracks. This is the finished script if anyone is curious.

void main()
{
int nObjectType = OBJECT_TYPE_CREATURE;
string sCaptain = “manuskess”;
location lTarget = GetLocation(GetWaypointByTag(“MANUS_DAY”));
int bUseAppearAnimation = FALSE;
object oCaptain;
int iTime = GetTimeHour();
int iIsPC = GetIsPC(GetEnteringObject());
if(iIsPC)
{
if(iTime >= 6 && iTime < 18)
CreateObject(nObjectType, sCaptain, lTarget, bUseAppearAnimation);
else
{
oCaptain = GetObjectByTag(sCaptain);
if(oCaptain != OBJECT_INVALID)
DestroyObject(oCaptain);
}
}
}

I made a near identical one for his house that only spawns him at night, so Captain Manus doesn’t have to be on duty 24/7 anymore. Thanks for the input everyone.