Sittable chairs & Sitting on the ground - help with scripting

Yep! That’s sit chair problem stage two … :slight_smile:

I had that for many a time … it is normally caused by a ClearAction call and a call to sit before the PCs reach their destination. Reminder: Make sure chairs are walkable too.

And do let me know if that script does help.

Cheers, Lance.

Tried your script and now we’re getting somewhere. Now everyone is sitting down except one character. But it’s the same character every time, and he seems stuck in a loop walking trying to get to the chair it seems, even if it’s right where he is.Two of the characters are sitting beside their chairs. Many of the NPCs face the wrong way. What I still like about this is that it is consistent. I tried reentering a few times and it’s always the same result exactly.

Hi andgalf,

OK, some of these issues may be because the chair is already “occupied” by another PC, even though we think it is fine. (Iirc anyway.)

Try un-commenting some of my comments, although you will need to put your own debug function call in there as that is one of my own functions.

Keep me updated … I’m just trying to sort one of my own at the moment. :slight_smile:

Cheers, Lance.

Ok. After poking around a lot last night I just made everything worse so I got back to an earlier version of the area and started anew. It seems that the ActionJumpToLocation doesn’t really work in this instance. Now I have a version of the script and the area that works most of the time. I guess I will just have to settle for that. I’m going crazy over this and how buggy and timing sensitive this whole game is. It’s driving me nuts. I found another sitting script among my scripts that I don’t know where it came from. I copied a line from there and that is the best solution yet. As I said, it works most of the time now. This is your somewhat modified script I’m using now (the code as usual looks like crap 'cause I can’t remember what kevL_s told me to do to make it appear so that a normal person can read this code here on the forums, the tabs are just nuts. I tried correcting it in Notepad++ but when it looks fine there and in the toolset it, as usual, looks like crap here):

void ActionPlayCustomAnimation(object oObject, string sAnimationName, int nLooping, float fSpeed = 1.0f)
{
PlayCustomAnimation(oObject, sAnimationName, nLooping, fSpeed);
}

// float GetNormalizedDirection(float fDirection):
// * This script returns a direction normalized to the range 0.0 - 360.0
// * Copyright (c) 2002 Floodgate Entertainment
// * Created By: Naomi Novik
// * Created On: 11/08/2002
float GetNormalizedDirection(float fDirection)
{
float fNewDir = fDirection;
while (fNewDir >= 360.0) {
	fNewDir -= 360.0;
}
while (fNewDir <= 0.0) {
	fNewDir += 360.0;
}

return fNewDir;
}

void SitDown(object oSitter, object oChair)
{		
        //AssignCommand(oSitter, SetFacing(GetNormalizedDirection(GetFacing(oChair)+180.00+GetLocalFloat(oChair,"rotate")) ));
        	
		AssignCommand(oSitter, ActionPlayCustomAnimation(OBJECT_SELF, "sitidle", 1, 1.0));
        	
        // EXTRA CODE THANKS TO SHAUGHN & EGUINTIR
        	
        SetOrientOnDialog(oSitter,FALSE);
        SetBumpState(oSitter,BUMPSTATE_UNBUMPABLE);	
}
		
	

void main()
{
        	
			object oChair = OBJECT_SELF; 
        	object oSitter = GetLastUsedBy();
            object oCheckSitter = GetLocalObject(oChair, "LastSeated");	
			string sChair = GetTag(oChair);
    	    string sAutofit = GetLocalString(oChair, "autofit");
			
		
		
        	
        	//SendMessageToAllPCs("Chair used by " + GetName(oSitter));
        	    
            // RETRIEVE VARS ATTACHED TO CHAIR	
        	int iHeading  = GetLocalInt(oChair, "degree");		
        	//string sName = GetFirstName(oChair); 
            int iPC_size  = GetLocalInt(oChair, "size");
			
        	//Assign the heading degrees
        	location lChair_o = GetLocation(oChair);
            location lChair = Location(GetArea(oChair), GetPositionFromLocation(lChair_o), GetNormalizedDirection(GetFacingFromLocation(lChair_o) + iHeading));
        	
            // CHECK THE SEAT IS FREE
        	if(GetLocalObject(oChair, "LastSeated") != OBJECT_INVALID && oSitter != oCheckSitter)
            {		
        		FloatingTextStringOnCreature("<<< The seat is already being used by somebody. >>>", oSitter, FALSE);		
        		return;	
            }
            
        	// SEAT THE USER & ASSOCIATE SEAT WITH NPC FOR RETURN SEAT	
        	if(oSitter != OBJECT_INVALID)
        	{	
        	SetLocalObject(oChair, "LastSeated", oSitter);
        	SetLocalObject(oSitter, "Seated", oChair);
        	}
        	
        	// JUST USE THE STANDARD CHAIRS
        	AssignCommand(oSitter, ActionMoveToLocation(lChair));
			DelayCommand(1.5, AssignCommand(oSitter, SetFacing( GetNormalizedDirection(GetFacing(oChair)+180.0+GetLocalFloat(oChair,"pl_rotate")) )));
        	DelayCommand(0.5, SitDown(oSitter, oChair));

}

EDIT: If forgot to mention that now everyone sits down on their chairs, even if it takes a second or two, which looks kind of lame, but whatever, but when they sit down on one of Patcha’s benches they face in the wrong direction. Therefore did a variation of this script, it’s mostly just exactly like Lance’s original, just without this line:

DelayCommand(1.5, AssignCommand(oSitter, SetFacing( GetNormalizedDirection(GetFacing(oChair)+180.0+GetLocalFloat(oChair,"pl_rotate")) )));
        	DelayCommand(0.5, SitDown(oSitter, oChair));

}

