Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (SERVER) then AddCSLuaFile() end
- ENT.Type = "anim"
- ENT.Base = "base_anim"
- ENT.Spawnable = true
- ENT.AdminSpawnable = true
- ENT.Category = "DayZ Modules"
- ENT.PrintName = "Backpack Base"
- ENT.Author = "Zephruz"
- ENT.Contact = "ScriptFodder"
- ENT.RenderGroup = RENDERGROUP_TRANSLUCENT
- function ENT:SetupDataTables()
- self:NetworkVar("String", 0, "BPType")
- self:NetworkVar("Entity", 0, "BPOwner")
- end
- function ENT:Initialize()
- self.BackpackItems = {}
- if (SERVER) then
- self:SetUseType( SIMPLE_USE )
- self:SetupBPInfo("small_backpack")
- self:NetworkVarNotify( "BPOwner", self.OnVarChanged )
- end
- end
- if (CLIENT) then
- function ENT:Draw()
- local bpOwn = self:GetBPOwner()
- -- self:SetPos(self:GetPos())
- if (!self.GetBPOwner or !self:GetBPOwner():IsValid()) then
- self:DrawModel()
- else
- local m = Matrix()
- local att = bpOwn:GetAttachment(bpOwn:LookupAttachment("chest"))
- m:Translate(att.Pos)
- m:Rotate(att.Ang)
- m:Translate(Vector(-9, 2, -5))
- m:Rotate(Angle(0, 180, 0))
- self:SetPos(m:GetTranslation())
- self:SetAngles(m:GetAngles())
- if (self:GetBPOwner() == LocalPlayer()) then
- if (GMODZ_bThirdPerson) then
- self:DrawModel()
- end
- else
- self:DrawModel()
- end
- end
- self:DrawShadow(false)
- end
- function ENT:OnRemove()
- local bpModel = self.BPModel
- if (bpModel && bpModel:IsValid()) then
- bpModel:Remove()
- end
- end
- end
- if (SERVER) then
- util.AddNetworkString("DZ_Backpacks.OpenGUI")
- function ENT:Think()
- if (self.GetBPOwner && self:GetBPOwner() && self:GetBPOwner():IsValid()) then
- if (self:GetPos():Distance(self:GetBPOwner():GetPos()) > 350) then
- self:SetPos(self:GetBPOwner():GetPos())
- end
- end
- end
- ENT.NTTime = os.time() + 0.2
- function ENT:Touch(ent)
- if (!ent or !ent:IsValid()) then return false end
- if (self.NTTime > os.time()) then return false end
- self.NTTime = os.time() + 0.2
- local bpAllI = DZ_Backpacks.AllowedItems
- for i=1,#bpAllI do
- if (!ent:GetClass():find(bpAllI[i])) then return false end
- end
- self:AddItem({
- name = ent.PrintName,
- class = ent:GetClass(),
- model = ent:GetModel(),
- amt = 1,
- })
- ent:Remove()
- return true
- end
- function ENT:SetupBPInfo(bpid)
- local bptype = DZ_Backpacks.Types[bpid]
- if (bptype) then
- self:SetBPType(bpid)
- self:SetModel( table.Random(bptype.models) )
- self:SetCollisionGroup( COLLISION_GROUP_NONE )
- self:PhysicsInit( SOLID_VPHYSICS )
- self:SetSolid( SOLID_VPHYSICS )
- self:PhysWake()
- self:DropToFloor()
- end
- end
- function ENT:Use( act, call, t, use )
- if (call:GetBackpack() && call:GetBackpack() == self) then return false end
- net.Start("DZ_Backpacks.OpenGUI")
- net.WriteEntity(self)
- net.WriteTable(self.BackpackItems)
- net.Send(call)
- end
- function ENT:OnVarChanged(name, old, new)
- if (name == "BPOwner") then
- if (new && new:IsValid() && new:IsPlayer()) then
- self:SetPos(new:GetPos())
- self:SetParent(new, 0)
- else
- if (old && old:IsValid() && old:IsPlayer()) then
- self:SetPos(old:GetPos() + ply:GetForward()*100 + Vector(0,0,50))
- end
- self:SetParent(nil)
- self:Respawn()
- end
- end
- end
- function ENT:AddItem(data)
- local bpInfo = (self.GetBPType && self:GetBPType() or false)
- bpInfo = (bpInfo && DZ_Backpacks.Types[bpInfo])
- if (bpInfo) then
- if (table.Count(self.BackpackItems) > (bpInfo.size or 12)) then
- return false
- end
- end
- local has = false
- for i=1,table.Count(self.BackpackItems) do
- if (self.BackpackItems[i].class == data.class) then
- has = i
- end
- end
- if (has) then
- self.BackpackItems[has].amt = self.BackpackItems[has].amt + data.amt
- else
- table.insert(self.BackpackItems, data)
- end
- if (self.GetBPOwner && self:GetBPOwner():IsValid()) then
- DZ_Backpacks.Data:UpdatePlayer(self:GetBPOwner(), {
- type_bp = (self:GetBPType() or "small_backpack"),
- cont_bp = (self.BackpackItems or {}),
- })
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement