Author Topic: Scripting an Area Transition?.?.?  (Read 1003 times)

Legacy_datamaster

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« on: May 08, 2011, 07:28:27 pm »


               I am wondering.  Is it possible to use a script called from a conversation to set up an Area Transition, maybe through a door or a trigger/waypoint?  For example, there is a door that goes nowhere with an NPC nearby.  You talk to the NPC and if you select the right part of the conversation, the door now goes somewhere.  I want to script to either set up the door's area transition or a trigger.  I don't want it to have to keep going through the conversation.  You do the conversation, then you never have to talk to the guy again, but you can go through the door.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #1 on: May 09, 2011, 04:17:46 am »


               Yes, you can script that.  You just need to place a script in the OnAreaTransitionClick Event for the door to control where it goes to.   Any door with a script in this event will override the standard transition for the door.
               
               

               
            

Legacy_datamaster

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #2 on: May 09, 2011, 04:54:16 pm »


               I can see that.  But what I am wondering is can I have a script triggered by a conversation set up that OnAreaTransitionClick script? Without there being one for that door before the conversation?  I want a door that, before talking to someone, goes nowhere(ie has not transition link at all), but after talking to someone, there is now a transition through that door by clicking on it.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #3 on: May 09, 2011, 11:45:28 pm »


               

Lightfoot8 wrote...

Yes, you can script that. You just need to place a script in the OnAreaTransitionClick Event for the door to control where it goes to. Any door with a script in this event will override the standard transition for the door.



AS already stated.  Yes, You can script that.  

For script help you realy should be posting in the scripting section.  But since we are already here.   You would place something like this in the OnAreaTransitionClick Event.

 #include "X0_I0_TRANSPORT"
void main()
{
  object oClicker = GetClickingObject();
  object oTarget = GetLocalObject(OBJECT_SELF,"TRANS_TARGET");

  TransportToWaypoint(oClicker,oTarget);
}
 


Then your transistion will take you to what ever object the local is set to.  If it is not set you will go nowhere.  
it is a simple script that only supports up to one of each companion type.  If you allow more then one summons or henchman or use X3 horses the script will need to be modified.
               
               

               
            

Legacy_datamaster

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #4 on: May 10, 2011, 05:43:57 am »


               Lightfoot,