When doing that the NPCs sitting on the benches face mostly in the right direction. Two of them sit a bit diagonally, if you get what I mean, but I can live with that.

EDIT2: And now another strange bug has appeared. When going out of the inn, if one uses one of the companions to open the door and click on to be teleported, the game hangs/crashes. I mostly just use the PC to do all this stuff but I don’t know why it would behave this way. Maybe it’s because I have a script on the door with some local int checks, so that you can’t leave the inn if you’re in the middle of a quest that needs completion inside…uurrgh, this game gets on my nerves some times.

Hi andgalf,

EDIT: Now have erf and mod for you to check out … two posts below this one. :slight_smile:

EDIT (IMPORTANT): I just recalled why some PCs appear to sit before they reach the chairs … it is because you call the SitDown function before they reach (by moving to) the chair they find. i.e. That is why I had a larger delay (2 seconds), just in case they had to move further. You can also alleviate this problem by placing the NPCs closer to the chair they have to sit on at build time. As I said before (and now recall some more), this is a variation of the original script that allows PCs to use the same chairs to sit, so this version relies more on an added animation for the NPCs (and timing) than direct interaction.

One time, I was going to write a whole post about how important timing of code is, but just let it go in the end. However, I can say that “timing” of events is probably the biggest issue I have with making sure the code works correctly … right down to the 0.1 and below levels. Seriously, I could go on, but I won’t bore you with it. :wink:

Just make sure you do not have any clear actions or another action trying to happen after you start the jump to new area call. It’s an easy thing to add and miss. I corrected one such situation to my own code recently.

If I have the time, I may try putting that area together for you still, just to try to satisfy myself about the whole sitting stuff too.

I don’t think I had that line in there anyway. :slight_smile:

Cheers, Lance.

I personally use two campaign scripts only for commoners animations. They are far from being perfect, but at least they are simple. They can of course be amended. Place the animations scripts onHeartbeat. I never noticed any performance issue, no need to despawn commoners when the PC exits the area.

Basically each commoner carries two variables “Bearing”, the direction he is facing, '“Anim”, the animation played. If you wish you can randomize these variables onSpawn. I personally prefer fully builded scenes so usually set the variables in the toolset.

For instance :
Bearing 90, Anim “sitfidget”. (faces North sit fidget)
Bearing 45, Anim “playguitar” (have a bard carrying a luth, she plays facing North East)

When using a sitting animation, have the commoner “on top of” a chair, set the chair as environmental or walkable, make sure that the commoner has the “no collision” property set.

