Aller au contenu

Photo

[Solved] New area transition in existing area (OC)


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

#1
princecorg

princecorg
  • Members
  • 67 messages
I'm new to scripting and would like to add a new area transition in an existing area (let's say Lothering).

I've read about scripts to spawn new creature or placeable and PRCSCR script, but in most cases, examples given are for creatures.

I've also read that it was impossible to add new waypoints via scripting so how do you make new area transitions ?

If the player can access a new area (defined in my module) from an existing area, how can i make him go back near the door he first used to access this area ?

Thanks for your help.

Modifié par princecorg, 09 novembre 2010 - 05:55 .


#2
mtottenh

mtottenh
  • Members
  • 5 messages
http://social.biowar...p/Area_tutorial

That should be what you are looking for, it details area transitions. AFAIK the process should be the same for editing an existing area, you just have to make sure that once you edit the existing area you export it to your override folder so that when you play your module(or even the sp campaign if you really want) it loads the edited area.

#3
TimelordDC

TimelordDC
  • Members
  • 923 messages
You don't want to edit existing OC areas - not recommended.



What you can do is spawn an invisible placeable near your transition point -> this will be pseudo-waypoint. Set up the transition for the player to go to one of the existing waypoints and in the areaload_preload_transition event, move him to the location near that placeable.

#4
princecorg

princecorg
  • Members
  • 67 messages
Thanks.

mtottenh, i agree with TimelordDC, i'll not temper with the existing OC areas.

As for the invisible placeable, it's a good idea.

Does this placeable have to be active ?

I'm not sure to fully understand how to achieve the change of location in the areaload_preload_transition event :

TimelordDC, could you enhance me with a sample of script ?

#5
FergusM

FergusM
  • Members
  • 460 messages
You'll want an inactive placeable, so that it doesn't collide with the player.

But, actually, is that really the best way to do things? Don't you have to specify a location to spawn the placeable in the first place? The whole issue being that you can't just place something in the area editor, it has to come from a script? The most straight forward way would be to just give a set of coordinates, wouldn't it?

Modifié par FergusM, 06 novembre 2010 - 08:07 .


#6
_L_o_B_o_

_L_o_B_o_
  • Members
  • 117 messages
* Deleted. No reply needed! Sorry:pinched: *

Modifié par _L_o_B_o_, 06 novembre 2010 - 08:35 .


#7
princecorg

princecorg
  • Members
  • 67 messages
As english is not my natural language, i'm not sure to fully understand you.
Everything has to be done by script as we must avoid to edit OC areas.
What i'm trying to do is adding a new transition area (door placeable) in an existing area (to extend a bit the single player campaign). The problem is that it is not possible to add waypoints in a dynamic way.
Sets of coordinates are easy to retrieve as you can duplicate an OC area in the toolset and add placeables, creatures or waypoints. All i do is just writing down the vectors and the orientation.
Are you suggesting that i can make the player appears directly at a set of coordinates when using the transition door from B to A travel (A would be the OC area and B my module area)?
As i'm totally new to DA scripting, i don't know how to do that and would appreciate if you could explain farther.
Thanks a lot.

Modifié par princecorg, 06 novembre 2010 - 08:31 .


#8
Proleric

Proleric
  • Members
  • 2 346 messages
AFAIK there is no explicit way of doing an area transition to a target location in DAO, because the area transition functions require us to specify a waypoint, not a location.

I find that SetLocation to an area which isn't loaded doesn't work and can crash to desktop, hence the need to use the area transition functions.

So, I'd support the suggestion of spawning an invisible object, doing an area transition to an existing waypoint, then, on arrival in the new area, use SetLocation to move both the player and their followers (not just the party leader) to the location of the invisible object.

Modifié par Proleric1, 07 novembre 2010 - 08:46 .


#9
princecorg

princecorg
  • Members
  • 67 messages
Yes, i understand that. It was what TimelordDC tried to explain to me.



As i'm totally noob with scripting, i would appreciate a sample of code for this.



I think it should even be posted as a template here :



http://social.biowar...n_existing_Area



So if someone wants to try ...

