Tutorial: Scripting Quest Completion

For all talk about quests. Creating, testing, bugs, and development progress.
Post Reply
User avatar
Interkarma
Posts: 3178
Joined: Sun Mar 22, 2015 1:51 am

Tutorial: Scripting Quest Completion

Post by Interkarma » Fri Jul 14, 2017 10:55 pm

Properly ending a quest is a common issue in Daggerfall's quest scripts. Because Daggerfall Unity is running the same scripts as classic Daggerfall, these scripting errors can occur in both.

To see this problem in action, accept quests from the Fighters Guild then immediately speak to the quest giver once again. Many of their scripts will immediately give player a reward, even though you haven't moved from the spot. Not all quests have this problem, but many of the Fighters Guild quests do experience it.

So I thought I'd put together a quick tutorial on how to properly script quest completion. Let's start with an example of a bad quest script from M0B00Y06.

Code: Select all

_S.02_ task:
	clicked npc _qgiver_ 
	give pc _gold_ 
	end quest 
	
_clearclick_ task:
	when _S.02_ and not _S.01_ 
	clear _S.02_ _clearclick_ 
The error is happening in S.02, which has a single trigger condition "clicked npc _qgiver_". The moment you click on the quest giver, this task will be executed whether you've completed the quest or not.

You'll note there's a _clearclick_ task which is supposed to be checking for quest completion and clearing the click, but it doesn't matter because S.02 has already been executed.

Here's the correct way to script a quest ending, from CUSTOM01.

Code: Select all

_questorClicked_ task:
	clicked npc _questgiver_

_clearclick_ task:
	when _questorClicked_ and not _necromancerDead_
	clear _questorClicked_ _clearclick_

_rewardPlayer_ task:
	when _questorClicked_ and _necromancerDead_
	give pc _reward_
	end quest
There are three parts to this:
  1. _questorClicked_ task picks up the click on quest giver.
  2. _clearclick_ task checks the quest ending condition(s) and clears both _questorClicked_ and itself when quest not completed.
  3. _rewardPlayer_ task will check both _questorClicked_ and quest ending condition(s) and only then gives player their reward and end quest.
All of these parts are important. If you didn't clear the click in step 2, player would get the reward as soon as the necromancer was killed later, instead of when returning to quest giver. If you don't separate out the click check and the reward process, then both of these things happen at the same time. If _clearclick_ doesn't also clear itself, then it won't be rearmed for next time.

Many of these quest scripts will need to be fixed eventually. Fortunately this is an easier job now everything is in plain text and people can send a PR.

For now though, I'm happy to have the same bugs as classic Daggerfall because these problems actually help me confirm my quest engine is properly emulating classic - because the same bad script behaviours are present in both. :)

Post Reply