// generic animation - recurrent

void main ()
{
	ClearAllActions();
	SetFacing(IntToFloat(GetLocalInt(OBJECT_SELF,"Bearing")));
	PlayCustomAnimation(OBJECT_SELF, GetLocalString(OBJECT_SELF, "Anim"), 1, 1.0);
}

Whenever you need the animation to be interrupted add a third variable to the commoner “Stop” and uses the second script, the animation is played when “Stop” is set to 0.
For an instance a NPC is sitting, during the conversation you recruit him, set “Stop” to 1 by a ga_local_int. That’s it.
Or you don’t want the bard to carry on playing when you tak to her :slight_smile:

// anim with a stop flag.

void main ()
{
	object oNPC = OBJECT_SELF;
	string sAnim = GetLocalString(oNPC, "Anim");
	
	ClearAllActions();
	
	if (GetLocalInt(oNPC, "Stop"))
		sAnim = "idle";
	else
		SetFacing(IntToFloat(GetLocalInt(oNPC,"Bearing")));	
	
	PlayCustomAnimation(oNPC, sAnim, 1, 1.0);
}
2 Likes

Hi andgalf,

OK, here is a download for you, which contains both a demo module and an erf to import an area and two scripts, which show sitting working fine … SITTING ERF AND MOD: -

You can either import the erf, or check out the demo mod with the code in place already. Lastly, the two scripts I used are below …

IMPORTANT: Make sure the NPCs you want to try to sit have a variable “TRYSIT” value of 1 on them, like in the demo module provided here.

I used the first script I posted to you (repeated here for ease of reference) and knocked together a cutdown version of my area on enter script for you that forces the NPCs to sit down.

Cheers, Lance.

THE CHAIR ON USED SCRIPT (alb_sit_script):-

void ActionPlayCustomAnimation(object oObject, string sAnimationName, int nLooping, float fSpeed = 1.0f)
{
PlayCustomAnimation(oObject, sAnimationName, nLooping, fSpeed);
}

// float GetNormalizedDirection(float fDirection):
// * This script returns a direction normalized to the range 0.0 - 360.0
// * Copyright (c) 2002 Floodgate Entertainment
// * Created By: Naomi Novik
// * Created On: 11/08/2002
float GetNormalizedDirection(float fDirection)
{
float fNewDir = fDirection;
while (fNewDir >= 360.0) {
	fNewDir -= 360.0;
}
while (fNewDir <= 0.0) {
	fNewDir += 360.0;
}

return fNewDir;
}

        void SitDown(object oSitter, object oChair)
        {		
        	AssignCommand(oSitter, SetFacing(GetNormalizedDirection(GetFacing(oChair)+180.00+GetLocalFloat(oChair,"rotate")) ));
        	AssignCommand(oSitter, ActionPlayCustomAnimation(OBJECT_SELF, "sitidle", 1, 1.0));
        	
        	// EXTRA CODE THANKS TO SHAUGHN & EGUINTIR
        	
        	SetOrientOnDialog(oSitter,FALSE);
        	SetBumpState(oSitter,BUMPSTATE_UNBUMPABLE);	
        }

        void main()
        {
        	object oChair = OBJECT_SELF; 
        	object oSitter = GetLastUsedBy();
            object oCheckSitter = GetLocalObject(oChair, "LastSeated");	
        	
        	//SendMessageToAllPCs("Chair used by " + GetName(oSitter));
        	    
            // RETRIEVE VARS ATTACHED TO CHAIR	
        	int iHeading  = GetLocalInt(oChair, "degree");		
        	string sName = GetFirstName(oChair); 
            
        	//Assign the heading degrees
        	location lChair_o = GetLocation(oChair);
            location lChair = Location(GetArea(oChair), GetPositionFromLocation(lChair_o), GetNormalizedDirection(GetFacingFromLocation(lChair_o) + iHeading));
        	
            // CHECK THE SEAT IS FREE
        	if(GetLocalObject(oChair, "LastSeated") != OBJECT_INVALID && oSitter != oCheckSitter)
            {		
        		FloatingTextStringOnCreature("<<< The seat is already being used by somebody. >>>", oSitter, FALSE);		
        		return;	
            }
            
        	// SEAT THE USER & ASSOCIATE SEAT WITH NPC FOR RETURN SEAT	
        	if(oSitter != OBJECT_INVALID)
        	{	
        	SetLocalObject(oChair, "LastSeated", oSitter);
        	SetLocalObject(oSitter, "Seated", oChair);
        	}
        	
        	// JUST USE THE STANDARD CHAIRS
        	AssignCommand(oSitter, ActionMoveToLocation(lChair));
        	DelayCommand(2.0, SitDown(oSitter, oChair));
        }