#10
_L_o_B_o_

_L_o_B_o_
  • Members
  • 117 messages
I am not sure if this is the best solution, but you can give it a try.

To ease the naming of areas, let's call AREA_A the existing area from the Single Player Campaign, and AREA_B your custom area. In my example I'm gonna use the orz260ar_proving area as AREA_A.

I'll create a PRCSCR script to perform the following tasks when AREA_A is loaded:

1.- Create a placeable that will trigger the transition to AREA_B.
2.- If the player is travelling from AREA_B to AREA_A, I'll put the player's party at a predefined location.

There is a little problem here, how do I know if the player is travelling from AREA_B to AREA_A? This information is available in the event script of AREA_A, but I'm using a PRCSCR script here. So, I'm gonna create a plot to store that information.

The plot is called transition_controller (use whatever name you prefer) and it has a main flag, TRANSITION_CONTROLLER_MOVE_PARTY. Now, each time the player clicks the placeable in AREA_B that triggers the transition to AREA_A, TRANSITION_CONTROLLER_MOVE_PARTY has to be set. This way when the PRCSCR script checks this flag, I'll know that I have to move the player's party to my invisible placeable.

This is the script that should be attached to the placeable that connects AREA_B to AREA_A:

/*
    Type:   Placeable Script.
    Owner:  my_area_b_placeable.utp
    Desc:   Triggers an area transition (orz260ar_proving) when clicked.
*/

#include "utility_h"
#include "wrappers_h"   
#include "plt_transition_controller"    

// The tag of the destination Single Player area.
const string    SP_AREA_TAG         = "orz260ar_proving";
// The tag of the waypoint of the Single Player area. You can use any waypoint, since the final location will be changed in the PRCSCR script.
const string    SP_AREA_WP_TAG      = "mn_exit_commons";

void main()
{
    event ev            = GetCurrentEvent();
    int nEvent          = GetEventType(ev);
    int bEventHandled   = FALSE;

    switch (nEvent)
    {
        //---------------------------------------------------------------------
        //  Sent by engine when creature clicks on the placeable.
        //---------------------------------------------------------------------
        case EVENT_TYPE_USE:
               			    
        WR_SetPlotFlag(PLT_TRANSITION_CONTROLLER, TRANSITION_CONTROLLER_MOVE_PARTY, TRUE);
        UT_DoAreaTransition(SP_AREA_TAG, SP_AREA_WP_TAG);
    
        bEventHandled = TRUE;
        break;
    }

    if (!bEventHandled)
    {
        HandleEvent(ev, RESOURCE_SCRIPT_PLACEABLE_CORE);
    }
}

Here is the code of the PRCSCR script:

/*
    Type:   PRSCR Script.
    Owner:  PRCSCR_MyMod.xls
    Desc:   Manages transitions between AREA_A and AREA_B.
*/

#include "wrappers_h"
#include "utility_h"
#include "plt_transition_controller"

// The tag of the placeable that triggers the transition to AREA_B.
const string    MY_TO_AREA_B_PLACEABLE_TAG    	= "my_to_area_b_placeable";
// The resource of the placeable that triggers the transition to AREA_B.
const resource  MY_TO_AREA_B_PLACEABLE_RES    	= R"my_to_area_b_placeable.utp";

