From 79c1c484eab6fbf36a69d155a324540887e38880 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 29 Oct 2016 17:51:13 -0400 Subject: Got shops working --- gamemode/shared/itemsystem/armor/balaclava.lua | 1 + gamemode/shared/itemsystem/exampleitem.lua | 2 +- gamemode/shared/itemsystem/foodstuffs/ratmeat.lua | 4 +- .../shared/itemsystem/foodstuffs/watermelon.lua | 2 +- gamemode/shared/itemsystem/item_common.lua | 76 ++++++++++++++++++++++ gamemode/shared/itemsystem/quest/rougebook.lua | 11 +++- gamemode/shared/itemsystem/weapons/rustyaxe.lua | 1 + 7 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 gamemode/shared/itemsystem/item_common.lua (limited to 'gamemode/shared/itemsystem') diff --git a/gamemode/shared/itemsystem/armor/balaclava.lua b/gamemode/shared/itemsystem/armor/balaclava.lua index d77da61..8b4b8d2 100644 --- a/gamemode/shared/itemsystem/armor/balaclava.lua +++ b/gamemode/shared/itemsystem/armor/balaclava.lua @@ -26,6 +26,7 @@ function item.GetOptions(self) local options = {} options["test"] = function() print("You pressed test!") end options["toste"] = function() print("You pressed toste!") end + options["drop"] = ART.DropItem(self) return options end diff --git a/gamemode/shared/itemsystem/exampleitem.lua b/gamemode/shared/itemsystem/exampleitem.lua index fdc0e9c..a21def8 100644 --- a/gamemode/shared/itemsystem/exampleitem.lua +++ b/gamemode/shared/itemsystem/exampleitem.lua @@ -75,7 +75,7 @@ item.onUnEquip = function(self,who) print("Aw, I'm being stored :(") end ---Technically optional, but item will display as a rock if you don't have it +--Technically optional, but item will display as a rock if you don't have it. If you want to do something other than drop on dropped, remove ent. item.onDropped = function(self,ent) print("I've been dropped!(BUVVV WUB WUB WUB WUB WUB)") end diff --git a/gamemode/shared/itemsystem/foodstuffs/ratmeat.lua b/gamemode/shared/itemsystem/foodstuffs/ratmeat.lua index 8990a49..5310fe2 100644 --- a/gamemode/shared/itemsystem/foodstuffs/ratmeat.lua +++ b/gamemode/shared/itemsystem/foodstuffs/ratmeat.lua @@ -39,6 +39,8 @@ item.Shape = { {true} } - +item.onDropped = function(self, ent) + ART.ApplyPAC(ent,"ratmeat") +end --Don't forget to register the item! ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/foodstuffs/watermelon.lua b/gamemode/shared/itemsystem/foodstuffs/watermelon.lua index c79ba6c..2b9f7cb 100644 --- a/gamemode/shared/itemsystem/foodstuffs/watermelon.lua +++ b/gamemode/shared/itemsystem/foodstuffs/watermelon.lua @@ -47,7 +47,7 @@ item.Shape = { } item.onDropped = function(self, ent) - ART.ApplyPAC(ent,"scraphammer") + ART.ApplyPAC(ent,"Watermelon") end print("Hello from exampleitem.lua") diff --git a/gamemode/shared/itemsystem/item_common.lua b/gamemode/shared/itemsystem/item_common.lua new file mode 100644 index 0000000..b4b7cce --- /dev/null +++ b/gamemode/shared/itemsystem/item_common.lua @@ -0,0 +1,76 @@ +if CLIENT then + ART.DropItem = function(item) + local i = item + print("Trying to drop item, Item was ") + PrintTable(item) + return function() + local data = item:Serialize() + net.Start("dropitem") + net.WriteString(item.Name) + net.WriteUInt(#data,32) + net.WriteData(data,#data) + net.SendToServer() + end + end + +else + util.AddNetworkString("dropitem") + + function gencompareto(item) + --Two items are equal if their Serialize()s are the same. + local tserialize = item:Serialize() + return function(otheritem) + local oserialize = otheritem:Serialize() + return tserialize == oserialize + end + end + + function ART.CreateDroppedItem(itemtbl, where) + local e = ents.Create("art_droppeditem") + e.Model = "models/props_junk/Rock001a.mdl" + e.Item = itemtbl + e:SetPos(where) + e:Spawn() + end + + net.Receive("dropitem",function(len,ply) + local itemtype = net.ReadString() + local itemdatalen = net.ReadUInt(32) + local itemdata = net.ReadData(itemdatalen) + local itemtbl = ART.GetItemByName(itemtype) + local item = itemtbl:DeSerialize(itemdata) + + print("I want to drop:") + PrintTable(item) + print("Do I have one?") + local row,col,n = ply:HasItem(gencompareto(item)) + print("row",row,"col",col,"n",n) + --To find out where to drop the item, go out from player's view, then down. + local pes = ply:GetPos()+Vector(0,0,64) + local pee = ply:GetForward()*50 + Vector(0,0,64) + ply:GetPos() + local tr1d = { + ["start"] = pes, + ["endpos"] = pee, + ["filter"] = ply, + } + local tr1r = util.TraceLine(tr1d) + local fes + if tr1r.hit then --Use where it hit and go down + fes = tr1r.HitPos + else --Use the spot 50 units in front of us + fes = pee + end + local tr2d = { + ["start"] = fes, + ["endpos"] = fes + Vector(0,0,-64), + } + local tr2r = util.TraceLine(tr2d) + local itempos = tr2r.HitPos + print("Dropping item at",itempos) + if row and col and n then + print("DropItem is",ART.DropItem) + ART.CreateDroppedItem(item,itempos) + ply:RemoveItemAt(n,row,col) + end + end) +end diff --git a/gamemode/shared/itemsystem/quest/rougebook.lua b/gamemode/shared/itemsystem/quest/rougebook.lua index 835b863..4eabe06 100644 --- a/gamemode/shared/itemsystem/quest/rougebook.lua +++ b/gamemode/shared/itemsystem/quest/rougebook.lua @@ -22,11 +22,14 @@ item.Shape = { local rougeadvice = { "He who refuses to trim his beard will find himself in a hairy situation.", - "You'll get tired defending from a man in a vehicle", - "You'll get exhaused attacking a man in a vehicle.", + "You'll get tired defending from a man in a car", + "You'll get exhaused attacking a man in a car.", + "Sex is not the answer, it is the question. And the answer is 'yes'.", + "The 'Darkest Hour' is when you can't find the matches.", "If you eat beans before church, you will sit in your own pew.", "He who seeks challenges will be puzzeled.", "He who fishes in another man's well is likely to catch crabs.", + "Enjoy masturbation, it's sex with someone you love.", } local lhint = 1 @@ -58,4 +61,8 @@ function item.GetOptions(self) return options end +item.onDropped = function(self, ent) + ART.ApplyPAC(ent,"book1") +end + ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/weapons/rustyaxe.lua b/gamemode/shared/itemsystem/weapons/rustyaxe.lua index f21500d..735c3da 100644 --- a/gamemode/shared/itemsystem/weapons/rustyaxe.lua +++ b/gamemode/shared/itemsystem/weapons/rustyaxe.lua @@ -26,6 +26,7 @@ function item.GetOptions(self) local options = {} options["test"] = function() print("You pressed test!") end options["toste"] = function() print("You pressed toste!") end + options["Drop"] = ART.DropItem(self) return options end -- cgit v1.2.3-70-g09d2