THE ON AREA ENTER SCRIPT:-

///////////////////////////////////////////////////////////////////////////////////////////////////
// SET "TRYSIT" VARIABLE TO 1 ON NPC AT BUILD TIME OR VIA SCRIPT TO MAKE THEM KEEP ATTEMPTING TO SIT
// THIS FUNCTION CAUSES PROBLEMS WHEN ADDED TO ALB_FUNCTIONS
// NB: NPCS MAY STRUGGLE TO SIT WHEN NOT CLOSE TO A CHAIR DUE TO WALKMESH ISSUES !!!!!!!!!!!!!!!!!!!
///////////////////////////////////////////////////////////////////////////////////////////////////
void ForceNPCReseat(object oTarget);
void ForceNPCReseat(object oTarget) 
{	
	if(GetLocalInt(oTarget, "TRYSIT") == 0){return;} // SITTING HAS BEEN CANCELLED	
			
	object oCurrentChair = GetLocalObject(oTarget, "Seated");
		
	// SendMessageToPC(GetFirstPC(TRUE), GetName(oTarget) + " IS TRYING TO SIT"); // DEBUG			
	
	// FIND THE NEAREST AVAILABLE CHAIR (USE THE FIRST 8 CHARACTERS E.g. pat_mid_chair5)
	int iCount = 1; object oChair = GetNearestObject(OBJECT_TYPE_PLACEABLE, oTarget, iCount);
	
	while(oChair != OBJECT_INVALID)
	{	
		// FIND A CHAIR WITHOUT A CURRENT USER
		if(GetStringLeft(GetTag(oChair), 8) == "pat_mid_")
		{
			object oCurrentSeater = GetLocalObject(oChair, "LastSeated");
			
			// TRY IGNORING THE FACT THAT THE LAST SEATED CHAIR HAD AN OCCUPANT (IT WAS PROBABLY THEM ANYWAY PRIOR EXIT)
			if(oCurrentSeater == OBJECT_INVALID || oCurrentSeater == oTarget)
			{
				//SendMessageToPC(GetFirstPC(TRUE), GetName(oTarget) + " FOUND A CHAIR"); // DEBUG	
				break;
			}
		} 
			
		iCount = iCount + 1; oChair = GetNearestObject(OBJECT_TYPE_PLACEABLE, oTarget, iCount);	
	}			
	
	// MAKE TARGET USE THIS CHAIR
	SetLocalObject(oChair, "LastSeated", oTarget); 
	SetLocalObject(oTarget, "Seated", oChair);	
	AssignCommand(oTarget, ClearAllActions(TRUE));
	AssignCommand(oTarget, ActionInteractObject(oChair));	
}   


void main()
{
	object oCreature = GetEnteringObject();
	
	// ONLY RUN WHEN PLAYER ENTERS
	if(!GetIsPC(oCreature)){return;}
	
	object oArea = GetArea(oCreature);
	
	object oNPC = GetFirstObjectInArea(oArea);
	
	while(oNPC != OBJECT_INVALID)
	{		
		// RESEAT NPCS
		if(GetObjectType(oNPC) == OBJECT_TYPE_CREATURE && GetLocalInt(oNPC, "TRYSIT") == 1)
		{			
			DelayCommand(0.5, ForceNPCReseat(oNPC));		
		}
		
		oNPC = GetNextObjectInArea(oArea);
	}
}
1 Like

Thanks for the replies @Lance_Botelle and @Claudius33

