From 1de5f9ac6f038bfed2230cc1272b253794b2f41a Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sun, 10 Jul 2016 17:04:29 -0400 Subject: Initial commit --- entities/entities/art_chest/cl_init.lua | 53 ++++++++++++ entities/entities/art_chest/init.lua | 72 ++++++++++++++++ entities/entities/art_chest/shared.lua | 2 + entities/entities/npc_townie/cl_init.lua | 66 ++++++++++++++ entities/entities/npc_townie/init.lua | 75 ++++++++++++++++ entities/entities/npc_townie/shared.lua | 123 ++++++++++++++++++++++++++ entities/weapons/hands.lua | 142 +++++++++++++++++++++++++++++++ 7 files changed, 533 insertions(+) create mode 100644 entities/entities/art_chest/cl_init.lua create mode 100644 entities/entities/art_chest/init.lua create mode 100644 entities/entities/art_chest/shared.lua create mode 100644 entities/entities/npc_townie/cl_init.lua create mode 100644 entities/entities/npc_townie/init.lua create mode 100644 entities/entities/npc_townie/shared.lua create mode 100644 entities/weapons/hands.lua (limited to 'entities') diff --git a/entities/entities/art_chest/cl_init.lua b/entities/entities/art_chest/cl_init.lua new file mode 100644 index 0000000..072d421 --- /dev/null +++ b/entities/entities/art_chest/cl_init.lua @@ -0,0 +1,53 @@ +include('shared.lua') +local invfuncs = include("../../../gamemode/shared/inventory_common.lua") + +ENT.RenderGroup = RENDERGROUP_BOTH + +function ENT:Initialize() +end + +function ENT:OnRemove() +end + +function ENT:Think() +end + +function ENT:Draw() + + self:DrawModel() +end + +local oldpanel = nil +net.Receive("openchestinv",function(len,ply) + if oldpanel ~= nil then oldpanel:Remove() end + print("Opening chest inventory") + local what = net.ReadEntity() + local chest = invfuncs.DeSerializeBackpack() + ShowInventory() + local dat = {} + dat.redraw = function() + net.Start("requestchestinv") + net.WriteEntity(what) + net.SendToServer() + end + dat.panel = vgui.Create( "DFrame" ) + oldpanel = dat.panel + dat.panel.OnClose = function() + net.Start("closechestinv") + net.WriteEntity(what) + net.SendToServer() + end + table.insert(LocalPlayer().invdisplays,dat) + local width = ScrW() + local height = ScrH() + local invpanel = dat.panel + invpanel:SetPos( width - (width/4), 0 ) + invpanel:SetSize( width / 4, height ) + invpanel:SetTitle( "Chest" ) + invpanel:SetDraggable( true ) + invpanel:MakePopup() + local innerpanel = vgui.Create("DPanel",dat.panel) + innerpanel:Dock(FILL) + innerpanel.Paint = function( self, w, h ) draw.RoundedBox( 4, 0, 0, w, h, Color( 157, 160, 167 ) ) end + invfuncs.DrawBackpackOnDPanel(innerpanel, chest, 1, what) +end) diff --git a/entities/entities/art_chest/init.lua b/entities/entities/art_chest/init.lua new file mode 100644 index 0000000..92d1371 --- /dev/null +++ b/entities/entities/art_chest/init.lua @@ -0,0 +1,72 @@ +AddCSLuaFile( "cl_init.lua" ) +AddCSLuaFile( "shared.lua" ) + +include("shared.lua") +local invfuncs = include("../../../gamemode/shared/inventory_common.lua") + +function ENT:Initialize() + self.Openedby = {} + self:SetModel("models/props_junk/Rock001a.mdl") + self:PhysicsInit( SOLID_VPHYSICS ) + self:SetMoveType( MOVETYPE_NONE ) + self:SetSolid( SOLID_VPHYSICS ) + self:SetCollisionGroup( COLLISION_GROUP_INTERACTIVE ) + self:SetUseType(SIMPLE_USE) + + local phys = self:GetPhysicsObject() + self.Inventory = {} + self.Inventory.Backpacks = {} + self.Inventory.Backpacks[1] = invfuncs.CreateBackpack("Chest",3,3) + + phys:EnableMotion(false) + phys:Sleep() + + self.StoredItems = {} +end + +util.AddNetworkString("openchestinv") +util.AddNetworkString("closechestinv") +util.AddNetworkString("requestchestinv") + +net.Receive("requestchestinv",function(ln,ply) + print("Received request for chest") + local chest = net.ReadEntity() + print("Chest:",chest) + chest:SendInventory(ply) +end) + +net.Receive("closechestinv",function(ln,ply) + local chest = net.ReadEntity() + print("closeing chest of ", ply,chest) + chest.Openedby[ply] = nil +end) + +function ENT:SendInventory(towho) + print("Sending inventory to",towho,type(towho)) + if type(towho) == "table" then + print("who:") + PrintTable(towho) + print("opendby:") + PrintTable(self.Openedby) + assert(#towho != 0,"Sending inventory to no players!") + else + print("towho is not a table!") + self.Openedby[towho] = true + end + print("about to start net message") + net.Start("openchestinv") + net.WriteEntity(self) + invfuncs.SerializeBackpack(self.Inventory.Backpacks[1]) + net.Send(towho) +end + +function ENT:SynchronizeInventory() + print("Entity synchronize called") + self:SendInventory(table.GetKeys(self.Openedby)) +end + +function ENT:Use(ply) + print("Ply opened:",ply) + self.Openedby[ply] = true + self:SendInventory(ply) +end diff --git a/entities/entities/art_chest/shared.lua b/entities/entities/art_chest/shared.lua new file mode 100644 index 0000000..0038793 --- /dev/null +++ b/entities/entities/art_chest/shared.lua @@ -0,0 +1,2 @@ +ENT.Type = "anim" +ENT.Base = "base_anim" diff --git a/entities/entities/npc_townie/cl_init.lua b/entities/entities/npc_townie/cl_init.lua new file mode 100644 index 0000000..f941737 --- /dev/null +++ b/entities/entities/npc_townie/cl_init.lua @@ -0,0 +1,66 @@ +include('shared.lua') + +ENT.RenderGroup = RENDERGROUP_BOTH + +/*--------------------------------------------------------- + Name: Draw + Desc: Draw it! +---------------------------------------------------------*/ +function ENT:Draw() + self:DrawModel() +end + +/*--------------------------------------------------------- + Name: DrawTranslucent + Desc: Draw translucent +---------------------------------------------------------*/ +function ENT:DrawTranslucent() + + // This is here just to make it backwards compatible. + // You shouldn't really be drawing your model here unless it's translucent + + self:Draw() + +end + +/*--------------------------------------------------------- + Name: BuildBonePositions + Desc: +---------------------------------------------------------*/ +function ENT:BuildBonePositions( NumBones, NumPhysBones ) + + // You can use this section to position the bones of + // any animated model using self:SetBonePosition( BoneNum, Pos, Angle ) + + // This will override any animation data and isn't meant as a + // replacement for animations. We're using this to position the limbs + // of ragdolls. + +end + + + +/*--------------------------------------------------------- + Name: SetRagdollBones + Desc: +---------------------------------------------------------*/ +function ENT:SetRagdollBones( bIn ) + + // If this is set to true then the engine will call + // DoRagdollBone (below) for each ragdoll bone. + // It will then automatically fill in the rest of the bones + + self.m_bRagdollSetup = bIn + +end + + +/*--------------------------------------------------------- + Name: DoRagdollBone + Desc: +---------------------------------------------------------*/ +function ENT:DoRagdollBone( PhysBoneNum, BoneNum ) + + // self:SetBonePosition( BoneNum, Pos, Angle ) + +end diff --git a/entities/entities/npc_townie/init.lua b/entities/entities/npc_townie/init.lua new file mode 100644 index 0000000..aa0f007 --- /dev/null +++ b/entities/entities/npc_townie/init.lua @@ -0,0 +1,75 @@ + +AddCSLuaFile( "cl_init.lua" ) +AddCSLuaFile( "shared.lua" ) + +include('shared.lua') + +function ENT:Initialize() + --print("NPC spawned!") + --self:SetMoveType(MOVETYPE_STEP) + self:SetSolid(SOLID_OBB) + --self:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE) + + if(self.Model) then self:SetModel(self.Model) + else print("NPC created without model, this might be a bug!") end + if(not self.Stats) then + print("NPC created without any stats, this is a bug!") + return + end + if(self.Stats["Vitality"]) then + self:SetHealth(self.Stats["Vitality"]) + else print("NPC created with no stat for vitality, this might be a bug!")end + if(self.Stats["Accel"]) then self.loco:SetAcceleration(self.Stats["Accel"])end + if(self.Stats["Decel"]) then self.loco:SetDeceleration(self.Stats["Decel"]) end + if(self.Stats["Step"]) then self.loco:SetJumpHeight(self.Stats["Step"]) end + if(self.OnSpawn) then self:OnSpawn() end + --self:SetModel( "models/Humans/Group01/Female_01.mdl" ) + --[[ + self:SetHullType( HULL_HUMAN ); + self:SetHullSizeNormal(); + + self:SetSolid( SOLID_BBOX ) + self:SetMoveType( MOVETYPE_STEP ) + + self:CapabilitiesAdd( CAP_MOVE_GROUND or CAP_OPEN_DOORS or CAP_ANIMATEDFACE or CAP_TURN_HEAD or CAP_USE_SHOT_REGULATOR or CAP_AIM_GUN ) + + self:SetMaxYawSpeed( 5000 ) + ]]-- +end + +function ENT:OnInjured(dmg) + --print("Taking some dammage") + local itempos = self:GetPos() + --print("Takeing " .. dmg:GetDamage() .. " health from our " .. self:Health()) + --self:SetHealth(self:Health() - dmg:GetDamage()) + --print("Health is now" .. self:Health()) + if self.OnDammage != nil then self:OnDammage(dmg) end +end + +function ENT:OnContact(ent) + if(ent:GetClass() == "ws_arrow") then + self:TakeDamage(30) + ent:SetParent(self) + end +end + +function ENT:OnKilled(dmg) + if(CLIENT) then return end + if not self.Drops then return end + --print("Looks like we have some drops") + for k,v in pairs(self.Drops) do + local rng = math.random(0,100) + local itemname = self.Drops[k][1] + local itemchance = self.Drops[k][2] + 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 + end + end + self:BecomeRagdoll( dmg ) +end diff --git a/entities/entities/npc_townie/shared.lua b/entities/entities/npc_townie/shared.lua new file mode 100644 index 0000000..3662edd --- /dev/null +++ b/entities/entities/npc_townie/shared.lua @@ -0,0 +1,123 @@ +ENT.Base = "base_nextbot" + +//WS stuff +ENT.Drops = nil +ENT.OnDammage = nil +ENT.Speed = 0 +ENT.Model = nil + +ENT.Behave = nil +ENT.Act = nil + +/*--------------------------------------------------------- + Name: OnRemove + Desc: Called just before entity is deleted +---------------------------------------------------------*/ +function ENT:OnRemove() +end + +--[[ +function ENT:DefaultBehaviour() + while ( true ) do + --Main loop for ai + --print("Going into behavior for " .. self.Name) + --Update aware enemies + local players = ents.FindByClass("Player") + + --Find the enemy with the highest priority + local maxpriority = -1 + local maxprioritytarget = nil + for k,v in pairs(self.AwareEnemies) do + local priority = self:AttackPriority(v) + if(priority == nil) then + print("Nill priority hit after ") + PrintTable(self) + end + if(priority > maxpriority) then + maxpriority = priority + maxprioritytarget = v + end + end + self.Target = maxprioritytarget + + --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)) + self:PlaySequenceAndWait( self.IdleSequences[randanim] ) + self:StartActivity( ACT_IDLE ) + --print("Acting idle") + --If there's noone within 4000 units, just remove ourselves to save server resources + local closest = 5000 + for k,v in pairs(player.GetAll()) do + local thisdist = self:GetPos():Distance(v:GetPos()) + if(thisdist < closest) then + closest = thisdist + end + end + if(closest > 4000) then + print("Closes player is " .. closest .. " removeing self...") + self:BecomeRagdoll(DamageInfo()) + end + else + --We have a target to attack! + + --Find which attack will do the most dammage + local maxdammage = -1 + local maxdammagefunc = nil + for k,v in pairs(self.Attacks) do + local dammagefunc = nil + local attackfunc = nil + for i,j in pairs(v) do + dammagefunc = i + attackfunc = j + end + local dammage = dammagefunc(self, self.Target) + if(dammage > maxdammage) then + maxdammage = dammage + maxdammagefunc = attackfunc + end + end + + --Do that attack + if(maxdammagefunc) then + maxdammagefunc(self, self.Target) + end + end + coroutine.yield() + end + + coroutine.yield() +end +]] + +function ENT:BehaveAct() + if(self.Act) then + self:Act() + else + print("NPC spawned without an Act function, this might be an error!") + end +end + +function ENT:Use() + +end + +function ENT:BehaveUpdate(num) + --print(num) + --self:BehaveUpdate(num) + + if(self.BehaveUpdate) then + self:BehaveUpdate(num) + end + +end + +function ENT:RunBehaviour() + if(self.Behave) then + self:Behave() + else + self:DefaultBehaviour() + end +end diff --git a/entities/weapons/hands.lua b/entities/weapons/hands.lua new file mode 100644 index 0000000..3d74aa3 --- /dev/null +++ b/entities/weapons/hands.lua @@ -0,0 +1,142 @@ +AddCSLuaFile("hands.lua") + +SWEP.ViewModel = ""--"models/error.mdl" +SWEP.WorldModel = ""--"models/error.mdl" + +SWEP.HoldType = "normal" + +SWEP.Primary.ClipSize = -1 +SWEP.Primary.DefaultClip = -1 +SWEP.Primary.Automatic = true +SWEP.Primary.Ammo = "none" + +SWEP.Secondary.Clipsize = -1 +SWEP.Secondary.DefaultClip = -1 +SWEP.Secondary.Automatic = false +SWEP.Secondary.Ammo = "none" + +SWEP.DrawAmmo = false +SWEP.DrawCrosshair = false + +function SWEP:Initialize() + self:SetWeaponHoldType(self.HoldType) + self:DrawShadow(false) + self:SetNoDraw(true) + + --[[ + if (CLIENT) then + self.MOB = ClientsideModel("error.mdl") + self.MOB:SetNoDraw(true) + self.MOB:DrawShadow(false) + end + ]] +end + +function SWEP:ShouldDropOnDie() + return false +end + +function SWEP:Think() +end + +function SWEP:Reload() +end + +local Box = Vector(8,8,8) + +function SWEP:PrimaryAttack() + local rightitem = self.Owner.Inventory.Equiped["Left"] + if rightitem ~= false and rightitem.onClick ~= nil then + rightitem:onClick(self.Owner) + end + --[[ + if (CLIENT and !IsFirstTimePredicted()) then return end + if (!self.Owner.Weapons or !self.Owner.Weapons[self.Owner.Select]) then return end + if (self.Owner.CD and self.Owner.CD > CurTime()) then return end + + local item = self.Owner.Weapons[self.Owner.Select].Item + + if (!item or !item.OnPrimary) then return end + + self.Owner:SetAnimation( PLAYER_ATTACK1 ) + + local Trace = { + start = self.Owner:GetShootPos(), + endpos = self.Owner:GetShootPos()+self.Owner:GetAimVector()*item.Range, + filter = self.Owner, + mins = Box*-1, + maxs = Box, + } + + local Tr = util.TraceHull(Trace) + + item:OnPrimary(self.Owner,Tr) + + self.Owner.CD = CurTime()+item.CD + ]] +end + +function SWEP:SecondaryAttack() + --[[ + if (CLIENT and !IsFirstTimePredicted()) then return end + if (!self.Owner.Weapons or !self.Owner.Weapons[self.Owner.Select]) then return end + if (self.Owner.CD and self.Owner.CD > CurTime()) then return end + + local item = self.Owner.Weapons[self.Owner.Select].Item + + if (!item or !item.OnSecondary) then return end + + self.Owner:SetAnimation( PLAYER_ATTACK1 ) + + local Trace = { + start = self.Owner:GetShootPos(), + endpos = self.Owner:GetShootPos()+self.Owner:GetAimVector()*item.Range, + filter = self.Owner, + mins = Box*-1, + maxs = Box, + } + + local Tr = util.TraceHull(Trace) + + item:OnSecondary(self.Owner,Tr) + + self.Owner.CD = CurTime()+item.CD + ]] +end + +if (CLIENT) then + local Zero = Vector(1,1,1) + --[[ + function SWEP:DrawWorldModel() + if (!self.Owner.Weapons or !self.Owner.Weapons[self.Owner.Select]) then return end + + local item = self.Owner.Weapons[self.Owner.Select].Item + + for k,v in pairs(item.Structure) do + local ID = self.Owner:LookupBone(v.Bone) + local Pos,Ang = self.Owner:GetBonePosition(ID) + + local Offset = v.Pos*1 + Offset:Rotate(Ang) + Pos = Pos + Offset + + local Dang = Ang*1 + + Ang:RotateAroundAxis(Dang:Right(),v.Ang.p) + Ang:RotateAroundAxis(Dang:Up(),v.Ang.y) + Ang:RotateAroundAxis(Dang:Forward(),v.Ang.r) + + self.MOB:SetModel(v.Model) + self.MOB:SetRenderOrigin(Pos) + self.MOB:SetRenderAngles(Ang) + + local mat = Matrix() + mat:Scale( v.Size or Zero ) + + self.MOB:EnableMatrix( "RenderMultiply", mat ) + self.MOB:SetupBones() + self.MOB:DrawModel() + end + end + ]] +end -- cgit v1.2.3-70-g09d2