No categories assigned

ContentDesigner:Adding Queest Function

Revision as of 15:59, 26 September 2015 by Cynnar (talk | contribs)

ContentDesigner:SpawnScripts - Calling Quests

Return to: ContentDesigner:SpawnScripts | Tutorials | Portal | Forum | Project Manager | Bug Tracker


Every NPC that offers a quest needs to have two things. One is a variable that is assigned to the quest ID. Two is the OfferQuest function. The following code below is taken from Verex N'Za, and can be found in his script VerexNZa.lua.


Assign Quest ID to a Local Variable

The very first thing that has to be done is to assign the quest ID to a local variable. This will be inserted just below the comments section.

Comments Section with quest variable

--[[
Script Name : <script-name>
Script Purpose : <purpose>
Script Author : <author-name>
Script Date : 9/7/2015
Script Notes : <special-instructions>
--]]

local ASolidifiedFront = 120

A breakdown of the new line local ASolidifiedFront = 120.

Starting off we use the word local to let the script know that this variable is to be used in this script only, and no where else.

Next I gave the variable the name ASolidifiedFront. This can be anything you want, but it is better to name it after the quest you are wanting to offer. This makes the script easier to understand, and is required if submitting to the server.

As you can see here it is easy to tell that the quest here is A Solidified Front.

The variable ASolidifiedFront has to be assigned to the quest ID. This way when the function sees the variabl ASolidifiedFront in the code it will know what quest to look for. Here it is set to 120 and is the quest ID of A Solidified Front.

To get the quest ID you can log on to the web database editor and find it under the quest section. If you are working on a local, or private, server you will need to look in your database.

If the NPC has multiple quest you would simply add another line with that Quests name for the variable and assign the quest ID to it.


Quest Function

We need to add a new function to our script. Choose a name for this function that will resemble what you want to accomplish like QuestOffer.

Setting up a quest function is similar to adding a chat function. For a refresher on adding chat functions refer to creating conversations page located near the bottom.

Quest Function

function QuestOffer(NPC, Spawn)
    if not HasQuest(Spawn, ASolidifiedFront) then
        OfferQuest(NPC, Spawn, ASolidifiedFront)
    else
        dlg_0_4(NPC, Spawn)
    end
end

This function has a check to see if the player has the quest or not. This particular check uses the if/else statement.

We want to know if our player has the quest ASolidifiedFront or not, and to respond appropriately.

if not HasQuest(Spawn, ASolidifiedFront) then

When doing a check start the code with if.


If they don't then the NPC will offer the player the quest. If they do then the NPC will continue on with the conversation. Theses checks can be done using the if/else statement.

OfferQuest(NPC, Spawn, ASolidifiedFront)

This line is the actual code that is used to call a quest. If we look at the above example and wanted to remove the checks then the function would look like this.

function QuestOffer(NPC, Spawn)
    OfferQuest(NPC, Spawn, ASolidifiedFront)
end

If you have read the creating conversations guide then it should be easy to tell what this line of code is doing. I am breaking the line down so I can point a few thing out.

We use the function OfferQuest to tell the server that there is a quest that needs to be presented to the player.

In the parameters we put NPC because we want the NPC to give the quest out. Next we use Spawn so the NPC knows who to give the quest to. In this case it is the player.

The last parameter is looking for a quest ID. Since we declared ASolidifiedFront at the top of the script to 120 we can use our variable in place of the quest ID.

When adding multiple quest you would add another function. We cannot call this function QuestOffer because the script will look for QuestOffer and call that function. So we would get the quest A Solidified Front instead of our new quest. Since we created QuestOffer to be a function, we can change the word QuestOffer to what ever we want so long as you use the same word in the conversation to call that function.

It may be easier to name your function after the quest when you have multiple quest. Examples are QuestOffer_ASolidifiedFront or Offer_ASolidifiedFront.