I’ll continue to test and see what happens. @Claudius33 You just gave me an idea that I could perhaps put the wapoint right on top of the chairs where they are to sit down. Maybe that solves things? Since the chairs are walkable I think that might actually work. The problem is that I need the characters to jump to the waypoint again when the PC reenters the area so that they can sit down again, otherwise they will be standing the second time entering.

I’ll take a look at your demo module @Lance_Botelle

I have tried for an hour to get rid of the weird teleporting bug when trying to get out from the inn. If one uses the PC it works, if you use a companion the game says the area is loaded but the meter freezes half-way. I can’t get around this. I guess I’m forced to tell people in the notes when releasing my module to always use the PC when entering new areas. I don’t know what else to do.
I’ve tried two different teleporting scripts that I have used so many times before (but as I said I normally use the PC when moving around).

I have now tried another area where I have the same kind of teleporting script functioning the exact same way with a few “if” and “else” and when trying to click on the door there to teleport by using a companion everything works. So I have no clue what’s causing the game to freeze when it does.

As I’ve said before, some days the toolset and NWN2 just drives me insane with all the werid stuff happening.

Might as well post the code here to see if I’ve made some kind of stupid mistake. This is placed on the OnClick of the door exiting the inn. The Transition under properties are set to LinkedToObjectType - Transition to a waypoint and then Linked to outs_inn and Party Transition True:

void main()
{
	
 object oPC = GetClickingObject();
 
 if (!GetIsPC(oPC)) return;
 
 	if(GetGlobalInt("fbtbackwithfriends"))
  	{	
 
  	object oTarget;
	location ITarget;
	oTarget=GetWaypointByTag("outs_inn");
	ITarget=GetLocation(oTarget);
	if(GetAreaFromLocation(ITarget)==OBJECT_INVALID)return;
	oTarget=GetFirstFactionMember(oPC,FALSE);
		while(GetIsObjectValid(oTarget))
		{
		AssignCommand(oTarget,ClearAllActions());
		AssignCommand(oTarget,ActionJumpToLocation(ITarget));
		oTarget=GetNextFactionMember(oPC,FALSE);
		}

  
 	 }
   
 	else if(GetGlobalInt("talkingcomp"))
 	{
 
 	FloatingTextStringOnCreature("You should talk first.",oPC);
	
 	}
	
	else
	{
		
	object oTarget;
	location ITarget;
	oTarget=GetWaypointByTag("outs_inn");
	ITarget=GetLocation(oTarget);
	if(GetAreaFromLocation(ITarget)==OBJECT_INVALID)return;
	oTarget=GetFirstFactionMember(oPC,FALSE);
		while(GetIsObjectValid(oTarget))
		{
		AssignCommand(oTarget,ClearAllActions());
		AssignCommand(oTarget,ActionJumpToLocation(ITarget));
		oTarget=GetNextFactionMember(oPC,FALSE);
		}

	
	}
 
}

I think that when the PC reenters the area, the commoner should be still sitting unless you despawn him. NWN2 applies the modifications already done (the famous phase 2 when loading the area).

You do not need to really put the waypoint “on top of” the chair, it can be just below. The sitting animation does the trick. You would do it for a commoner lying on a bed though.

As for the freezing issue , I’ve no idea at the moment.

1 Like

Well, with Patcha’s scripts when leaving and reentering the characters where no longer sitting. That’s why I felt I had to use the script in my 4th post here.

Edit: I placed the waypoints below the chairs and even if you now don’t see the characters move they face the wrong direction sometimes. I’m getting dizzy by all this. Soon I honestly don’t know what I’ve tried or not tried anymore. :woozy_face: :dizzy_face: :confounded:

Before I get even more of a headache caused by all this I think I’ll take a look at Lance’s demo mod now to see how he does things.

1 Like

@Lance_Botelle Looking at your module now I notice that your characters don’t have any scripts on them besides the variable TRYSIT. Is that something that’s important perhaps?
Also the table is Static but not Walkable. Shouldn’t it be Walkable?

1 Like

Hi andgalf,

The table does not matter - only the chairs.

The only reason there are no other scripts is because all mine are different to the stock ones. By all means, put your own scripts there. :slight_smile:

