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 .