aboutsummaryrefslogtreecommitdiff
path: root/gamemode/questsystem/component_kill.lua
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2018-11-03 18:23:45 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2018-11-03 18:23:45 -0400
commit28affa22541b9ef251707793f6b1c1a26d663592 (patch)
tree622754894d75c74dc5e8516ccf184ad4bf328fef /gamemode/questsystem/component_kill.lua
parentc639e7c7c6ab1595fdce39f56312e3d6a886bbe8 (diff)
downloadartery-28affa22541b9ef251707793f6b1c1a26d663592.tar.gz
artery-28affa22541b9ef251707793f6b1c1a26d663592.tar.bz2
artery-28affa22541b9ef251707793f6b1c1a26d663592.zip
Started on new npc system
Started work on the new npc system
Diffstat (limited to 'gamemode/questsystem/component_kill.lua')
-rw-r--r--gamemode/questsystem/component_kill.lua67
1 files changed, 67 insertions, 0 deletions
diff --git a/gamemode/questsystem/component_kill.lua b/gamemode/questsystem/component_kill.lua
index 3925a12..b1ffa71 100644
--- a/gamemode/questsystem/component_kill.lua
+++ b/gamemode/questsystem/component_kill.lua
@@ -1,3 +1,70 @@
--[[
Something to stop gmod from freaking out
]]
+if SERVER then
+ inv = nrequire("sv_invtracker.lua")
+end
+local log = nrequire("log.lua")
+
+local quests = {}
+local comp = {}
+
+comp.Name = "Quest Component Kill"
+comp.kills = 0
+comp.npcname = "Init not yet called"
+
+function comp:Update()
+ self.Quest:UpdateCompleted()
+end
+
+function comp:Complete()
+ if self.kills >= self.numkills then
+ log.debug("Completed a gather arc of a quest!")
+ end
+ return self.items >= self.ItemNumber
+end
+
+function comp:Init(ply,npcname,numkills)
+ if not ply or not itemname or not itemnumber then log.error("Tried to create a kill arch for a quest without correct arguments") end
+ self.npcname = itemname
+ self.kills = 0
+ self.numkills = 0
+ if CLIENT then return end
+ self.Owner = ply
+ -- self:Update()
+ quests[#quests + 1] = self
+end
+
+--[[
+Detour the player's GiveItem(), to check if the quest is
+complete after giving the player the item
+]]
+if SERVER then
+ local plymeta = FindMetaTable("Player")
+ local det = plymeta.GiveItem
+ function plymeta:GiveItem(tbl)
+ det(self,tbl)
+ log.debug("Calling component_gather's GiveItem()")
+ for k,v in pairs(quests) do
+ if v.Name == comp.Name and v.ItemName == tbl.Name then
+ v:Update()
+ end
+ end
+ end
+end
+
+function comp:GetText()
+ return string.format("Gather %s %s",self.ItemNumber,self.ItemName)
+end
+
+function comp:Serialize()
+ return util.TableToJSON({self.ItemName,self.ItemNumber})
+end
+
+function comp:DeSerialize(data)
+ local tbl = util.JSONToTable(data)
+ self.ItemName = tbl[1]
+ self.ItemNumber = tbl[2]
+end
+
+nrequire("core/quests/arcs.lua").RegisterArc(comp)