The TRYSIT var is just my way of distinguishing which NPCS to try to sit on the chairs, that is all. i.e. If you have a room of NPCs and you only want half (or even a random set to sit), just set the var on those ones.

BUT, you should see that it works … :slight_smile:

If you import the erf and start working from this base, you can see if anything you now do breaks it. And that is what I mean by starting from a working base until you see what might break it.

Keep me updated. Import that erf and start from there! :wink:

Cheers, Lance.

Try using the OnUsed hook on the door and not the on click. Switch the function to GetLastUsedBy. Alternatively, try switching back to the Main PC with function (forgotten the exact wording of it - something like SetControlledPC < It is not that, but I am not at the toolset at the moment to confirm) and call on the new switched PC - now the Main one. Also, there is a JumpParty (check exact wording) function so you don’t have to loop via faction check. Use that instead.

I’ll pop by again a bit later to see how things are going for you … We’ll get the jump party sorted too, do not worry. :slight_smile:

2 Likes

Hi again, Lance!

I took a break for a few hours and now I’m back trying again. I actually didn’t import your erf but instead just looked at your scripts and how you did it and exported them using my own naming for them. A bit convoluted to do it that way but…well, anyway… :yum:

When I did exactly as your test mod it worked apart from one thing. I’m using Patcha’s benches ( Bench{Working} ), and when doing that the NPCs sitting on those face away from the tables instead of the opposite. I don’t know how to make that work. When using Patcha’s scripts they always face the right way (even if they only sit down half of the time). I tried entering and reentering quite a few times and your scripts seem really solid. So if we could fix the sitting down on the benches then I think I would be satisfied.

The only thing that is a bit…well…that I don’t quite like, is that since there is a 2 second delay you can clearly see the NPCs sitting themselves down when entering the area. I tested by making it a 1 second delay but then the characters wouldn’t turn to face the right way when sitting on the chairs, so I guess we have to let it be 2 seconds. Again, those darn timing problems with this game. One thought I had about this, but I’m not sure it would work considering how sensitive to everything this seems to be, would be to maybe run the sitting script when the PC and the companions click on the door and teleport inside to the inn. Maybe one could run the OnEnter script there…or something?

The jumping script I’m using (and which has been the most solid way to jump with characters in all my modules) are taken from Lilac Soul’s Script Editor. I know I have also written down the function you and kevL_s have recommended: JumpPartyToArea, but on another occasion the Lilac Soul script was more solid (the JumpPartyToArea had some issues when teleporting into a house and there were some other functions involved so…). Maybe in this rare case though I could try that and maybe it will work better here.

I’ll try your thought about putting the script on OnUsed instead and see if it makes a difference.

EDIT: Would the function SetOwnersControlledCompanion(oPC); work for setting whoever character you are controlling back to the main pc? If let’s say you first run object oPC=GetLastUsedBy(); and then if(!GetIsPC(oPC)) return; and then SetOwnersControlledCompanion(oPC);

EDIT2: Switching to OnUsed did the trick! Now the game doesn’t hang anymore even when using a companion to go out. I don’t know if the SetOwnersControlledCompanion(oPC); worked since when outside you still control the companion you controlled when clicking on the door but…well, it doesn’t matter as long as the game doesn’t hang.

2 Likes

Hi andgalf,

I think I had that fixed in mine … not at toolset again, but try altering the var ref (on bench) to 180 degrees different (if that is the way they work iirc). I will take a closer look tomorrow - just prompt me if need be.

Yes, I also see this. You can reduce the impact by adding a fadefromblack when entering, so any sittables finish by the time the fade finishes - or close to anyway. It was a minor thing for me, so I never pursued it.

I would be very surprised if this is due to this function, as it is a very solid function in my experience. I would suspect something else may have been interfering… hmmm.

Yes, that’s the one. :slight_smile: Use oPC = SetOwnersControlledCompanion(oPC); to turn oPC into the main PC. A minor delay after using this function may sometimes be required, so you may need to call a separate function with the new defined oPC after this.

