aboutsummaryrefslogtreecommitdiff
path: root/gamemode/core/quests/quest.lua
blob: ed5ec5741965e3ceb82137997174e184a8ac4846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
--[[
	Ease of use functions for generating quests
]]

--[[
	local quest = {
		q.MakeArc("TalkArc",Entity(24),"Talk to Jared The Brutal","Rats...","I JARED THE BRUTAL. YOU THINK YOU TOUGH? GO KILL 10 RATS!!!"),
		q.MakeArc("KillArc","Rat",10)
		q.MakeArc("TalkArc",Entity(24),"Talk to Jared The Brutal","I kill 10 rats.","HOLY SHIT, YOU KILL 10?? GOOD. YOU BRUTAL NOW. HERE IS REWARD.")
	}
	local reward = function(ply)
		for i=1,10 do
			pcall(function()
				ply:GiveItem("Rat Meat")
			end,function()

			end)
		end
		ply:AddSkill("Hunting",20)
	end
	local Killquest = q.GenerateQuest(quest,reward)
]]

nrequire("itemsystem/quest.lua")
local itm = nrequire("item.lua")
local log = nrequire("log.lua")
local arc = nrequire("arcs.lua")
local typ = nrequire("type.lua")
local q = {}

-- Generates an item that represents a quest
function q.GenerateQuest(questname,arcstbl,rewards)
	typ.checktypes(
		questname,"string",
		arcstbl,"table",
		rewards,"table"
	)
	local q = itm.GetItemByName("Quest")
	q.QuestName = questname
	q.Arcs = arcstbl
	for k,v in pairs(arcstbl) do
		v.Quest = q
	end
	q.Reward = rewards
	return q
end

if SERVER then
	concommand.Add("artery_gen_test_quest",function(ply,cmd,args)
		print("Generating a test quest")
		local qu = {
			arc.MakeArc("Quest Component Gather",ply,"Test item", 3)
		}
		local reward = {
			{"Test item", 1}
		}
		local kq = q.GenerateQuest("My test quest",qu,reward)
		kq.Owner = ply
		xpcall(function()
			ply:GiveItem(kq)
		end,function(err)
			log.error("Failed to add quest:" .. err)
			log.error(debug.traceback())
		end)
	end)
end

return q