Aller au contenu

Photo

Restrict the OnClientEnter depending on where we enter the area from?


  • Veuillez vous connecter pour répondre
14 réponses à ce sujet

#1
andysks

andysks
  • Members
  • 1 645 messages

Hi all. As the title says, is there a method to do this? Like, if we have an area that is available for entering through two different triggers, says south and north, or doors, or whatever, can we restrict the OnClientEnter event to fire only on one of them?

 

In my situation, if it helps, it is a door, normal triggers and world map transition. I want the script to fire only when we come to the area using the world map, but not if we exit a building that is placed in the area, which means we enter it again.



#2
Clangeddin86

Clangeddin86
  • Members
  • 220 messages

Couldn't you just remove the OnClientEnter and move that script to the transiction trigger of the one door you'd like to fire it?



#3
andysks

andysks
  • Members
  • 1 645 messages

Well, actually the floor is filled with other triggers :). Honestly, I thought so too. That I could do it like that. But the restriction (if possible) could be the better solution. And to clarify:

1: the area is exterior

2: Accessible via a world map travel.

3: In the area there is a building placed, available for entering.

4: Some cutscenes might happen in this area, where the PC will get transferred to another area, and then back.

 

So, basically I want the script to only fire when we arrive through a world map travel. If not possible, I guess I could arrange a trigger as you said.



#4
Clangeddin86

Clangeddin86
  • Members
  • 220 messages

You could try with the following:

 

On the world map, you put on ClientEnterScript a new script that sets a local variable of the PC (you could call it WORLD_MAP) to 1.

 

On your script, you put a check that returns if that variable is different than 1.

At the end of the script, you set the variable to zero (you should be inside an exterior area anyway).

 

That should work, no?


  • andysks aime ceci

#5
andysks

andysks
  • Members
  • 1 645 messages

I guess that makes sense. Everytime we travel there, the variable is set to TRUE. Script OnEnter checks for true and fires, and after it fires it sets it to false.



#6
andysks

andysks
  • Members
  • 1 645 messages

Works idealy. Thanks for the tip :). On a side note, does any one know why the game/windows give an assertion error when one tries to pass a global as SetGlobalInt instead of as an int bVariable and then checks for TRUE or FALSE? Or at least this is what happened to me now. I tried 

 

SetGlobalInt("CAMP_TRAVEL", 1);

 

Got the error, and then this worked.

 

int bMakeTravel = GetGlobalInt ("CAMP_TRAVEL");

 

In any case, the whole situation makes a lot more sense now. Thanks again for the help :).



#7
Tchos

Tchos
  • Members
  • 5 030 messages

If you don't want to worry about whether you erase or change the local variable or you plan to teleport there in other ways, you can do a check at the beginning of the On Client Enter script comparing the distance of one of the waypoints to the player.  If it's below a certain value, the player must have arrived at waypoint 1, so execute the rest of the script.  If it's above a certain value, the player must have arrived at waypoint 2, so abort.

 

This assumes that On Client Enter only fires when the player has arrived in the area, which is my understanding as to why we don't use On Enter for such things.



#8
andysks

andysks
  • Members
  • 1 645 messages

This idea Tchos seems good now, because changing a variable through/or just before the world map travel bugs quite a bit. So far two new I haven't seen before. One was the assertion fail, and then the party froze in place. So, this is a good idea you have there. Compare distances maybe not, mainly because I don't know how to do it, but could I check the PC's position/location through a check on the waypoint?



#9
Tchos

Tchos
  • Members
  • 5 030 messages
float fDistance1   =  GetDistanceBetween(oWaypoint1, oPC);
float fDistance2   =  GetDistanceBetween(oWaypoint2, oPC);
if (fDistance1 < fDistance2)
{
   // Player must have entered via waypoint 1
}

You can do it without checking both distances like I suggested above, but this way I think better illustrates the process.



#10
andysks

andysks
  • Members
  • 1 645 messages

I like that. Seems simple and few lines of code :).

 

Logical question, which is more correct, because both will compile. (see brackets).

	else if ( GetLocalInt(oPC, "NW_JOURNAL_ENTRYwalorin") == 101
	&& fDistance1 < fDistance2
        && GetGlobalInt("met_maudril") == 1	
	&& GetGlobalInt("met_walorin") == 1
	&& GetGlobalInt("WAL_FIRST_HANG") == 0)
	else if ( GetLocalInt(oPC, "NW_JOURNAL_ENTRYwalorin") == 101
	&& (fDistance1 < fDistance2)
        && GetGlobalInt("met_maudril") == 1	
	&& GetGlobalInt("met_walorin") == 1
	&& GetGlobalInt("WAL_FIRST_HANG") == 0)

They need to all return in order for the condition to pass. In the past KevL explained to me the process of && and || but I forgot :/.



#11
andysks

andysks
  • Members
  • 1 645 messages

Forget about it. Trial and error showed me the way, and of course your method works as intended Tchos. This is awesome. It adds something I really felt needed!



#12
Tchos

Tchos
  • Members
  • 5 030 messages

No problem.  I notice you're using the local int method of checking the journal.  Do you know that it can be done with the function GetJournalEntry(string szPlotID, object oObjectJournal)?  That way you don't have to preface your journal tag with "NW_JOURNAL_ENTRY".



#13
kevL

kevL
  • Members
  • 4 052 messages

In the past KevL explained to me the process of && and || but I forgot :/.


if they're all ANDs you don't need any extra sub-brackets. Ie, each condition must check TRUE, and "fDistance1 < fDistance2" is 'just another expression',

tldr; they're both the same.

#14
kamal_

kamal_
  • Members
  • 5 238 messages

No problem.  I notice you're using the local int method of checking the journal.  Do you know that it can be done with the function GetJournalEntry(string szPlotID, object oObjectJournal)?  That way you don't have to preface your journal tag with "NW_JOURNAL_ENTRY".

Lilac Soul's script generator generates script like andy has. i know from experience :-)

 

It's the nwn1 way, but it works fine.



#15
andysks

andysks
  • Members
  • 1 645 messages

I'm using both methods, and since from experience they both work, it comes down to which I feel like implementing at the moment :).