ff_u_pc_export

Export the PC to servervault on key moments such as resting.

Variables

ENABLE__FF_U_PC_EXPORT: (string) (opt-out) Set to “N” to disable unit.

Source code

// @code
#include "ff_i_core"

const string ENABLE__FF_U_PC_EXPORT = "ENABLE__FF_U_PC_EXPORT";


// -----------------------------------------------------------------------------

//! @brief Export oPC to the server vault and log the event.
//! @param oPC A player character.
//! @param sEvent Name of the triggering event (for log context).
void ExportCharacter(object oPC, string sEvent)
{
  if (!GetIsPC(oPC))
    return;

  ExportSingleCharacter(oPC);
  LogInfo(GetPCInfo(oPC) + " was exported");
}


// -----------------------------------------------------------------------------

void main()
{
  if (!GetModuleFlag(ENABLE__FF_U_PC_EXPORT, TRUE))
    return;

  // In case PC is in combat for a long duration, no saving will be done, so save after combat.
  // https://discord.com/channels/382306806866771978/995637334919893082/1464282628155773115
  // "+ schedule another auto-save shortly after otherwise you might get cases where no save has happened for hours or longer if that characters is always in combat just when the save is going to happen"
  string sEvent = GetCurrentEvent();
  if (sEvent == ON_REGISTER)
  {
    SubscribeToEvent(ON_DEFAULT_PC_REST_START, __FILE__);
    SubscribeToEvent(ON_DEFAULT_PC_LEVELUP, __FILE__);
    SubscribeToEvent(ON_DEFAULT_PC_DEATH, __FILE__);
    SubscribeToEvent(ON_DEFAULT_PC_DYING, __FILE__);
    SubscribeToEvent(ON_DEFAULT_PC_RESPAWN, __FILE__);
    SubscribeToEvent(ON_DEFAULT_AREA_EXIT, __FILE__);
    SubscribeToEvent(ON_AFTER_COMBAT_EXIT, __FILE__);
  }
  else if (sEvent == ON_DEFAULT_PC_REST_START)
    ExportCharacter(GetLastPCRested(), sEvent);
  else if (sEvent == ON_DEFAULT_PC_LEVELUP)
    ExportCharacter(GetPCLevellingUp(), sEvent);
  else if (sEvent == ON_DEFAULT_PC_DEATH)
    ExportCharacter(GetLastPlayerDied(), sEvent);
  else if (sEvent == ON_DEFAULT_PC_DYING)
    ExportCharacter(GetLastPlayerDying(), sEvent);
  else if (sEvent == ON_DEFAULT_PC_RESPAWN)
    ExportCharacter(GetLastRespawnButtonPresser(), sEvent);
  else if (sEvent == ON_DEFAULT_AREA_EXIT)
    ExportCharacter(GetExitingObject(), sEvent);
  else if (sEvent == ON_AFTER_COMBAT_EXIT)
    ExportCharacter(OBJECT_SELF, sEvent);
}