void main()
{
    object oPlayer = GetMainControlled();
    object oSPArea = GetArea(oPlayer);
	
    // Check if we have already spawned the placeble that triggers the transition to AREA_B.
    object oMyToAreaBPlaceable = UT_GetNearestObjectByTag(oPlayer, MY_TO_AREA_B_PLACEABLE_TAG);

    // If the placeable has not been created yet.
    if (!IsObjectValid(oMyToAreaBPlaceable))
    {
        // The position where the placeable will be placed. Look for the correct coordinates in the area.
        vector vMyToAreaBPlaceablePosition = Vector(-13.2948f, -2.52783f, 0.0f);
        location lMyToAreaBPlaceableLocation = Location(oSPArea, vMyToAreaBPlaceablePosition, 0.0f);
		
        CreateObject(OBJECT_TYPE_PLACEABLE, MY_TO_AREA_B_PLACEABLE_RES, lMyToAreaBPlaceableLocation);
    }	

    // Check if we are coming to AREA_A from AREA_B.
    if (WR_GetPlotFlag(PLT_TRANSITION_CONTROLLER, TRANSITION_CONTROLLER_MOVE_PARTY))
    {
        // Important. Reset the flag!
        WR_SetPlotFlag(PLT_TRANSITION_CONTROLLER, TRANSITION_CONTROLLER_MOVE_PARTY, FALSE);	

        // The position where the player's party will be placed when travelling from AREA_B to AREA_A.
        // Look for the correct coordinates in the area.   
        vector vNewPartyPosition = Vector(-22.2707f, -4.82985f, -2.38419f);    
        location lNewPartyLocation = Location(oSPArea, vNewPartyPosition, 0.0f);

        // Move the player's party to the given location.
        command cJump = CommandJumpToLocation(lNewPartyLocation);
        object[] aParty = GetPartyList();
        int n;

        int nPartySize = GetArraySize(aParty);
        for (n = 0; n < nPartySize; n++)
        {
            WR_AddCommand(aParty[n], cJump, TRUE, FALSE, COMMAND_ADDBEHAVIOR_DONTCLEAR);
        }
    }
}

Here you have a good start. Good luck!

EDIT: While I was brushing my teeth I have realized that using CommandJumpToLocation() you don't need to create an invisible placeable to later retrieve its location. It is redundant and ugly code, so I have erased that part.

Modifié par _L_o_B_o_, 08 novembre 2010 - 10:23 .


#11
princecorg

princecorg
  • Members
  • 67 messages
Thanks a lot. Image IPB
Honestly, i wouldn't have been able to write this script myself. I'll give it a try as soon as i can.

Modifié par princecorg, 07 novembre 2010 - 05:41 .


#12
princecorg

princecorg
  • Members
  • 67 messages
I've got some questions.

It seems that my placeable in area A (in my case lot100ar_lothering) is not created, i know that the PRCSCR script is working as i've changed the associated plot to true and my party is moved to the coordinates i paste from the toolset.
I thought at first that may be my placeable wasn't created because it could be spawn at a "non safe" place so i tried coordinates where the player can actually walk on and where there is nothing else. Still doesn't work.

Any ideas of what is going wrong ?

About the function createobject, does bSpawnActive has to be set ?

By the way, about coordinates, what is the "f" for ? (in vector) and can the "z" coordinates be different from 0.0 (as my door is about at 1.0 height) ?

Modifié par princecorg, 08 novembre 2010 - 07:33 .


#13
_L_o_B_o_

_L_o_B_o_
  • Members
  • 117 messages

princecorg wrote...
About the function createobject, does bSpawnActive has to be set ?


Ah, that's a mistake due to copy-pasting of the line I first wrote to create the invisible placeble.

As you point, the placeable is not active, so you can't see it in your area. Use this line instead or change bSpawnActive to TRUE:

CreateObject(OBJECT_TYPE_PLACEABLE, MY_TO_AREA_B_PLACEABLE_RES, lMyToAreaBPlaceableLocation);

princecorg wrote...
By the way, about coordinates, what is the "f" for ? (in vector) and can the "z" coordinates be different from 0.0 (as my door is about at 1.0 height) ?


That "f" is used for floating-point constants. In other programming languages like C++, the value 2.5 is by default stored as a double (which is another data type that requires more memory). If you use 2.5f it is stored as a float. I'm not sure what the difference is in the scripting language used in the toolset, but I think that it is the same thing.


You can use z coordinates different from 0.0, don't worry for that :)

Modifié par _L_o_B_o_, 08 novembre 2010 - 10:25 .


#14
princecorg

princecorg
  • Members
  • 67 messages
You're right. I didn't even see that you have changed the function.

I'll try as soon as i come back from work.

#15
princecorg

princecorg
  • Members
  • 67 messages
It works !



_L_o_B_o_, your help has been more than useful, you should consider proposing your script to the Wiki.