diff options
Diffstat (limited to 'gamemode/itemsystem/item_common.lua')
| -rw-r--r-- | gamemode/itemsystem/item_common.lua | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/gamemode/itemsystem/item_common.lua b/gamemode/itemsystem/item_common.lua new file mode 100644 index 0000000..b4b7cce --- /dev/null +++ b/gamemode/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 |
