diff options
Diffstat (limited to 'entities')
| -rw-r--r-- | entities/entities/art_droppeditem/cl_init.lua | 99 | ||||
| -rw-r--r-- | entities/entities/art_droppeditem/init.lua | 80 | ||||
| -rw-r--r-- | entities/entities/art_droppeditem/shared.lua | 17 | ||||
| -rw-r--r-- | entities/entities/npc_huntable/init.lua | 3 | ||||
| -rw-r--r-- | entities/weapons/hands.lua | 6 |
5 files changed, 198 insertions, 7 deletions
diff --git a/entities/entities/art_droppeditem/cl_init.lua b/entities/entities/art_droppeditem/cl_init.lua new file mode 100644 index 0000000..eb4b21f --- /dev/null +++ b/entities/entities/art_droppeditem/cl_init.lua @@ -0,0 +1,99 @@ +include('shared.lua') + +ENT.RenderGroup = RENDERGROUP_BOTH + +/*--------------------------------------------------------- + Name: Draw + Desc: Draw it! +---------------------------------------------------------*/ +function ENT:Draw() + self:SetAngles(Angle(180,(CurTime()*200)%360,0)) + if(self:GetColor().a == 255) then + self:DrawModel() + end +end + +local lp +local sentrequests = {} +hook.Add("Tick","pickupitemstick",function() + lp = lp or LocalPlayer() + local ae = ents.FindInSphere(lp:GetPos(),5) + for k,v in pairs(ae) do + local ei = v:EntIndex() + if (not sentrequests[ei]) and v.GetClass and v:GetClass() == "art_droppeditem" then + print("Sending request to pick up", ei) + net.Start("art_requestpickup") + net.WriteUInt(ei,16) + net.SendToServer() + sentrequests[ei] = true + timer.Simple(5,function() + sentrequests[ei] = nil + end) + end + end +end) + + +net.Receive("art_informmodel",function() + print("Player received model information") + local ei = net.ReadUInt(16) + local m = net.ReadString() + local e = Entity(ei) + e:SetModel(m) + e.newmodel = m +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/art_droppeditem/init.lua b/entities/entities/art_droppeditem/init.lua new file mode 100644 index 0000000..de27e6d --- /dev/null +++ b/entities/entities/art_droppeditem/init.lua @@ -0,0 +1,80 @@ +--[[ + This entity gives townies things to do +]] +AddCSLuaFile( "cl_init.lua" ) +AddCSLuaFile( "shared.lua" ) + +include("shared.lua") + +util.AddNetworkString("art_requestmodel") +util.AddNetworkString("art_informmodel") +util.AddNetworkString("art_requestpickup") + +function ENT:Initialize() + self:SetModel(self.Model or "models/error.mdl") + assert(self.Item ~= nil, "Attempted to drop something without .Item set!") + self.ItemName = self.Item.Name + 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) + end + self:SetMoveType(MOVETYPE_NONE) + self:SetSolid(SOLID_NONE) + self:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE) +end + +--A client is near enough to draw the item, tell them what to draw. +net.Receive("art_requestmodel",function(len,pl) + print(pl," requested a model") + local ei = net.ReadUInt(16) + local e = Entity(ei) + assert(e.Model ~= nil,"Attempted to request model for non-art_droppeditem entity") + net.Start("art_informmodel") + net.WriteUInt(ei,16) + net.WriteString(e.Model) + net.Send(pl) +end) + +net.Receive("art_requestpickup",function(len,pl) + local ei = net.ReadUInt(16) + local e = Entity(ei) + print("Got request to pick up", e) + local ep = e:GetPos() + print("got ep pos") + local plp = pl:GetPos() + print("got pl pos") + local d = ep:Distance(plp) + print("Got distance") + if d < 30 then + print("Inside if statement") + local i = ART.GetItemByName(e.ItemName):DeSerialize(e.ItemData) + print("Created item") + if pl:GiveItem(i) then + print("In if") + e:Remove() + end + print("Removed item") + else + print("Player not close enough!") + end +end) + +function ENT:Use(activator, caller, usetype) + print("a",activator,"c",caller,"u",usetype) +end + +print("Remove the concommand in art_droppeditem/init.lua") +concommand.Add("dropmellon",function(ply,cmd,args) + local e = ents.Create("art_droppeditem") + e.Model = "models/props_junk/Rock001a.mdl" + e.Item = ART.GetItemByName("Watermelon") + local hitpos = ply:GetEyeTrace().HitPos + Vector(0,0,10) + print("Traceresult was") + PrintTable(ply:GetEyeTrace()) + print("Hitpos was", hitpos) + e:SetPos(hitpos) + e:Spawn() +end) diff --git a/entities/entities/art_droppeditem/shared.lua b/entities/entities/art_droppeditem/shared.lua new file mode 100644 index 0000000..a72fcf8 --- /dev/null +++ b/entities/entities/art_droppeditem/shared.lua @@ -0,0 +1,17 @@ +ENT.Base = "base_entity" + +//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 diff --git a/entities/entities/npc_huntable/init.lua b/entities/entities/npc_huntable/init.lua index b136878..3adf3e2 100644 --- a/entities/entities/npc_huntable/init.lua +++ b/entities/entities/npc_huntable/init.lua @@ -48,7 +48,8 @@ function ENT:OnKilled(dmg) if (CLIENT) then return end if not self.Drops then return end --print("Looks like we have some drops") - error("You need to code how item drops work!") + --error("You need to code how item drops work!") + local itemstodrop = {} for k, v in pairs(self.Drops) do local rng = math.random(0, 100) diff --git a/entities/weapons/hands.lua b/entities/weapons/hands.lua index c97249a..e0b1ae6 100644 --- a/entities/weapons/hands.lua +++ b/entities/weapons/hands.lua @@ -36,12 +36,6 @@ function SWEP:ShouldDropOnDie() return false end -function SWEP:Think() -end - -function SWEP:Reload() -end - local Box = Vector(8,8,8) function SWEP:PrimaryAttack() |
