ff_c_act_journal
Dialog action adding a quest state to, or saving, the journal of the speaking PC.
With QUEST and JOURNAL_ID set, the quest state is added to the PC’s journal
with AddJournalQuestEntryEx(), which saves it. The state is only added if it
is higher than the PC’s current state for the quest: the current journal state is
never overwritten by a lower one.
Without parameters, set this script as the action of a dialog node that adds or updates
a journal entry from the node’s Journal tab, so the entry is persisted like one added
with AddJournalQuestEntryEx(). The save is delayed slightly, since the engine
applies the node’s journal entry after the action script runs.
Scripts
ActionsTaken: ff_c_act_journal
Variables
QUEST: (string) Tag of the journal category.
JOURNAL_ID: (int) Journal entry ID.
Source code
// @code
#include "ff_i_core"
// -----------------------------------------------------------------------------
//! @brief Save the journal of oPC.
//! Wrapper so SaveJournal() can be delayed: DelayCommand needs a void function.
//! @param oPC The PC.
void _SaveJournal(object oPC)
{
SaveJournal(oPC);
}
// -----------------------------------------------------------------------------
void main()
{
object oPC = GetPCSpeaker();
if (!GetIsPC(oPC))
return;
string sQuest = GetScriptParam("QUEST");
string sState = GetScriptParam("JOURNAL_ID");
// Journal tab of the dialog node.
if (sQuest == "" && sState == "")
{
DelayCommand(0.5f, _SaveJournal(oPC));
return;
}
int nState = StringToInt(sState);
if (sQuest == "" || nState <= 0)
{
LogError(__FILE__ + ": called with invalid 'QUEST' or 'JOURNAL_ID' value");
return;
}
// Do not overwrite the current journal state.
if (GetJournalQuestState(sQuest, oPC) >= nState)
return;
LogDebug(__FILE__, GetPCInfo(oPC) + " journal " + sQuest + " set to " + IntToString(nState));
AddJournalQuestEntryEx(sQuest, nState, oPC, FALSE);
}