diff options
28 files changed, 444 insertions, 44 deletions
diff --git a/entities/entities/art_chest/cl_init.lua b/entities/entities/art_chest/cl_init.lua index 2907968..1ba18b4 100644 --- a/entities/entities/art_chest/cl_init.lua +++ b/entities/entities/art_chest/cl_init.lua @@ -19,6 +19,17 @@ function ENT:Draw() end local oldpanel = nil +local namecache = {} + +net.Receive("informchestname",function() + local e = net.ReadEntity() + local s = net.ReadString() + namecache[e] = s + if oldpanel ~= nil then + oldpanel:SetTitle(s) + end +end) + net.Receive("openchestinv",function(len,ply) if oldpanel ~= nil then oldpanel:Remove() end print("Opening chest inventory") @@ -44,7 +55,15 @@ net.Receive("openchestinv",function(len,ply) local invpanel = dat.panel invpanel:SetPos( width - (width/4), 0 ) invpanel:SetSize( width / 4, height ) - invpanel:SetTitle( "Chest" ) + print("Trying to get name",name) + if namecache[what] == nil then + net.Start("requestchestname") + net.WriteEntity(what) + net.SendToServer() + invpanel:SetTitle( "Chest" ) + else + invpanel:SetTitle(namecache[what]) + end invpanel:SetDraggable( true ) invpanel:MakePopup() local innerpanel = vgui.Create("DPanel",dat.panel) diff --git a/entities/entities/art_chest/init.lua b/entities/entities/art_chest/init.lua index 92d1371..cd39eab 100644 --- a/entities/entities/art_chest/init.lua +++ b/entities/entities/art_chest/init.lua @@ -24,9 +24,25 @@ function ENT:Initialize() self.StoredItems = {} end -util.AddNetworkString("openchestinv") -util.AddNetworkString("closechestinv") -util.AddNetworkString("requestchestinv") +local uans = { + "openchestinv", + "closechestinv", + "requestchestinv", + "requestchestname", + "informchestname", +} +for k,v in pairs(uans) do + util.AddNetworkString(v) +end + +net.Receive("requestchestname",function(ln,ply) + local e = net.ReadEntity() + local s = e:GetName() + net.Start("informchestname") + net.WriteEntity(e) + net.WriteString(s) + net.Send(ply) +end) net.Receive("requestchestinv",function(ln,ply) print("Received request for chest") diff --git a/entities/entities/art_droppeditem/cl_init.lua b/entities/entities/art_droppeditem/cl_init.lua index eb4b21f..eb8868d 100644 --- a/entities/entities/art_droppeditem/cl_init.lua +++ b/entities/entities/art_droppeditem/cl_init.lua @@ -16,10 +16,14 @@ end local lp local sentrequests = {} hook.Add("Tick","pickupitemstick",function() - lp = lp or LocalPlayer() + lp = (lp and lp:IsValid()) and lp or LocalPlayer() + if not lp:IsValid() then return end local ae = ents.FindInSphere(lp:GetPos(),5) for k,v in pairs(ae) do local ei = v:EntIndex() + if ei ~= 1 and ei ~= -1 then + print("Checking if we should pick up", ei) + end if (not sentrequests[ei]) and v.GetClass and v:GetClass() == "art_droppeditem" then print("Sending request to pick up", ei) net.Start("art_requestpickup") diff --git a/entities/entities/art_droppeditem/init.lua b/entities/entities/art_droppeditem/init.lua index de27e6d..491d479 100644 --- a/entities/entities/art_droppeditem/init.lua +++ b/entities/entities/art_droppeditem/init.lua @@ -17,10 +17,16 @@ function ENT:Initialize() self.ItemData = self.Item.Data if self.Item.onDropped then self:SetColor(Color(0,0,0,0)) - timer.Simple(1,function() - self.Item:onDropped(self) - end) + local od = self.Item.onDropped + if od ~= nil then + timer.Simple(1,function() + if self and self.Item then + od(self.Item,self) + end + end) + end end + self:DrawShadow(false) self:SetMoveType(MOVETYPE_NONE) self:SetSolid(SOLID_NONE) self:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE) diff --git a/entities/entities/npc_huntable/init.lua b/entities/entities/npc_huntable/init.lua index 3adf3e2..e5b52c8 100644 --- a/entities/entities/npc_huntable/init.lua +++ b/entities/entities/npc_huntable/init.lua @@ -58,12 +58,9 @@ function ENT:OnKilled(dmg) local heightoffset = 10 if rng < itemchance then - local drop = ents.Create("ws_item") - drop.Item = GetItemByName(itemname) - drop:SetModel(drop.Item.Model) - drop:SetPos(self:GetPos() + (self:GetUp() * heightoffset)) - drop:Spawn() - heightoffset = heightoffset + 10 + local drop = ART.GetItemByName(itemname) + print("Createing a drop of",drop) + ART.CreateDroppedItem(drop, self:GetPos()) end end diff --git a/entities/entities/npc_huntable/shared.lua b/entities/entities/npc_huntable/shared.lua index 2f34721..279199f 100644 --- a/entities/entities/npc_huntable/shared.lua +++ b/entities/entities/npc_huntable/shared.lua @@ -18,7 +18,7 @@ end function ENT:DefaultBehaviour() self.lastrun = CurTime() while (true) do - print("Inside defaultbehaviour") + --print("Inside defaultbehaviour") local delta = CurTime() - self.lastrun self:AI(delta) --Main loop for ai @@ -42,7 +42,7 @@ end function ENT:AI(num) - print("Inside behaveupdate") + --print("Inside behaveupdate") local players = player.GetAll() for k, v in pairs(players) do @@ -60,8 +60,8 @@ function ENT:AI(num) local priority = self:AttackPriority(v) if (priority == nil) then - print("Nill priority hit after ") - PrintTable(self) + --print("Nill priority hit after ") + --PrintTable(self) end if (priority > maxpriority) then @@ -71,13 +71,13 @@ function ENT:AI(num) end self.Target = maxprioritytarget - print("My target is",self.Target) + --print("My target is",self.Target) --If we can't find anyone to attack, just stay idle if (self.Target == nil) then --print("Couldn't find anyone to attack!") --Play an idle sequence local randanim = math.Round(math.Rand(0, #self.IdleSequences)) - print("Playing sequence",self.IdleSequences[randanim]) + --print("Playing sequence",self.IdleSequences[randanim]) self:PlaySequenceAndWait(self.IdleSequences[randanim]) self:StartActivity(ACT_IDLE) --print("Acting idle") @@ -93,7 +93,7 @@ function ENT:AI(num) end if (closest > 4000) then - print("Closes player is " .. closest .. " removeing self...") + --print("Closes player is " .. closest .. " removeing self...") self:BecomeRagdoll(DamageInfo()) end else diff --git a/entities/entities/npc_shop/cl_init.lua b/entities/entities/npc_shop/cl_init.lua new file mode 100644 index 0000000..4cfd132 --- /dev/null +++ b/entities/entities/npc_shop/cl_init.lua @@ -0,0 +1,5 @@ +include('shared.lua') +--local invfuncs = include("../../../gamemode/shared/inventory_common.lua") +local invfuncs = ART.invfuncs + +ENT.RenderGroup = RENDERGROUP_BOTH diff --git a/entities/entities/npc_shop/init.lua b/entities/entities/npc_shop/init.lua new file mode 100644 index 0000000..93b5755 --- /dev/null +++ b/entities/entities/npc_shop/init.lua @@ -0,0 +1,46 @@ +AddCSLuaFile( "cl_init.lua" ) +AddCSLuaFile( "shared.lua" ) + +include("shared.lua") +local invfuncs = include("../../../gamemode/shared/inventory_common.lua") + +--Some things that can be looted +local lootables = { + +} + +function CreateRandomLoot(time) + +end + +function ENT:Initialize() + + self.Openedby = {} + + self:PhysicsInit( SOLID_VPHYSICS ) + self:SetMoveType( MOVETYPE_NONE ) + self:SetUseType(SIMPLE_USE) + + self:SetSolid(SOLID_BBOX ) + self:SetCollisionGroup(COLLISION_GROUP_NPC ) + + print("Initalizeing shop npc") + if(self.Model) then self:SetModel(self.Model) + else print("NPC created without model, this might be a bug!") end + + if self.Pos then self:SetPos(self.Pos) + else print("NPC created without a position, this might be a bug!") end + + self.talking = false + + if self.Name then self:SetName(self.Name) + else print("NPC created without a name! They won't be able to open doors!") end + + if self.OnSpawn then self.OnSpawn(self) end + + self:SetUseType( SIMPLE_USE ) +end + +function ENT:Use(ply) + ART.OpenShop(self.shopitems,ply) +end diff --git a/entities/entities/npc_shop/shared.lua b/entities/entities/npc_shop/shared.lua new file mode 100644 index 0000000..28ee2d3 --- /dev/null +++ b/entities/entities/npc_shop/shared.lua @@ -0,0 +1,2 @@ +ENT.Type = "nextbot" +ENT.Base = "art_chest" diff --git a/entities/weapons/hands.lua b/entities/weapons/hands.lua index e0b1ae6..d55c416 100644 --- a/entities/weapons/hands.lua +++ b/entities/weapons/hands.lua @@ -39,6 +39,7 @@ end local Box = Vector(8,8,8) function SWEP:PrimaryAttack() + if not self.Owner.Inventory then return end local rightitem = self.Owner.Inventory.Equiped["Left"] if rightitem ~= false and rightitem.onClick ~= nil then rightitem:onClick(self.Owner) diff --git a/gamemode/client/cl_inventory.lua b/gamemode/client/cl_inventory.lua index b806846..a40a5f8 100644 --- a/gamemode/client/cl_inventory.lua +++ b/gamemode/client/cl_inventory.lua @@ -7,6 +7,11 @@ print("Hello from cl_inventory.lua") ART.PrayerEquiped = ART.PrayerEquiped or { false,false,false,false } +net.Receive("equiphelpprayer",function() + print("equiphelp received client side!") + ART.PrayerEquiped[4] = "Noob Help" +end) + local lastpanel = lastpanel or 1 diff --git a/gamemode/client/cl_weaponswitch.lua b/gamemode/client/cl_weaponswitch.lua index 5aaed87..f7edcfc 100644 --- a/gamemode/client/cl_weaponswitch.lua +++ b/gamemode/client/cl_weaponswitch.lua @@ -1,3 +1,7 @@ function GM:PlayerSwitchWeapon( ply, oldWeapon, newWeapon ) return false end + +hook.Add( "HUDShouldDraw", "HideWeaponSelHUD", function( name ) + if name == "CHudWeaponSelection" then return false end +end ) diff --git a/gamemode/client/qpanels/inventory.lua b/gamemode/client/qpanels/inventory.lua index 9fec1cc..b366c7a 100644 --- a/gamemode/client/qpanels/inventory.lua +++ b/gamemode/client/qpanels/inventory.lua @@ -82,7 +82,10 @@ local function DrawBackpackOnDPanel(dp, backpack, backpacknum, tent) if invfuncs.CanFitInBackpack(backpack,j,i,item) then local fromtbl = icon.invpos local wasequiped = icon.wasequiped - if wasequiped then + local ondropped = icon.ondropped + if ondropped then + ondropped(backpacknum,j,i,item) + elseif wasequiped then net.Start("unequipitem") net.WriteString(wasequiped) net.WriteUInt(backpacknum,16) diff --git a/gamemode/init.lua b/gamemode/init.lua index 0b311ea..b4f5c76 100644 --- a/gamemode/init.lua +++ b/gamemode/init.lua @@ -3,3 +3,26 @@ AddCSLuaFile( "shared.lua" ) AddCSLuaFile( "cl_init.lua" ) include( "shared.lua" ) + +local pmeta = FindMetaTable("Player") + +--- Loads a player's inventory +-- @param json The JSON string to create the player's inventory from +function pmeta:LoadInventory(json) + local reinv = util.JSONToTable(json) + for k,v in pairs(reinv) do + self.Inventory[k] = v + end + print("After loading inventory, player's inventory was") + PrintTable(self.Inventory) + self:SynchronizeInventory() + self:SynchPrayers() + if self:HasPrayer("Noob Help") then + print("Player had Noob Help, equiping!") + net.Start("equiphelpprayer") + net.Send(self) + else + error("Player did not have noob help, inventory was:") + PrintTable(self.Inventory) + end +end diff --git a/gamemode/server/sv_config.lua b/gamemode/server/sv_config.lua index cb365a6..82f1061 100644 --- a/gamemode/server/sv_config.lua +++ b/gamemode/server/sv_config.lua @@ -3,10 +3,10 @@ ]] ART.defaults = {} -ART.defaults.starting_inventory = '{"Backpacks":[[[[false,false,false,false,false],[false,false,false,false,false],[false,false,false,false,false],[false,false,false,false,false],[false,false,false,false,false]],[5,5],"Rucksack"]],"Equiped":{"Gloves":false,"Left":false,"Head":false,"Legs":false,"Right":false,"Body":false,"Boots":false}}' +ART.defaults.starting_inventory = '{"Backpacks":[[[[false,false,false,false,false],[false,false,false,false,false],[false,false,false,false,false],[false,false,false,false,false],[false,false,false,false,false]],[5,5],"Rucksack"]],"Credits":0,"Equiped":{"Gloves":false,"Left":false,"Boots":false,"Legs":false,"Right":false,"Body":false,"Head":false},"Prayers":{"Noob Help":true}}' ART.defaults.starting_skills = "[]" ART.defaults.starting_quests = "[]" -ART.defaults.starting_prayers = "[]" +ART.defaults.starting_prayers = "[]" --This dosen't actually do anything, remove it at some point. ART.defaults.starting_position = "185 310 524" ART.defaults.starting_world = "0.0.0.0:27015" diff --git a/gamemode/server/sv_mapconfig.lua b/gamemode/server/sv_mapconfig.lua index b9a93b8..7117a07 100644 --- a/gamemode/server/sv_mapconfig.lua +++ b/gamemode/server/sv_mapconfig.lua @@ -21,6 +21,7 @@ local removeents = { "npc_townie", -- "art_chest", "info_townienode", + "npc_shop", } for k,v in pairs(removeents) do diff --git a/gamemode/shared/inventory.lua b/gamemode/shared/inventory.lua index a8c1756..2165686 100644 --- a/gamemode/shared/inventory.lua +++ b/gamemode/shared/inventory.lua @@ -1,5 +1,7 @@ --[[ Various functions to work with inventories + player:GetCredits() + player:SetCredits(number credits) ]] --- Various functions to deal with inventories. -- @module Player @@ -159,6 +161,7 @@ if SERVER then util.AddNetworkString("moveitem") util.AddNetworkString("equipitem") util.AddNetworkString("unequipitem") + util.AddNetworkString("buyitem") end --- Unequips an item. @@ -169,14 +172,16 @@ end -- @param col The column in the backpack to put the item function pmeta:UnEquip(equipslot, backpack, row, col) local item = self.Inventory.Equiped[equipslot] + local tobackpack = self.Inventory.Backpacks[backpack] + print("Unequiping into backpack", tobackpack) if self:CanFitInBackpack( - self.Inventory.Backpacks[backpack], + tobackpack, row, col, item ) then self.Inventory.Equiped[equipslot] = false - self:PutInvItem(tobackpack,row,col,item) + self:PutInvItem(backpack,row,col,item) if item.onUnEquip ~= nil then item:onUnEquip(self) end @@ -228,6 +233,50 @@ net.Receive("equipitem",function(len,ply) ply:EquipItem(backpacknum,fromrow,fromcol,equippos) end) +net.Receive("buyitem",function(len,ply) + local itemname = net.ReadString() + local backpack = net.ReadUInt(8) + local j = net.ReadUInt(8) + local i = net.ReadUInt(8) + local item = ART.GetItemByName(itemname) + local nearshops = ents.FindInSphere( ply:GetPos(), 100 ) + local cost + for k,v in pairs(nearshops) do + if v:GetClass() ~= "npc_shop" then goto nextent end + print("Checking if ", v, " has a ", itemname) + print("Shop items were") + PrintTable(v.shopitems) + for i,j in pairs(v.shopitems) do + if j[1] == itemname then + cost = j[2] + goto itemfound + end + end + ::nextent:: + end + ::itemfound:: + if cost == nil then + ply:ChatPrint("Could not find a shop selling that!") + return false + end + print("Found item, cost was ", cost) + local playercreds = ply:GetCredits() + local tbp = ply.Inventory.Backpacks[backpack] + local canfit = invfuncs.CanFitInBackpack(tbp,j,i,item) + print("Can it?",canfit) + if playercreds < cost then + ply:ChatPrint("You don't have enough credits to buy that!") + return false + end + if not canfit then + ply:ChatPrint("You can't put that into your packpack there!") + return false + end + playercreds:SetCredits(playercreds - cost) + invfuncs.PutItemInBackpack(tbp,j,i,item) + return true +end) + net.Receive("moveitem",function(len,ply) local froment = net.ReadEntity() local toent = net.ReadEntity() @@ -262,16 +311,6 @@ net.Receive("moveitem",function(len,ply) toent:SynchronizeInventory() end) ---- Loads a player's inventory --- @param json The JSON string to create the player's inventory from -function pmeta:LoadInventory(json) - local reinv = util.JSONToTable(json) - for k,v in pairs(reinv) do - self.Inventory[k] = v - end - self:SynchronizeInventory() -end - --- Networks a player's inventory -- Makes sure the client's version of the inventory matches up to the server's version, this should be called after manipulateing the client's inventory in any way. function pmeta:SynchronizeInventory() 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 diff --git a/gamemode/shared/loadprayers.lua b/gamemode/shared/loadprayers.lua index 53631c2..3c94b72 100644 --- a/gamemode/shared/loadprayers.lua +++ b/gamemode/shared/loadprayers.lua @@ -69,6 +69,8 @@ if SERVER then end util.AddNetworkString( "art_synch_prayers" ) + util.AddNetworkString( "equiphelpprayer" ) + function meta:SynchPrayers() print("Sending " .. table.Count(self.Inventory.Prayers) .. " prayers:") PrintTable(self.Inventory.Prayers) diff --git a/gamemode/shared/npcsystem/rat.lua b/gamemode/shared/npcsystem/rat.lua index d1c5422..ab96883 100644 --- a/gamemode/shared/npcsystem/rat.lua +++ b/gamemode/shared/npcsystem/rat.lua @@ -23,8 +23,8 @@ NPC.IdleSequences = { --Drops should be formated as [index]={["item name"], percent_drop} where percent_drop is a number from 0 to 100 NPC.Drops = { - [0] = {"Meat",100},--Rats will drop at least 1 meat, and have a 50% chance of dropping 2 - [1] = {"Meat",50}, + [0] = {"Rat Meat",100},--Rats will drop at least 1 meat, and have a 50% chance of dropping 2 + [1] = {"Rat Meat",50}, } --Attacks should be formated as [i]={function attackpriority() = function doattack()} @@ -47,7 +47,7 @@ local dorun = function(self,ply) direction:Normalize() local addition = direction * 1000 local topos = self:GetPos() + addition - print("I want to go to ", topos) + --print("I want to go to ", topos) self.TargetPos = topos end NPC.Attacks = { diff --git a/gamemode/shared/shop.lua b/gamemode/shared/shop.lua new file mode 100644 index 0000000..b188e7c --- /dev/null +++ b/gamemode/shared/shop.lua @@ -0,0 +1,138 @@ +local ivf = include("inventory_common.lua") +ART = ART or {} + +if SERVER then + for k,v in pairs({ + "art_openshop", + "art_buyitem", + "art_sellitem", + }) do + util.AddNetworkString(v) + end + + function ART.OpenShop(tbl, ply) + print("Called openshop!") + print("tbl was") + PrintTable(tbl) + if CLIENT then return end + net.Start("art_openshop") + net.WriteTable(tbl) + net.Send(ply) + end + + function ART.CreateShop(npc) + print("Createing shop npc") + local npcent = ents.Create("npc_shop") + for k,v in pairs(npc) do + npcent[k] = v + end + npcent:Spawn() + print("Called spawn") + end + +end + +if SERVER then return end +local w,h = ScrW(),ScrH() +function DrawShopItemOnDPanel(dp,item) + --An item is a string, and int cost + local itemtbl = ART.GetItemByName(item[1]) + local cost = item[2] + + local shape = itemtbl.Shape + local twidth,theight = 0,#shape + for k=1,#shape do + twidth = math.max(twidth,#shape[k]) + end + + local slotsize = math.Round(w / 32) + local backgrid = vgui.Create( "DGrid", dp ) + backgrid:SetPos( 10, 30 ) + backgrid:SetCols( twidth ) + backgrid:SetColWide( theight ) + backgrid:Dock(FILL) + + local shopicon = vgui.Create( "DImageButton", dp ) + shopicon:SetSize(slotsize * twidth, slotsize * theight) + shopicon:SetPos(0,0) + shopicon:SetText(itemtbl.Name) + if itemtbl.Tooltip then + shopicon:SetTooltip(itemtbl.Tooltip) + end + if itemtbl.Paint then + shopicon.Paint = itemtbl.Paint + end + if itemtbl.DoOnPanel then + itemtbl.DoOnPanel(shopicon) + end + --invicon.Paint = function(self, w, h) draw.RoundedBox(4, 0,0,w,h,Color(0,100,0)) end + shopicon.DoClick = function() + print("You cliked me!") + end + shopicon.Item = itemtbl + shopicon.Cost = cost + shopicon:Droppable("Inventory") + shopicon.ondropped = function(back,j,i,item) + print("ondropped was called!") + print("back",back,"j",j,"i",i,"item",item) + PrintTable(item) + net.Start("buyitem") + net.WriteString(item.Name) + net.WriteUInt(back,8) + net.WriteUInt(j,8) + net.WriteUInt(i,8) + net.SendToServer() + end + + print("Displaying shape:") + PrintTable(shape) + for k = 1, twidth do + for i = 1, theight do + if not shape[k][i] then + print("Found false spot:",k,i) + local emptyslot = vgui.Create("DPanel", dp) + emptyslot:SetSize(slotsize,slotsize) + emptyslot:SetPos(slotsize * (i - 1), slotsize * (k - 1)) + end + end + end + +end + +function DrawShopOnDPanel(dp,items) + --This gets pretty involved, lets try to not make it a clusterfuck. + DrawShopItemOnDPanel(dp,items[1]) + +end + +local shopwindow,shoppanel + +local function createshopwindow() + print("Createing shopwindow") + shopwindow = vgui.Create( "DFrame" ) + shopwindow:SetPos( w - (w / 4), 0 ) + shopwindow:SetSize( w / 4, h ) + shopwindow:SetTitle( "Unset shop" ) + shopwindow:SetDraggable( true ) + shopwindow.OnClose = function(self) + self:SetVisible(false) + print("After onclose, shopwindow was",shopwindow) + end + shopwindow:SetVisible(false) + + shoppanel = vgui.Create( "DPanel",shopwindow) + shoppanel:SetPos( 10, 30 ) -- Set the position of the panel + shoppanel:Dock(FILL) +end +createshopwindow() + +net.Receive("art_openshop",function() + print("shopwindows was ",shopwindow) + if not shopwindow:IsValid() then createshopwindow() end + assert(shopwindow,"Shopwindow was not created, even after re-createing!") + ShowInventory() + shopwindow:SetVisible(true) + local stock = net.ReadTable() + DrawShopOnDPanel(shoppanel,stock) + shopwindow:MakePopup() +end) @@ -15,6 +15,8 @@ Multi-serverness is defined in /data/artery/maps/<map_name> PAC's to download on demand are in /data/artery/pacs/<pac_name> +two shop npc's within 200 units of eachother cannot sell the same item. + For creation: Finding the player's current position lua_run_cl local gp = LocalPlayer():GetPos() print(string.format("Vector(%.2d,%.2d,%.2d)",gp.x,gp.y,gp.z)) |
