No categories assigned

ContentDesigner:Adding Queest Function

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. This allows our script to do something if conditions are met, and if the conditions are not met do something different.

What we want this check to accomplish is to see if the player has the quest A Solidified Front. If he/she does not have the quest then offer it to them. If he/she has the quest then do not off the quest and go to a new dialog function.

if not HasQuest(Spawn, ASolidifiedFront) then

When you look at this part of the code you can see it starts with the keyword if. All our if statements will always use the keyword if to start the function.

Next we use the word not. It is also a check, and is used in conjunction with a lua function like HasQuest. This reads does not have quest.

For the parameters we have Spawn, and ASolidifiedFront. Spawn is who the check is to be preformed on. ASolidifiedFront is the quest ID of the quest to check against.

ASolidifiedFront is used in place of the quest ID here. The code will execute properly because at the top of the script we set ASolidifiedFront to store the value 120, and that is our quest ID.

We finish up with the keyword then. This has to be at the end or the code will not work. This makes sense because if conditions are met then execute this code.

Now when the NPC is hailed and reaches this part of the script it will check if player does not have quest A Solidified Front then, and what do we want it to do?

That's right we want it to offer a quest. Who do we want offering the quest? The NPC. Who is it being offered to? The Spawn. What quest is being offered? ASolidifiedFront. So we use the OfferQuest function like this.

OfferQuest(NPC, Spawn, ASolidifiedFront)

Now that the player is offered the quest the script will skip the next check, else, and look for the if statement to be closed with end. Just like the function has to be closed with end so does the if statement.

Since there is only the code for the if statement in our function this is all that is executed and will finish when reaching end.

If the player has the quest we sure don't want the NPC to offer it again. This is where the else comes into play.

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.