Keep me updated. I am too tired to look at this at the moment, but will have a go tomorrow. Just give me the information if its not already listed n a post above already.

We’ll get it working. :slight_smile:

Cheers, Lance.

2 Likes

Tried with JumpPartyToArea and it seems to work. The one time it didn’t work I also used the script on OnClick script of a door, so maybe that was the problem then as it was when my game froze. Anyway my code for leaving the inn is now like this, but still when I’m outside I still control the companion. Kind of strange:

void main()
{
	
 object oPC = GetLastUsedBy();
 
 if (!GetIsPC(oPC)) return;
 
 oPC = SetOwnersControlledCompanion(oPC);
 
 	if(GetGlobalInt("fbtbackwithfriends"))
  	{	
   	
	DelayCommand(1.0, JumpPartyToArea(oPC, GetWaypointByTag("outs_inn")));
	
	}
   
 	else if(GetGlobalInt("talkingcomp"))
 	{
 
 	FloatingTextStringOnCreature("You should talk first.",oPC);
	
 	}
	
	else
	{
	
	DelayCommand(1.0, JumpPartyToArea(oPC, GetWaypointByTag("outs_inn")));	

	}
 
}
2 Likes

Good news, Lance! I think I’ve got everything working now! :smiley:

I did a fade to black (quite a lot of tweaking before I got it right and I used a function I got from somewhere that I used in my last module) so now you can’t see the sitting down. With the benches I first tried adding degree=180 but that didn’t work so I just tried spinning the benches around and that actually did the trick. I then had to remove the SetOrientOnDialog(oSitter,FALSE); since I want three of the NPCs to turn to the PC since you can talk to them.

The only thing that doesn’t work (but that’s not that important) yet is the oPC=SetOwnersControlledCompanion(oPC);
but that was only to remove the bug (which is now gone), so if we can’t get that to do what it should do then that’s no biggie.

Thank you for your patience with me and for putting so much time and effort to help me with my module and for convincing me to not give up when it seems a bit hopeless!! It’s truly appreciated! :slightly_smiling_face:

2 Likes

I was going to say that originally, but thought the benches may have had “backs” to them in this case. I had not wanted to state the obvious. :wink:

This function does take a little getting used to how it can be used. I believe the problem you have here, however, is because you need to delay the entire function that uses the new oPC, so the delay cannot be within the same initial script. Here is an example … just pseudo code, not tested in any way …

NB: I believe I have used the function like you have somewhere, but not if I need to do an action with them as well iirc. i.e. If I intend to do an action after switching, then use the function like I show below. If just needing to switch and ref, then I think I can get away with using the function in same script section.

void DoStuff(object oPC)
{
string sName = GetFirstName(oPC);
AssignCommand)(oPC, SpeakString(…));
}

void main()
{
object oPC = GetLastUsedBy();
oPC=SetOwnersControlledCompanion(oPC);

   DelayCommand(0.1, oPC, DoStuff(oPC));

}

Does that makes sense? I think of it as the engine having a bit of time to switch to the main PC prior having to do stuff with them.

Anyway, it’s good to hear you have it working. :slight_smile:

Thank you.

Cheers, Lance.

Yes, it makes sense. I’ll try that then.

I tried it with this script but it doesn’t work. I’ve probably done something wrong. The party still jumps to the new area but you still control the companion instead of it switching to the PC:

void Teleport(object oPC)
{
object oPC = GetOwnedCharacter(oPC);
AssignCommand(oPC, JumpPartyToArea(oPC, GetWaypointByTag("outs_inn")));
}

void main()
{
	
 object oPC = GetLastUsedBy();
 
 if (!GetIsPC(oPC)) return;
 
 oPC = SetOwnersControlledCompanion(oPC);
 
 	if(GetGlobalInt("fbtbackwithfriends"))
  	{	
   	
	DelayCommand(1.0, Teleport(oPC));	
	
	}
   
 	else if(GetGlobalInt("comanpiontalk"))
 	{
 
 	FloatingTextStringOnCreature("You should talk first.",oPC);
	
 	}
	
	else
	{
	
	DelayCommand(1.0, Teleport(oPC));	

	}
 
}