Posted by
| Nick Gammon
Australia (23,068 posts) Bio
Forum Administrator |
Message
| This post describes how to set up tasks in the Lua-based task system.
Tasks are stored in a file tasklist.lua.
Inside that file are the definitions for the all_tasks table. This is a table of all possible tasks (that a player might eventually do, be currently doing, or have done previously).
A minimal definition would be:
That defines no tasks. Now we can add entries for each task, like this:
all_tasks.academy1 = {
-- task definition here
} -- end academy1 task
all_tasks.academy2 = {
-- task definition here
} -- end academy2 task
Each task is its own table, with fields as described below. Tasks have an identifying "task id" which is the table key (eg. "academy1"). Tasks IDs should be in lower case as player input is forced to lower case. If you make an upper-case ID it won't be found. I will put commas after each field example, as that is how they would appear in the table definition.
- name - Summary to show in task list (keep to below about 50 characters) (required). eg.
name = "Find teacher Domick",
- description - Multiple line description of task purpose. eg.
description = [[
Mistress Tsythia wants you to visit Domick in The Laboratory of Skills
and Spells.
Please give him this note ('&Ygive note domick&W').]],
- giver - vnum of task giver mob (required). eg.
giver = 10399, -- vnum of task giver: Mistress Tsythia
- receiver - vnum of task to receive the task hand-in. If omitted, task received by task-giver. eg.
receiver = 10340, -- vnum of task receiver: Domick
- min_level - minimum level you need to be to see this task. If omitted, no minimum level.
This is intended to stop low-level players being given ridiculously hard quests. eg.
min_level = 1, -- minimum level to attain task
- max_level - maximum level you can be to see this task. If omitted, no maximum level.
This is intended to stop high-level players being given ridiculously easy quests. eg.
max_level = 5, -- maximum level to attain task
- available - function that returns false if task is not available. If omitted, task is always available. You could test for completion of earlier tasks, player class, etc. eg.
-- is task available? (check prerequisites, class, etc.)
available = function ()
return completed_tasks.academy2 ~= nil -- have to do "academy2" task first
end,
- accept- function called when task is accepted. If omitted, nothing special is done. Return false if task can not be accepted (might return false if you need to put something in inventory, and it is full). eg.
-- do stuff for accepting (like put things in inventory)
accept = function ()
task_item (36) -- give player a note
end, -- end accept
- complete - function called when task is completed (finished / handed in). If omitted, nothing special is done. Return false if task can not be finished (might return false if you need to put something in inventory, and it is full). eg.
-- do stuff for completing (like task rewards)
complete = function ()
task_xp (20)
task_item (10308) -- a plate of armour
task_gold (100)
send ("&WDomick tells you: 'Good work!")
end, -- complete function
- abandon - function called when task is abandoned. If omitted, nothing special is done (might remove task items from inventory).
-- do stuff for abandoning (like removing task items - use with caution)
abandon = function ()
mud.destroy_item (10308) -- remove task item
end, -- end accept
- time_limit - time limit in minutes - task must be completed in that time (real time). If omitted, no time limit. eg.
time_limit = 10, -- time limit in minutes
- subtasks - table of subtasks which need to be completed - see below. If omitted, there are no subtasks, and task can be handed in immediately. Ssubtasks are keyed by number and are shown in order given.
Subtasks do not need to be completed in any particular order. If you want to arrange that the player does one thing and then another thing, make different tasks, and make the second task dependent on the first one.
Many subtasks have a 'count' - this lets you specify that they must "kill 5 mobs" or "obtain 10 items".
Subtasks
Each task consists of zero or more subtasks. Probably 1 to 3 subtasks would be normal for many tasks. When you do "show task" the current stage with each subtask is shown (eg. killed 3/5 mobs, obtained 1/10 items).
If you have no subtasks, then the task can be finished immediately. This would be useful if you are trying to get the player from one place to another. (eg. Mayor of Town A wants you to report to the Mayor of Town B).
- description - sub task description (keep reasonably short - probably 50 characters max). This should be a short phrase succinctly describing the subtask, without puctuation (eg. "Naga slain", "Bread purchased", "Sword repaired").
As the player works on the subtask a count is appended (eg. "Naga slain: 3/5").
- type - type of subtask - this is a string that indicates the events to look for to trigger a "subtask completed" message.
- killmob - must kill 'count' mobs in vnums table
- visitroom - must visit one of the rooms in the vnums table
- bribe - must bribe one of the mobs in the vnums table with 'count' coins
- give - must give 'count' objects of vnum 'item' to one of the mobs in the vnums table
- get - must get 'count' objects of vnum 'item' (into inventory)
- buy - must buy 'count' objects of vnum 'item'
- wear - must wear 'count' objects of vnum 'item'
- drop - must drop 'count' objects of vnum 'item'
- repair - must repair 'count' objects of vnum 'item'
- use - must use 'count' objects of vnum 'item'
- possess - must have 'count' objects of vnum 'item' in inventory
- count - number of items to get/buy/drop etc., count of mobs to kill, size of bribe. If omitted, defaults to 1.
- vnums - table of vnums of mobs (turned into vnum lookup table)
- item - vnum of item to get/buy/drop etc. (required, where applicable)
- complete - function that is called when this subtask is completed. If omitted, nothing special is done. This could be used to spawn additional mobs when a boss is killed, for example.
Difference between 'get' and 'possess'.
Subtask type 'get' counts when you obtain the item, even if you subsequently lose it. If the player drops an item and picks it up again this will count as two "gets".
Subtask type 'possess' counts possession of the item, giving it away before handing in will fail the subtask. "Possess" items are destroyed on task completion. The "possess" subtask type is more useful to make sure a player is obtaining items.
Vnum tables
Subtasks that use the "vnums" table item are designed to allow "fuzzy" tasks. In other words, if you need to "kill 5 naga" then the naga might be "bone naga" or "naga mages". Thus you might put the vnums for both of them in the vnums table.
Example subtasks
The subtask below requires the player to have in their inventory 5 loaves of bread:
subtasks = { -- table of sub tasks
{ -- subtask 1
description = "Bread obtained",
type = "possess",
item = 21021, -- A loaf of bread
count = 5,
}, -- end subtask
}, -- end subtasks table
The subtask below requires the player to purchase one piece of meat:
subtasks = { -- table of sub tasks
{ -- subtask 1
description = "Meat purchased",
type = "buy",
item = 10317, -- Dried rabbit meat
}, -- end subtask
}, -- end subtasks table
} -- end of task academy5
Below are three subtasks, to kill various mobs:
subtasks = { -- table of sub tasks
{ -- subtask 1
description = "Naga slain",
type = "killmob",
vnums = { 10302 }, -- The bone naga
count = 5,
}, -- end subtask 1
{ -- subtask 2
description = "Wolf slain",
type = "killmob",
vnums = { 10300 }, -- The dread wolf
count = 10,
}, -- end subtask 2
{ -- subtask 3
description = "Carrior crawler slain",
type = "killmob",
vnums = { 10303 }, -- A carrion crawler
count = 8,
}, -- end subtask 3
}, -- end subtasks table
Example of a complete task
all_tasks.academy4 = {
-- name of task - shown in task list
name = "Getting your hands dirty",
-- description - shown when you do "task show x"
description = [[
Mistress Tsythia would like you to head for the battlegrounds, and
kill 4 wolves, 3 naga and 2 carrion crawlers.
Your reward for doing this is 1000 gold.
]],
giver = 10399, -- vnum of task giver: Mistress Tsythia
-- receiver = 10399, -- vnum of task receiver: Mistress Tsythia
min_level = 1, -- minimum level to attain task
max_level = 5, -- maximum level to attain task
time_limit = nil, -- time limit in minutes
-- it task available? (check prerequisites, class, etc.)
available = function ()
return completed_tasks.academy3 ~= nil
end,
-- do stuff for accepting (like put things in inventory)
accept = function ()
end, -- end accept
-- do stuff for abandoning (like removing task items)
abandon = function ()
end, -- end accept
-- do stuff for completing (like task rewards)
complete = function ()
task_xp (5000)
task_gold (1000)
end, -- complete function
-- table of subtasks
-- each subtask is its own table
-- required fields: description / type
subtasks = { -- table of sub tasks
{ -- subtask 1
description = "Naga slain",
type = "killmob",
vnums = { 10302 },
count = 3,
}, -- end subtask
{ -- subtask 2
description = "Wolf slain",
type = "killmob",
vnums = { 10300 },
count = 4,
}, -- end subtask
{ -- subtask 3
description = "Carrior crawler slain",
type = "killmob",
vnums = { 10303 },
count = 2,
}, -- end subtask
}, -- end subtasks table
} -- end of task academy4
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|