From 984b841c008ba29ead9ecb12aa86a57de2b0597a Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Fri, 25 Aug 2017 15:03:30 -0400 Subject: Fixed some bugs * Huntables now drop items correctly * Shop npcs work * Fixed a bug in shaped inventory --- gamemode/core/npc/cl_shop.lua | 13 ++++++++++-- gamemode/core/npc/sv_huntingspawner.lua | 7 +++++-- gamemode/core/npc/sv_shop.lua | 36 ++++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 5 deletions(-) (limited to 'gamemode/core/npc') diff --git a/gamemode/core/npc/cl_shop.lua b/gamemode/core/npc/cl_shop.lua index de8ec23..873a37c 100644 --- a/gamemode/core/npc/cl_shop.lua +++ b/gamemode/core/npc/cl_shop.lua @@ -18,7 +18,7 @@ local function DrawShopItemOnDPanel(dp,itemtbl,cost) backgrid:SetColWide( theight ) backgrid:Dock(LEFT) - local shopicon = vgui.Create( "DImageButton", dp ) + local shopicon = vgui.Create( "DModelPanel", dp ) shopicon:SetSize(slotsize * twidth, slotsize * theight) shopicon:SetPos(0,0) shopicon:SetText(itemtbl.Name) @@ -29,7 +29,7 @@ local function DrawShopItemOnDPanel(dp,itemtbl,cost) shopicon.Paint = itemtbl.Paint end if itemtbl.DoOnPanel then - itemtbl.DoOnPanel(shopicon) + itemtbl:DoOnPanel(shopicon) end shopicon.Paint = function(self, wi, hi) surface.SetDrawColor( 0, 0, 0, 255 ) @@ -70,6 +70,15 @@ local function DrawShopItemOnDPanel(dp,itemtbl,cost) net.WriteString(itemtbl.Name) net.SendToServer() end + + local sellbutton = vgui.Create("DButton",dp) + sellbutton:Dock(RIGHT) + sellbutton:SetText("Sell\n(" .. math.floor(cost - math.log(cost)) .. ")") + sellbutton.DoClick = function() + net.Start("art_sellitem") + net.WriteString(itemtbl.Name) + net.SendToServer() + end end diff --git a/gamemode/core/npc/sv_huntingspawner.lua b/gamemode/core/npc/sv_huntingspawner.lua index f6bf827..279d834 100644 --- a/gamemode/core/npc/sv_huntingspawner.lua +++ b/gamemode/core/npc/sv_huntingspawner.lua @@ -95,7 +95,10 @@ end) local external_drops = {} function o.RegisterDrops(npcname,tbl) - assert(external_drops[npcname] == nil, string.format("Tried to register 2 drop tables for the npc %q",npcname)) + if not external_drops[npcname] == nil then + MsgC(Color(255,255,0),"WARNING: Tried to register 2 drop tables for " .. npcname) + end + --assert(external_drops[npcname] == nil, string.format("Tried to register 2 drop tables for the npc %q",npcname)) external_drops[npcname] = tbl end @@ -111,7 +114,7 @@ hook.Add("OnNPCKilled","droplootforexnpcs",function(npc,attacker,inflictor) if rng < itemchance then local drop = itm.GetItemByName(itemname) print("Createing a drop of",drop) - track.CreateDroppedItem(drop, npc:GetPos() + Vector(math.random(20),math.random(20),20)) + track.DropItem(drop, npc:GetPos()) end end end) diff --git a/gamemode/core/npc/sv_shop.lua b/gamemode/core/npc/sv_shop.lua index c0e2153..50b6ac8 100644 --- a/gamemode/core/npc/sv_shop.lua +++ b/gamemode/core/npc/sv_shop.lua @@ -52,7 +52,7 @@ net.Receive("art_buyitem",function(len,ply) --Find the price of the item we want to buy local price - for k,v in pairs(shop.shopitems) do + for k,v in pairs(tshop.shopitems) do if v[1] == itemname then price = v[2] break @@ -72,4 +72,38 @@ net.Receive("art_buyitem",function(len,ply) end end) +net.Receive("art_sellitem",function(len,ply) + local itemname = net.ReadString() + + --Find the shop near the player + local es = ents.FindInSphere(ply:GetPos(),500) + local tshop + for k,v in pairs(es) do + if IsValid(v) and v:GetClass() == "npc_shop" then + tshop = v + break + end + end + print("Shop was", tshop) + print("Items:", tshop.shopitems) + PrintTable(tshop.shopitems) + + --Find the price of the item we want to buy + local price + for k,v in pairs(tshop.shopitems) do + if v[1] == itemname then + price = math.floor(v[2] - math.log(v[2])) + break + end + end + + local spot = ply:HasItem(itemname) + if spot then + print("Selling item at spot",spot) + PrintTable(spot) + ply:RemoveItem(spot) + ply:SetCredits(ply:GetCredits() + price) + end +end) + return shop -- cgit v1.2.3-70-g09d2