diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2017-08-25 15:03:30 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2017-08-25 15:03:30 -0400 |
| commit | 984b841c008ba29ead9ecb12aa86a57de2b0597a (patch) | |
| tree | 079aa2cacacc2bb515788a40c94308b19fbeac08 /gamemode | |
| parent | 233e478e40d72a091f70f18dc6846066a4f52016 (diff) | |
| download | artery-984b841c008ba29ead9ecb12aa86a57de2b0597a.tar.gz artery-984b841c008ba29ead9ecb12aa86a57de2b0597a.tar.bz2 artery-984b841c008ba29ead9ecb12aa86a57de2b0597a.zip | |
Fixed some bugs
* Huntables now drop items correctly
* Shop npcs work
* Fixed a bug in shaped inventory
Diffstat (limited to 'gamemode')
| -rw-r--r-- | gamemode/core/npc/cl_shop.lua | 13 | ||||
| -rw-r--r-- | gamemode/core/npc/sv_huntingspawner.lua | 7 | ||||
| -rw-r--r-- | gamemode/core/npc/sv_shop.lua | 36 | ||||
| -rw-r--r-- | gamemode/inventorysystem/shapedinventory/sh_shaped.lua | 3 |
4 files changed, 53 insertions, 6 deletions
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 diff --git a/gamemode/inventorysystem/shapedinventory/sh_shaped.lua b/gamemode/inventorysystem/shapedinventory/sh_shaped.lua index 76d322d..66aa24b 100644 --- a/gamemode/inventorysystem/shapedinventory/sh_shaped.lua +++ b/gamemode/inventorysystem/shapedinventory/sh_shaped.lua @@ -79,8 +79,9 @@ function inv:Has(ptr) end for k,v in pairs(self.tracker) do if type(v) == "table" and compare_func(v) then + print("Found item in spot:",k) local row = math.ceil(k / self.width) - local col = k % self.width + local col = ((k - 1) % self.width) + 1 print("Has is retuning",row,col) return {row,col} end |
