OnClientEnter question

I had a weird problem when testing some things just now. I oftentimes use scripts on the OnClientEnter of an area. I’ve never had any issues with this before, but now I had some odd and worrying things happen, which made me doubt my own understanding of how the OnClientEnter of an area actually works…

This script ran the first time I entered the area but NOT the second time for some reason.

My understanding, which I now think is not right, is that the OnClientEnter only runs if the PC enters the area, but the OnEnter of an area runs everytime something enters? Is that correct. Anyhow, here’s my script:

void CheckArea()
{

object oPC = GetFirstPC();

object oArea = GetObjectByTag("Island");
object oCasper = GetObjectByTag("casper");

	if(GetArea(oCasper) == oArea)
	{
	
		SetLocalInt(OBJECT_SELF,"Done",1);
		SetCutsceneMode(oPC);
		AssignCommand(oCasper, ActionStartConversation(oPC, "c_casper", FALSE, FALSE, TRUE, FALSE));
	
	}


}

void main()
{

object oPC = GetEnteringObject();

if(!GetIsPC(oPC)) return;

SendMessageToPC(oPC,"The script is found and runs.");

if(GetLocalInt(OBJECT_SELF,"Done")) return;

DelayCommand(0.3,CheckArea());



}

EDIT: To Clarify: When testing this the object oCasper wasn’t in the area, so that bit of code was never run. Also, when switching to using this on the OnEnter of the area, it worked both times I when I entered, and then reentered the area (by going to another area and then coming back). By the way, this script is in my campaign folder, if that has anything to do with it.

Alright, NOW it gets interesting. I tried this script again on OnClientEnter, but this time I first went to this area, then to another area and then back again. And this time it worked!

So the curious thing is that before, when it doesn’t work, I used @kevL_s’ scripts with the Party Roster thingy I discussed in another thread. Here are those two scripts again (with additions from myself):

/*
    Door OnOpen script. Shows the PartySelect gui. Original script by kevL_s and previous script ideas by travus. Specific module additions and changes by andgalf.
*/

const string sROSTER_NELOWYN = "nelowync"; // note: this needs to be the *roster* string-id
const string sROSTER_WRENBUR = "gnome"; // note: this needs to be the *roster* string-i
const string sROSTER_LANIA = "leniac"; // note: this needs to be the *roster* string-i
const string sROSTER_FLEKSA = "fleksac"; // note: this needs to be the *roster* string-i
const string sROSTER_TINDRA = "tindra"; // note: this needs to be the *roster* string-i
const string sROSTER_SEMAPHINE = "semaphine"; // note: this needs to be the *roster* string-i

#include "ginc_gui"

void SelectYourParty()
{

    ShowPartySelect(GetFirstPC(),
					TRUE,         // modal
                    "jump_exit",  // callback script on Accept
                    TRUE);        // show close button

}

void main()
{

	SetGlobalInt("academygoout",1);
		
	object oTindra = GetObjectFromRosterName(sROSTER_TINDRA);
	object oSemaphine = GetObjectFromRosterName(sROSTER_SEMAPHINE);
	object oFleksa = GetObjectFromRosterName(sROSTER_FLEKSA);
	
	SetIsRosterMemberSelectable(sROSTER_NELOWYN,TRUE);
	SetIsRosterMemberSelectable(sROSTER_WRENBUR,TRUE);
	SetIsRosterMemberSelectable(sROSTER_LANIA,TRUE);
	
	if(GetIsObjectValid(oFleksa))
	{
		SetIsRosterMemberSelectable(sROSTER_FLEKSA,TRUE);
	}
	
	if(GetIsObjectValid(oSemaphine))
	{
		SetIsRosterMemberSelectable(sROSTER_SEMAPHINE,TRUE);
	}
	
	if(GetIsObjectValid(oTindra))
	{
		SetIsRosterMemberSelectable(sROSTER_TINDRA,TRUE);
	}
	
	
	DelayCommand(0.5, SelectYourParty());

}

/*
    Callback script for PartySelect gui. Set by 's_a1_leaveacademy' (door OnOpen
	script). Script by kevL_s.
*/

#include "ginc_transition"

void main()
{
    object oTarget = GetWaypointByTag("outsacad_wp");
    SinglePartyTransition(OBJECT_SELF, oTarget); 
	//destination must be in the same module, else use SaveRosterLoadModule()
}

When using these two scripts leaving another area, and entering the area with my OnClientEnter script, the OnClientEnter script doesn’t run. Why is that! It’s so odd!

followed by

SetLocalInt(OBJECT_SELF,"Done",1);

