aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2017-08-25 15:03:30 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2017-08-25 15:03:30 -0400
commit984b841c008ba29ead9ecb12aa86a57de2b0597a (patch)
tree079aa2cacacc2bb515788a40c94308b19fbeac08
parent233e478e40d72a091f70f18dc6846066a4f52016 (diff)
downloadartery-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
-rw-r--r--entities/entities/art_droppeditem/init.lua4
-rw-r--r--entities/weapons/hands.lua2
-rw-r--r--gamemode/core/npc/cl_shop.lua13
-rw-r--r--gamemode/core/npc/sv_huntingspawner.lua7
-rw-r--r--gamemode/core/npc/sv_shop.lua36
-rw-r--r--gamemode/inventorysystem/shapedinventory/sh_shaped.lua3
6 files changed, 57 insertions, 8 deletions
diff --git a/entities/entities/art_droppeditem/init.lua b/entities/entities/art_droppeditem/init.lua
index afd3139..6c66ac8 100644
--- a/entities/entities/art_droppeditem/init.lua
+++ b/entities/entities/art_droppeditem/init.lua
@@ -67,7 +67,9 @@ net.Receive("art_requestpickup",function(len,pl)
xpcall(function()
pl:GiveItem(i)
e:Remove()
- end,function() --We couldn't put the item in the player's inventory!
+ end,function()
+ print("Unable to put item into player's inventory")
+ --We couldn't put the item in the player's inventory!
--Don't do anything I guess
end)
else
diff --git a/entities/weapons/hands.lua b/entities/weapons/hands.lua
index 553c4f1..57c56d9 100644
--- a/entities/weapons/hands.lua
+++ b/entities/weapons/hands.lua
@@ -39,7 +39,7 @@ function SWEP:DefaultPickup()
if self.Pickup == nil then
local tr = self.Owner:GetEyeTrace()
local dist = self.Owner:GetPos():Distance(tr.HitPos)
- if dist < 100 and tr.Entity:GetMass() < 100 then
+ if dist < 100 and tr.Entity.GetMass and tr.Entity:GetMass() < 100 then
self.Pickup = tr.Entity
self.PickupAngles = tr.Entity:GetAngles()
self.PickupOffset = dist
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