Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local me = Ply"oh"
- local ENT = {}
- do -- ENT
- ENT.Type = "anim"
- ENT.Base = "base_entity"
- ENT.Bottom = Vector(-0.53724020719528,-0.059773083776236,-34.8798828125)
- ENT.ClassName = "player_physics"
- function ENT:GetBottom()
- return self:LocalToWorld(self.Bottom)
- end
- function ENT:GetEyePos()
- return self:GetBottom() + self:GetUp() * 64
- end
- function ENT:HasPlayer()
- return self:GetOwner():IsPlayer()
- end
- function ENT:GetPlayer()
- return self:GetOwner():IsPlayer() and self:GetOwner() or NULL
- end
- if CLIENT then
- function ENT:Draw()
- self:DrawModel()
- end
- else
- function ENT:Initialize()
- self:SetModel("models/props_wasteland/controlroom_filecabinet002a.mdl")
- self:SetMoveType(MOVETYPE_VPHYSICS)
- self:PhysicsInit(SOLID_VPHYSICS)
- self:SetCollisionGroup(SOLID_VPHYSICS)
- self:SetMaterial("models/wireframe")
- self:StartMotionController()
- self:NextThink(CurTime()+2)
- end
- function ENT:SetPlayer(ply)
- self:RemovePlayer()
- self:SetPos(ply:EyePos())
- ply:SetPos(self:GetEyePos())
- ply:SetMoveType(MOVETYPE_NOCLIP)
- self:SetOwner(ply)
- ply:SetOwner(self)
- ply:SetParent(self)
- ply:SetNotSolid(true)
- ply:SetViewOffset(vector_origin)
- ply:SetViewOffsetDucked(vector_origin) -- view offset will fix player parent rotation
- end
- function ENT:OnRemove()
- local ply = self:GetPlayer()
- if ply:IsPlayer() then
- ply:SetParent()
- ply:SetOwner()
- ply:SetPos(self:GetEyePos())
- ply:SetMoveType(MOVETYPE_WALK)
- ply:SetViewOffset(Vector(0,0,64))
- ply:SetViewOffsetDucked(Vector(0,0,28))
- end
- end
- ENT.RemovePlayer = ENT.OnRemove
- function ENT:PhysicsSimulate(phys, delta)
- local ply = self:GetPlayer()
- if ply:IsPlayer() then
- hook.Call("PlayerPhysicsMove", nil, ply, phys)
- end
- end
- function ENT:Think()
- if not self:HasPlayer() then self:Remove() end
- self:NextThink(CurTime()+2)
- return true
- end
- end
- scripted_ents.Register(ENT, ENT.ClassName, true)
- end
- do -- meta
- do -- player
- local player_meta = FindMetaTable("Player")
- function player_meta:HasPlayerPhysics()
- return self:GetParent().ClassName == "player_physics"
- end
- function player_meta:GetPlayerPhysics()
- return self:HasPlayerPhysics() and self:GetParent() or NULL
- end
- if SERVER then
- function player_meta:SetPlayerPhysics(bool)
- if bool and not self:HasPlayerPhysics() then
- local entity = ents.Create(ENT.ClassName)
- entity:Spawn()
- entity:SetPlayer(self)
- elseif bool == false and self:HasPlayerPhysics() then
- self:GetPlayerPhysics():Remove()
- end
- end
- end
- end
- end
- do -- hooks
- hook.Add("Move", "player_physics", function(ply)
- if ply:HasPlayerPhysics() then
- return true
- end
- end)
- if CLIENT then
- hook.Add("UpdateAnimation", "player_physics", function(ply)
- if ply:HasPlayerPhysics() then
- if ply == LocalPlayer() and not ply:ShouldDrawLocalPlayer() then return end
- local self = ply:GetPlayerPhysics()
- ply:SetPos(self:GetBottom())
- ply:SetRenderOrigin(ply:GetPos())
- ply:SetAngles(self:GetAngles())
- ply:SetRenderAngles(ply:GetAngles())
- ply:SetupBones()
- hook.Call("UdpdatePlayerPhysicsAnimation", nil, ply, self)
- end
- end)
- else
- end
- end
- --[[
- do return end
- timer.Simple(1, function()
- for key, entity in pairs(ents.FindByClass(ENT.ClassName)) do
- table.Merge(entity:GetTable(), ENT)
- -- entity:Initialize()
- end
- if SERVER then
- if #ents.FindByClass(ENT.ClassName) > 0 then return end
- local trace = me:GetEyeTrace()
- local entity = ents.Create(ENT.ClassName)
- entity:Spawn()
- entity:SetPos(trace.HitPos + Vector(0,0,entity:BoundingRadius()))
- entity:DropToFloor()
- entity:SetPlayer(Entity(10))
- undo.Create(ENT.ClassName)
- undo.SetPlayer(me)
- undo.AddEntity(entity)
- undo.Finish()
- end
- end)]]
Advertisement
Add Comment
Please, Sign In to add comment