The way you seem to be saying your responses are that you place that script(or one like it) in the door's OnAreaTransitionClick BEFORE the module is played.  ie: I load up the toolset, I bring up the script for the door's OnAreaTransitionClick and put that in(making sure it goes to the destination I want), save the module.  Then load the module and play it, where now that I am playing the module, when I click that door open then click the Area Transition I go to the place it goes to.
That is not what I am wanting.  I want it that when I play the module, I click on the door and there is NO Area Transition set for the door.  THEN I go talk to an npc and tell him to set up the door's destination.  THEN I go to the door and there is an Area Transition for it.  I want to have a script in run by the specific part in the conversation that set's up that door's Area Transition.
I want it to where I can have multiple areas in a module, but set it up through a conversation which area that door goes to(this can change each time the module is started from the beginning).
I am glad for your responses to my different posts topics.  They have been helpful.  I am wanting this one to be where I got a number of different areas and through conversation(s), the player can set up what area specific doors go to(instead of me as the module creator setting that door's destination to a specific spot beforehand)

"Knowledge knows no bounds!  But hindsight might wish there had been!"
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #5 on: May 10, 2011, 06:12:48 am »


               The script as is will take you nowhere.  There is no way to even set a local object in the toolset before you start playing the game.   You would set up your conversation to set the local object on the door from your conversation.   Useing the SetLocalObject function in a Action Taken script  in your conversation.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #6 on: May 10, 2011, 09:07:40 am »


               If I'm understanding what you want you could do something like this:

In your conversation lines you could use scripts like this to set a string on the player that will tell which waypoints the player will travel to:

void main()
{
    object oPC = GetPCSpeaker();
    SetLocalString(oPC, "DESTINATION", "tag of waypoint");//Put the correct tag of your WP here
}


Then in your door or trigger's OnClick event you could put something like this:

void main()
{
    object oPC = GetClickingObject();
    string sWP = GetLocalString(oPC, "DESTINATION");
    object oWP = GetWaypointByTag(sWP);
    AssignCommand(oPC, ActionJumpToObject(oWP));
}


If the destiantion needs to be more permanent you can do a couple other things. Instead of putting the string variable for the destination on the player you could use the database or an item the player will always have.

Hope that helps. Good luck.
               
               

               


                     Modifié par GhostOfGod, 10 mai 2011 - 08:12 .
                     
                  


            

Legacy_datamaster

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #7 on: May 10, 2011, 05:49:17 pm »


               Another way I was thinking of, after I posted that last post, was setting a variable via the conversation(ex. if wanting to go to area 1, set x to 1, area 2, set x to 2, etc.) and having in the OnAreaTransitionClick an if statement that checks for this, and if it is 1 ports you to area 1, and if 2 it ports you to area 2, etc. The doors in the areas that it is porting near to will have to have their own script to check where to port back to though. I will probably want to be careful of having long if statements though.
I got to thinking after my last post, that what I was asking most likely wasn't possible in the way I was asking, so I started thinking of ways to get around it and still do what I was wanting.
Although, now that I think about it, the way you are saying might be slightly better than mine. It avoids the if statement(s) I mentioned.
edit-using the if statement(s) though can mean using them for each script, for each area(which includes getting back to the start.  If I use the if statements, I can have in the starting area script, if x=1 then port to area 1, while in area 1, if x=1 then port back to the start.  I will have to think on this.
-----------------------------
"Knowledge knows no bounds! But hindsight might wish there had been some!"
               
               

               


                     Modifié par datamaster, 10 mai 2011 - 04:52 .
                     
                  


            

Legacy_datamaster

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #8 on: May 11, 2011, 04:23:02 pm »


               After testing this, I figured out how to do what I was wanting here, but not the way I was wanting.
I have the variable(s) set via the conversation.  Then I have the door's OnOpen script using an if statement, check that variable.  If it is one thing, teleport the PC to the correct area(a waypoint in that area).  Else if it is another thing, teleport them to a different area, and so on.  Then shut the door.
Each door that I have being part of this has it's own NPC near it to set the destination for it(using a different variable for each door).
I have it set where once the destination is picked, it can't be changed without starting the module again(this is an easy fix if you want the door to be changeable after the first destination is set).
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #9 on: May 11, 2011, 10:51:19 pm »


               

datamaster wrote...
I have the variable(s) set via the conversation. Then I have the door's OnOpen script using an if statement, check that variable. If it is one thing, teleport the PC to the correct area(a waypoint in that area). Else if it is another thing, teleport them to a different area, and so on.



I think you are making it over complacated.  Why set an int.  Setting an Int only make you have to create another logic structure to figure out what the int means.   Just use the first script I gave you in the OnAreaTransitionClick Event.  The door will not go anywhere when the module starts.  The local object is not yet set, therefore the dore has no destnation.   In you Action Taken conversation Event just set the local object on the door to where you want it to go. 

Ok let me assume that you have 5 doors with the tags RandomDoor1,RandomDoor2, ect... and an NPC with a conversation standing next to each door.  One of you Action Taken scripts for setting the NPC's  door(The one Nearest to the NPC) to go to door 5, could look like this.

void main()
{
  // Get the Object for each door.
  object oNPCsDoor = GetNearestObject(OBJECT_TYPE_DOOR);
  object oDestDoor = GetObjectByTag("RandomDoor5");
 
  //Set oDestDoor as the destnation for oNPC's door.
  SetLocalObject ( oNPCsDoor,"TRANS_TARGET",oDestDoor);

  // Set oNPC's door as the Destnation for oDestDoor
  SetLocalObject ( oDestDoor,"TRANS_TARGET",oNPCsDoor);
}


               
               

               


                     Modifié par Lightfoot8, 11 mai 2011 - 09:53 .
                     
                  


            

Legacy_datamaster

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #10 on: May 13, 2011, 07:23:27 pm »


               I think I see what you mean Light.  I am going to test it out soon.
What I am thinking is that if you talk to the NPC for a door(the door being the one closest to the NPC), and you tell him to set this door to the door #5(RandomDoor5) with this door being #1, the Action Taken script for that line in the conversation is that script you just posted(and the OnAreaTransition Script for each door being the first script you posted here and the tags of the doors being RandomDoor1, RandomDoor2, etc).  If you tell him instead to set it to door #2, then it is the same script but oDestDoor is set to RandomDoor2.

I think one problem I was having understanding was that you were mentioning one door, I don't see anywhere about setting it differently based on what is picked in the conversation, just that the choice is set in conversation.

So I think I have it now.

If I have any other problems with this, I will let you know.  But as I said, I think I have it.

And yes, the way I am understanding it from your posts, is that this way is better scripting that what I was thinking.

Also is this #include "X0_I0_TRANSPORT" what must be in all OnAreaTransitionClick scripts for it to appear/work?
               
               

               
            

Legacy_datamaster

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #11 on: May 14, 2011, 04:11:46 am »


               I am running into a problem. To test how I think it should be, from what you are saying Lightfoot, I made a new module. The door has your script in it's OnAreaTransitionClick:

#include "X0_I0_TRANSPORT"
void main()
{
object oClicker = GetClickingObject();
object oTarget = GetLocalObject(OBJECT_SELF,"TRANS_TARGET");

TransportToWaypoint(oClicker,oTarget);
}

And this script is in the Actions Taken for the conversation:

void main()
{
// Get the Object for each door.
object oNPCsDoor = GetNearestObject(OBJECT_TYPE_DOOR);
object oDestDoor = GetObjectByTag("RandomDoor5");

//Set oDestDoor as the destnation for oNPC's door.
SetLocalObject ( oNPCsDoor,"TRANS_TARGET",oDestDoor);

// Set oNPC's door as the Destnation for oDestDoor
SetLocalObject ( oDestDoor,"TRANS_TARGET",oNPCsDoor);
}

The conversation has three choices(with the RandomDoor5 changed appropriately in each).
The destination doors ARE made.

The problem I am having is that when I click to open the door, there is NO area transition clickie highlight there. This was one problem I ran into earlier, before I decided to put the solution I had had into the OnOpen script and have it teleport the PC. I believe yours should work, if the area transition highlight shows up on opening the door.

edit-I also tried something else with another door and 3 more areas(all forests).  I tried having it randomly select between them(yes I used an if statement for this).  I told it to set an int to a die roll result of a d6.  If that result is a 1 or a 2, run the scriptlines you have but to a certain forest, or if it is 3 or 4, another forest, else a third.
               
               

               


                     Modifié par datamaster, 14 mai 2011 - 03:16 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #12 on: May 14, 2011, 05:08:16 am »


               Open the proptries for the door. On the Area Transistion tab, Select either Door or waypoint for the destination type.  It does nor really matter which one you pick Since you do not need to setup the Area Transistion in the toolset.  As long as it is not set to None you will have an area transition clickie highlight there.
               
               

               
            

Legacy_datamaster

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #13 on: May 15, 2011, 04:02:38 am »


               Ahh, did not(obviously) know that.  Thanks!
               
               

               
            

Legacy_datamaster

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +0/-0
Scripting an Area Transition?.?.?
« Reply #14 on: May 15, 2011, 04:47:49 am »


               With current tests, the door that sets the destination to where the PC says for it to go, is working.
The random side is occasionally working.  I think I know the problem.

This is my script for the random select door(the script on the door is the same as the other door, but this is the script in the conversation's Actions Taken script).

void main()
{
  int seconddoor = d6();
  // Get the Object for each door.
  object oNPCsDoor = GetNearestObject(OBJECT_TYPE_DOOR);
  object oDestDoor;
  if ((seconddoor == 1) || (seconddoor == 2))
  {
    oDestDoor = GetObjectByTag("RandomDoor9");
  }
  else if ((seconddoor == 3) || (seconddoor == 4))
  {
    oDestDoor = GetObjectByTag("RandomDoor11");
  }
  else
  {
    oDestDoor = GetObjectByTag("RandomDoor13");
  }
  //Set oDestDoor as the destination for oNPC's door.
  SetLocalObject(oNPCsDoor,"TRANS_TARGET",oDestDoor);
  // Set oNPC's door as the Destination for oDestDoor
  SetLocalObject(oDestDoor,"TRANS_TARGET",oNPCsDoor);
}

I think the problem is in the if statements.
ex. take this one:

  if ((seconddoor == 1) || (seconddoor == 2))

Now the seconddor ==1 is fine, but I think my OR statement is wrong(or using the wrong symbols or something).
I have been trying to find out what the AND, OR, etc. commands for if statements are in the NWN scripting language.  No luck.  I tried looking up Boolean Algebra and c# programming, and it says the OR symbol is +, but that not always working either.

Also, I am wondering, is the second SetLocalObject supposed to set the destination door back to this door?  ex. You set door1 to door2(you are standing at door1 though), does this set door2 back to door1 if you click on door2?
If it doesn't, I figure it should be reasonably ok, somehow, to tell the script that sets the objects to get the destination door it is going to use and set it's destination back to this one.

---------------------------
"Knowledge knows no bounds!  But hindsight might wish there had been some!"