ff_u_pc_locstart
Move starting point to waypoint.
If in debug, and a waypoint called “WP_MODULE_START” exists, then the starting point will be moved to that location.
This enables moving easily the waypoint, but without touching the “official” starting point, which also kind of often crashes the toolset.
When resting or entering an area with a variable called “PLAYER_SAVE_LOCATION”, then the location of PC will be saved and PC will login into that area.
Variables
ENABLE__FF_U_P_LOCSTART: (string) (opt-out) Set to “N” to disable unit.
SAVE_PLAYER_LOCATION: (int) Set to 1 on area to save on enter and rest
Source code
// @code
#include "ff_i_core"
const string ENABLE__FF_U_P_LOCSTART = "ENABLE__FU_P_LOCSTART";
const string WP_MODULE_START = "WP_MODULE_START";
const string SAVE_PLAYER_LOCATION = "SAVE_PLAYER_LOCATION";
// -----------------------------------------------------------------------------
//! @brief Persist oPC's current location if the area has SAVE_PLAYER_LOCATION set.
//! @param oPC A player character.
void SaveLocation(object oPC);
void SaveLocation(object oPC)
{
if (!GetIsPC(oPC))
return;
object oArea = GetArea(oPC);
if (!GetIsObjectValid(oArea))
return;
if (GetLocalInt(oArea, SAVE_PLAYER_LOCATION) == 0) // FIXME
return;
location locSave = GetLocation(oPC);
string sArea = GetTag(GetAreaFromLocation(locSave));
NWNX_Object_SetString(oPC, ENABLE__FF_U_P_LOCSTART + "_AREA", sArea, TRUE);
NWNX_Object_SetFloat(oPC, ENABLE__FF_U_P_LOCSTART + "_POSITION_X", GetPositionFromLocation(locSave).x, TRUE);
NWNX_Object_SetFloat(oPC, ENABLE__FF_U_P_LOCSTART + "_POSITION_Y", GetPositionFromLocation(locSave).y, TRUE);
NWNX_Object_SetFloat(oPC, ENABLE__FF_U_P_LOCSTART + "_POSITION_Z", GetPositionFromLocation(locSave).z, TRUE);
NWNX_Object_SetFloat(oPC, ENABLE__FF_U_P_LOCSTART + "_FACING", GetFacingFromLocation(locSave), TRUE);
LogInfo(GetPCInfo(oPC) + " location was exported for " + sArea);
}
// -----------------------------------------------------------------------------
//! @brief Set oPC's spawn location to the previously saved persistent location, or the default.
//! @param oPC A player character.
void LoadLocation(object oPC);
void LoadLocation(object oPC)
{
if (!GetIsPC(oPC))
return;
// Set the default
NWNX_Player_SetSpawnLocation(oPC, GetStartingLocation());
// If in debug, send to testing location
if (GetIsDebug())
{
object oWP = GetObjectByTag(WP_MODULE_START);
if (GetIsObjectValid(oWP))
{
LogInfo(GetPCInfo(oPC) + " will spawn in debug (WP_MODULE_START) location");
NWNX_Player_SetSpawnLocation(oPC, GetLocation(oWP));
return;
}
}
string sArea = NWNX_Object_GetString(oPC, ENABLE__FF_U_P_LOCSTART + "_AREA");
object oArea = GetObjectByTag(sArea);
if (!GetIsObjectValid(oArea))
{
LogInfo(GetPCInfo(oPC) + " will spawn in default module location");
return;
}
float fX = NWNX_Object_GetFloat(oPC, ENABLE__FF_U_P_LOCSTART + "_POSITION_X");
float fY = NWNX_Object_GetFloat(oPC, ENABLE__FF_U_P_LOCSTART + "_POSITION_Y");
float fZ = NWNX_Object_GetFloat(oPC, ENABLE__FF_U_P_LOCSTART + "_POSITION_Z");
float ff = NWNX_Object_GetFloat(oPC, ENABLE__FF_U_P_LOCSTART + "_FACING");
location locSpawn = Location(oArea, Vector(fX, fY, fZ), ff);
LogInfo(GetPCInfo(oPC) + " will spawn in persistent starting waypoint in area " + sArea);
NWNX_Player_SetSpawnLocation(oPC, locSpawn);
}
// -----------------------------------------------------------------------------
void main()
{
if (!GetModuleFlag(ENABLE__FF_U_P_LOCSTART, TRUE))
return;
string sEvent = GetCurrentEvent();
if (sEvent == ON_REGISTER)
{
SubscribeToEvent(ON_BEFORE_PC_ELC, __FILE__);
SubscribeToEvent(ON_DEFAULT_AREA_ENTER, __FILE__);
SubscribeToEvent(ON_DEFAULT_PC_REST_STOP, __FILE__);
}
else if (sEvent == ON_BEFORE_PC_ELC)
LoadLocation(OBJECT_SELF);
else if (sEvent == ON_DEFAULT_AREA_ENTER)
DelayCommand(1.0f, SaveLocation(GetEnteringObject()));
else if (sEvent == ON_DEFAULT_PC_REST_STOP)
SaveLocation(GetLastPCRested());
}