will make it run only once, this is a trick used to have a script run only once, in this case, on enter area it’s mostly done for initialisation which normaly is done only once

You set 1 the first time a player enter the area. and you check if 1 was set in that area. If it’s set you cut the execution.

1 Like

@Shallina - I’m afraid you are wrong about this in this particular situation. As I said,

So the CheckArea function never ran when testing this and that’s where I put the SetLocalInt(OBJECT_SELF,"Done",1);

And if following your logic, it wouldn’t have worked when I tried the other test without kevL_s’ scripts, and it worked perfectly fine there, so the whole issue seems to rather be something with the ShowPartySelect thingy or maybe the SinglePartyTransition…or something…

@kevL_s - I think I found the solution, since now it seems to be working. By changing your second script back to Colorsfade’s original one that looked like this seemed to solve this odd bug:

#include "ginc_transition"
#include "ginc_gui"


void DoTransition(object oTarget)
{
	object oPC = GetFirstPC(); 
	SinglePartyTransition(OBJECT_SELF, oTarget);
	
	object oPCF = GetFirstFactionMember(OBJECT_SELF,FALSE);
	while (GetIsObjectValid(oPCF))
	{
		CloseGUIScreen(oPCF,GUI_PARTY_SELECT);		
		oPCF = GetNextFactionMember(OBJECT_SELF,FALSE);	
	}
}

void main()
{

object oTarget= GetWaypointByTag("outsacad_wp");
DelayCommand(0.2f, DoTransition(oTarget));


}

So maybe for some odd reason you have to use the CloseGUIScreen for the bug to not be there.

strange … I tried it here on my end. transition from an exterior area /w door onopen to an interior waypoint. With companions in the party and without … the debug in an OnClientEnter script slotted on the destination area always fired as expected (using my original barebones scripts as posted)

anyway / just a note …

 
I have no clue why the gui seemingly needs to be closed, the cancel/accept buttons ought close the PartySelect screen auto.

*shrug :\

 
ps. I tend to think the 0.2f delay on SinglePartyTransition() fixes it if anything … rather than the calls to CloseGUIScreen()

2 Likes

Were you possessing a different PC?

i.e. It may fire if you are possessing your main PC, but maybe not if possessing a companion?

Just querying as I also have some strange behaviour in the early days, and I cannot recall what it was in the end. Even my own notes were “wrong” when I just checked them.

Try using a single PC as a test and see if it always fires then. Otherwise, maybe controlling a different PC at time of entry causes issues with the way it is.

Catch you later!

@kevL_s - Ah, so you think it might be the delay that’s the necessary bit here? Could be…I’ll test that tomorrow. Now I need some sleep.

@Lance_Botelle - I was possessing the main PC, as in the area where I go from I only have the PC, then the GUI happens when you choose which companions to come with you, you teleport the party, and with kevL_s’ jump_exit script I found the bug.

1 Like

@kevL_s - I did as you suggested and delayed the SinglePartyTransition with 0.2, and now it worked! Strange that it needs a delay there. Anyway, since it works now, I’ll go back to your script again (with the delay, of course) as I find it more logical and compact. So, for future me, if I get into a similar situation again, the script now looks like this:

// 'jump_exit'
/*
    Callback script for PartySelect gui. Set by 'dr_op_partyselect' (door OnOpen
	script).
*/

#include "ginc_transition"

void main()
{
    object oTarget = GetWaypointByTag("outsacad_wp");
    DelayCommand(0.2,SinglePartyTransition(OBJECT_SELF, oTarget));
}

Another thing with this that is a bit odd (I think, I’m not sure) is that when I loaded a save, to be in the right place and not have to replay stuff, I am in the area with the OnClientEnter, and when loading I didn’t get the SendMessageToPC message. However, if I play “from the beginning” (not really but…) and I arrive in the area, since I placed the SetStartLocation there, I get the message. But everytime, in both cases, when I go to the other area, and from that other area do the Party Select and teleport out to the area with OnClientEnter, I get the message. I thought that even if you load a save, you “enter” the area where the save is at, and that should fire the OnClientEnter, but maybe that’s not correct?

1 Like

well… i did my test on a barebones test-module setup. You’ve no doubt got all kinds of stuff going on … placeables to load etc etc etc. Perhaps the engine just needs a fraction of a second to work all that extra stuff out …

uh… when loading a game the splash screen(s) tend to hide messages to the chatbox, or causes them to be bypassed … if you want/need accurate debug during such events you’ve got to go with PrintString() to the NwN2 logfile

2 Likes

Aha. Didn’t know that. Interesting. Well, then nothing’s wrong, I guess. I just wondered if I had found another bug I needed to adress.

1 Like