About Quests

When working with quests, you need to understand and modify lua scripts. You need to understand or create the map in question so you can use specific zones and markers, as well as NPC Entity information. You can learn about maps in the CreateYourFirstMap tutorial.

You keep track of the progress of a player's quest by using quest variables. Note that when coding/scripting a game, the word "quest" doesn't necessarily mean the same thing as it does to a player. A player thinks of a quest as a long task. To a coder, a quest can be as simple as turning a light on or off. The light starts as off, and then the player turns it on. Now the quest is "completed." A quest is actually just a variable that gets retained across maps and is saved when the player saves their game.

Quest variables have two parts, the quest identifier, and the quest value. The quest identifier is a fixed constant that identifies a particular quest. In this tutorial, there are two quests, and therefore two quest constants. One is named P_STARTED_NEW, and the other P_WELCOMING_PARTY. Each quest also has an integer value. The value always starts at 0 for a new game. When the player saves and loads his game, this value is retained.

Old quest identifiers were set in progress.h, in the include directory. They are now set in global.lua. Right now, either place will work, but progress.h may be eliminated in the future. Adding a quest identifier is as simple as opening global.lua, and adding the following line, after the other quest identifiers:
P_STARTED_NEW = 200

Notice that I set the identifier to 200. (Do not confuse this with the quest value. We haven't gotten there yet.) The identifier is an arbitrary number. You can set the number to anything from 0 to 1000. Just make sure that this number is unique to this quest. KQ currently uses identifiers up to around 120. Don't add any identifiers less than that if you want to add your script/map to the official KQ client.

Now that I have explained quest identifiers, I will now explain quest values, and how to set them. When the player starts a new game, the value of every quest, such as P_STARTED_NEW starts at 0. Now suppose that the player has done something to further along this quest. When that happens, you want to keep track of this by setting the value of P_STARTED_NEW to something else. To set the value of this quest to something else, use the function, set_progress(). The syntax of set_progress is set_progress(quest_id, value). For example:
set_progress(P_STARTED_NEW, 1)

Now the value of P_STARTED_NEW is 1. Later, if you want to retrieve the value of P_STARTED_NEW, use the function, get_progress(). For example:

if (get_progress(P_STARTED_NEW) > 0)
  -- The player has started the P_STARTED_NEW quest
end

Examples

Now for a couple of examples. Remember that you place script code, such as quests, in the following functions:

function autoexec()
function postexec()
function entity_handler(en)
function zone_handler()

Note that there is no map file that accompanies these scripts. However, assuming that you have read CreateYourFirstMap, you have the skills to create the map yourself. Consider it an exercise and a test to create a map to accompany these scripts. The tiles can be simple. You need two entities, one with ID 0 and one with ID 1. You do not need to place any zones, but you do need a marker titled "entrance." Also, remember that a full script file must have each of the four functions mentioned above, autoexec(), postexec(), etc. If you do not use these functions, create empty ones.

Example 1

The following demonstrates a simple method, using quests, to show an intro dialog to the player. When you first enter the map, you want to immediately hear the intro dialog. Some Entity will be talking to you, but only if you haven't heard the speech before. If you have, you will skip that speech.


function postexec()
  if (get_progress(P_STARTED_NEW) == 0) then
    -- You have not had this "intro talk" yet
    bubble(0, "Hello, people. You are listening to the intro talk. Please talk to everyone.")

    -- Now you have heard it, so you can set the flag so you don't have to hear it each time you enter the map
    set_progress(P_STARTED_NEW, 1)
  end
end

That's it!

Example 2

Okay, so now we want to talk to some guy on the screen (his ID# is 1) who welcomes you to town. He says things differently the second time you talk to him. Note that this example uses the not yet mentioned functions set_gp() and get_gp(). The functions are very much like set_progress() and get_progress(), but they set and get the user's gold count.




There you have it. You should now be able to write simple quests that you can talk to people, have them go to different towns, and be able to use the P_* progress markers (quest identifiers) to show when you've performed some certain task or not.


Page hosted by
SourceForge
Vote for us!
Vote for the RPG top 50
Gaming HTML standards
Valid XHTML 1.0!