Would it be possible to make a journal entry automatically update based on the value of a variable?
For example, a quest requires the PC to kill 3 goblins. I created three goblins, and for each in the OnDeath script I put the following (courtesy of Lilac Soul’s generator):
void main()
{
object oPC = GetLastKiller();
while (GetIsObjectValid(GetMaster(oPC)))
{
oPC=GetMaster(oPC);
}
if (!GetIsPC(oPC)) return;
int nInt;
nInt = GetLocalInt(oPC, "KilledGoblin");
nInt += 1;
SetLocalInt(oPC, "KilledGoblin", nInt);
}
Is there a way to make the journal entry automatically update as soon as the variable “KilledGoblin” = 3?
Thanks!
In the same script you can check if pc has quest and quest state is the necessary and variable is >2 after updating it, and then update the quest state.
1 Like
Thanks Baireswolf. Would it be possible to show what that code might look like? I’m not at the level yet where I can write it out from scratch.
Journal entry name would be “Kill3Goblins”
I think I’m most of the way there now. The part at the end will update the journal upon killing 3 goblins. I just need to work in how to check for the PC having the quest to begin with:
void main()
{
object oPC = GetLastKiller();
while (GetIsObjectValid(GetMaster(oPC)))
{
oPC=GetMaster(oPC);
}
if (!GetIsPC(oPC)) return;
int nInt;
nInt = GetLocalInt(oPC, "KilledGoblin");
nInt += 1;
SetLocalInt(oPC, "KilledGoblin", nInt);
if (GetLocalInt(oPC, "KilledGoblin")== 3)
{
AddJournalQuestEntry("Kill3Goblins", 2, oPC, TRUE, FALSE);
}
}
Checking to see if the PC has the quest active should only require a little editing of your script:
void main()
{
object oPC = GetLastKiller();
while (GetIsObjectValid(GetMaster(oPC)))
{
oPC=GetMaster(oPC);
}
if (!GetIsPC(oPC)) return;
int nInt;
nInt = GetLocalInt(oPC, "KilledGoblin");
nInt += 1;
SetLocalInt(oPC, "KilledGoblin", nInt);
if ((GetLocalInt(oPC, "KilledGoblin") == 3) && ( GetLocalInt(oPC, "NW_JOURNAL_ENTRYKill3Goblins") == 1 ))
{
AddJournalQuestEntry("Kill3Goblins", 2, oPC, TRUE, FALSE);
}
}
Fair warning, however: this check will only run upon killing a goblin, so if the PC has already killed those goblins before accepting the quest, they will be unable to advance the quest. You may want to have those three goblins spawn as part of a respawning encounter, depending on what your module will be like.
1 Like
Thanks Protoss, looks like everything works now. The sticking point for me was figuring out how to have multiple “if” conditions at once.
And point taken about the timing of the quest and the encounter.
This was my first time asking for help and it was great to get helpful replies so quickly. Really appreciate having such a supportive community here.
Another thing to note is that, if you do decide to go with the respawning goblins route, then if the player has already killed three or more goblins prior to accepting the quest, then KilledGoblin might be well over 3, meaning the quest won’t update no matter how many goblins the player kills. For that reason, I recommend having the script increase the KilledGoblin integer only when they have the quest:
void main()
{
int nValue;
// Get the creature who triggered this event.
object oPC = GetLastKiller();
// We are really interested in the ultimate master of the killer.
while ( GetMaster(oPC) != OBJECT_INVALID )
oPC = GetMaster(oPC);
// If the PC is exactly at stage 1 of journal quest "Kill3Goblins".
if ( GetLocalInt(oPC, "NW_JOURNAL_ENTRYKill3Goblins") == 1 )
{
// Set a local integer.
nValue = GetLocalInt(oPC, "KilledGoblin") + 1;
SetLocalInt(oPC, "KilledGoblin", nValue);
// If the local int is exactly 3.
if ( GetLocalInt(oPC, "KilledGoblin") == 3 )
{
// Update the player's journal.
AddJournalQuestEntry("Kill3Goblins", 2, oPC, FALSE);
}
}
}
This way, even if the player has killed goblins beforehand, they still need to kill 3 more upon accepting the quest in order for the quest to update. Otherwise, you can change the LocalInt requirements to 3 or more rather than 3 exactly:
if ((GetLocalInt(oPC, "KilledGoblin") >= 3) && ( GetLocalInt(oPC, "NW_JOURNAL_ENTRYKill3Goblins") == 1 ))
{
AddJournalQuestEntry("Kill3Goblins", 2, oPC, TRUE, FALSE);
}
This means the player only has to kill one more goblin for the quest to update, if they’ve killed goblins prior. Up to you if you want to go that route.
1 Like
You can also use the journal to track the number of killed Goblins like this
In the text of the journal entry while on the quest:
“You have killed < CUSTOM6611 > goblins sofar.” (remove space before C and after 1, don’t know why it wont let my post it)
Then in the goblins death script you put:
int nInt;
nInt = GetLocalInt(oPC, “KilledGoblin”);
nInt += 1;
SetLocalInt(oPC, “KilledGoblin”, nInt);
SetCustomToken(6611, IntToString(nInt));
Now the journal entry should show how many goblins you have killed.
/Pap
1 Like
Strings delimited as < > will display correctly in a code block:
You have killed <CUSTOM6611> goblins so far.
2 Likes