Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.05 KB | None | 0 0
  1. local Player = FindMetaTable("Player")
  2.  
  3. --The Quests from this point down have not been added to any npc yet, and probolly are under cunstruction
  4. local Quest = {}
  5. Quest.Name = "quest_gatherantlionshell"
  6. Quest.PrintName = "The Legendary Beast!"
  7. Quest.Story = "Hey! You! Yeah, you! I can help you. Have you ever heard of a beast called, the Antlion Guard!? I hear it has a shell as hard as rock! Bring me its shell, and i can make you a sheild. It wont be free tho. I'll need some cash too!"
  8. Quest.Level = 16
  9. Quest.ObtainItems = {}
  10. Quest.ObtainItems["antlion_shell"] = 1
  11. Quest.ObtainItems["money"] = 500
  12. Quest.GainedExp = 600
  13. Quest.GainedItems = {}
  14. Quest.GainedItems["armor_shield_antlionshell"] = 1
  15. Register.Quest(Quest)
  16.  
  17. function Player:AddQuest(strQuest, tblInfo)
  18.     if !ValidEntity(self) then return end
  19.     local tblQuestTable = QuestTable(strQuest)
  20.     if !self:GetQuest(strQuest) && tblQuestTable then
  21.         self.Data.Quests[strQuest] = {}
  22.         local tblNewQuestTable = {}
  23.         tblNewQuestTable.Done = false
  24.         for strNPC, intToKill in pairs(tblQuestTable.Kill or {}) do
  25.             tblNewQuestTable.Kills = tblNewQuestTable.Kills or {}
  26.             tblNewQuestTable.Kills[strNPC] = 0
  27.         end
  28.         self:UpdateQuest(strQuest, tblInfo or tblNewQuestTable)
  29.     end
  30. end
  31.  
  32. function Player:QuestItem(strItem)
  33.     local tblItemTable = ItemTable(strItem)
  34.     if !tblItemTable.QuestItem or self:GetQuest(tblItemTable.QuestItem) then
  35.         if !self:HasCompletedQuest(tblItemTable.QuestItem) then
  36.             return true
  37.         end
  38.         return false
  39.     end
  40.     return false
  41. end
  42.  
  43. function Player:HasCompletedQuest(strQuest)
  44.     if self:GetQuest(strQuest) && self:GetQuest(strQuest).Done then
  45.         return true
  46.     end
  47.     return false
  48. end
  49.  
  50. function Player:GetQuest(strQuest)
  51.     if !ValidEntity(self) then return end
  52.     self.Data.Quests = self.Data.Quests or {}
  53.     return self.Data.Quests[strQuest]
  54. end
  55.  
  56. function Player:UpdateQuest(strQuest, tblInfo)
  57.     if !ValidEntity(self) then return end
  58.     if self:GetQuest(strQuest) then
  59.         table.Merge(self.Data.Quests[strQuest], tblInfo or self.Data.Quests[strQuest] or {})
  60.         if SERVER then
  61.             SendUsrMsg("UD_UpdateQuest", self, {strQuest, tblInfo or self.Data.Quests[strQuest]})
  62.             self:SaveGame()
  63.         end
  64.         if CLIENT && GAMEMODE.QuestMenu then
  65.             GAMEMODE.QuestMenu:LoadQuests()
  66.         end
  67.         return true
  68.     end
  69.     self:AddQuest(strQuest, tblInfo)
  70. end
  71.  
  72. function Player:AddQuestKill(strNPC)
  73.     if !ValidEntity(self) then return end
  74.     local tblGivePlayers = {self}
  75.     if #(self.Squad or {}) > 1 then tblGivePlayers = self.Squad end
  76.     for _, ply in pairs(tblGivePlayers) do
  77.         if ValidEntity(ply) then
  78.             for strQuest, tblInfo in pairs(ply.Data.Quests or {}) do
  79.                 local tblQuestTable = QuestTable(strQuest)
  80.                 if tblInfo.Kills && tblInfo.Kills[strNPC] && tblInfo.Kills[strNPC] + 1 <= tblQuestTable.Kill[strNPC] then
  81.                     tblInfo.Kills[strNPC] = tblInfo.Kills[strNPC] + 1
  82.                     ply:UpdateQuest(strQuest, tblInfo)
  83.                 end
  84.             end
  85.         end
  86.     end
  87. end
  88.  
  89. function Player:CanAcceptQuest(strQuest)
  90.     if !ValidEntity(self) then return false end
  91.     local tblQuestTable = QuestTable(strQuest)
  92.     if tblQuestTable && self:GetLevel() >= tblQuestTable.Level && !self:GetQuest(strQuest) then
  93.         if tblQuestTable.QuestNeeded && !self:HasCompletedQuest(tblQuestTable.QuestNeeded) then return false end
  94.         return true
  95.     end
  96.     return false
  97. end
  98.  
  99. function Player:CanTurnInQuest(strQuest)
  100.     if !ValidEntity(self) then return false end
  101.     local tblQuestTable = QuestTable(strQuest)
  102.     local tblPlayerQuestTable = self:GetQuest(strQuest)
  103.     if tblQuestTable && !tblPlayerQuestTable.Done && tblPlayerQuestTable then
  104.         for strNPC, intKillAmount in pairs(tblQuestTable.Kill or {}) do
  105.             if tblPlayerQuestTable.Kills[strNPC] < intKillAmount then return false end
  106.         end
  107.         for strItem, intAmountNeeded in pairs(tblQuestTable.ObtainItems or {}) do
  108.             if !self:HasItem(strItem, intAmountNeeded) then return false end
  109.         end
  110.         if self:HasRoomFor(tblQuestTable.GainedItems, -self:TotalWeightOf(tblQuestTable.ObtainItems or {})) then
  111.             return true
  112.         end
  113.     end
  114. end
  115.  
  116. if SERVER then
  117.     function KillNPC(npcTarget, plyKiller, weapon)
  118.         if npcTarget:GetNWInt("level") > 0 && plyKiller:IsPlayer() then
  119.             local tblNPCTable = NPCTable(npcTarget:GetNWString("npc"))
  120.             if !tblNPCTable then return end
  121.             plyKiller:AddQuestKill(npcTarget:GetNWString("npc"))
  122.         end
  123.     end
  124.     hook.Add("OnNPCKilled", "KillNPC", KillNPC)
  125.    
  126.     function Player:TurnInQuest(strQuest)
  127.         if !ValidEntity(self) then return end
  128.         if !self.UseTarget.Quest or self.UseTarget:GetPos():Distance(self:GetPos()) > 100 then return end
  129.         local tblQuestTable = QuestTable(strQuest)
  130.         if self:CanTurnInQuest(strQuest) then
  131.             self:TakeItems(tblQuestTable.ObtainItems)
  132.             self:GiveItems(tblQuestTable.GainedItems)
  133.             self:ConCommand("play xhosters/iQuestComplete.wav")
  134.             if tblQuestTable.GainedExp && tblQuestTable.GainedExp > 0 then
  135.                 self:GiveExp(tblQuestTable.GainedExp, true)
  136.             end
  137.             self.Data.Quests[strQuest].Done = true
  138.             self:UpdateQuest(strQuest)
  139.         end
  140.     end
  141.     concommand.Add("UD_TurnInQuest", function(ply, command, args) ply:TurnInQuest(args[1]) end)
  142.    
  143.     function Player:AcceptQuest(strQuest)
  144.         if !ValidEntity(self) then return end
  145.         if !self.UseTarget.Quest or self.UseTarget:GetPos():Distance(self:GetPos()) > 100 then return end
  146.         if self:CanAcceptQuest(strQuest) then
  147.             if QuestTable(strQuest).StartingItems then
  148.                 if self:HasRoomFor(QuestTable(strQuest).StartingItems) then
  149.                     self:GiveItems(QuestTable(strQuest).StartingItems)
  150.                     self:AddQuest(strQuest)
  151.                     self:ConCommand("play xhosters/iQuestActivate.wav"
  152.                 end
  153.             else
  154.             self:ConCommand("play xhosters/iQuestActivate.wav")
  155.                 self:AddQuest(strQuest)
  156.             end
  157.         end
  158.     end
  159.     concommand.Add("UD_AcceptQuest", function(ply, command, args) ply:AcceptQuest(args[1]) end)
  160. end
  161.  
  162. if CLIENT then
  163.     usermessage.Hook("UD_UpdateQuest", function(usrMsg)
  164.     self:ConCommand("play xhosters/iQuestUpdate.wav")
  165.         local strQuest = usrMsg:ReadString()
  166.         local strIncomingInfo = usrMsg:ReadString()
  167.         --print(string.len(strQuest .. strIncomingInfo))
  168.         --print(strQuest .. strIncomingInfo)
  169.         LocalPlayer():UpdateQuest(strQuest, glon.decode(strIncomingInfo))
  170.     end)
  171. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement