Python1320

Untitled

Jan 9th, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.99 KB | None | 0 0
  1. local me = Ply"oh"
  2.  
  3. local ENT = {}
  4.  
  5. do -- ENT
  6.  
  7.     ENT.Type = "anim"
  8.     ENT.Base = "base_entity"
  9.  
  10.     ENT.Bottom = Vector(-0.53724020719528,-0.059773083776236,-34.8798828125)
  11.     ENT.ClassName = "player_physics"
  12.  
  13.     function ENT:GetBottom()
  14.         return self:LocalToWorld(self.Bottom)
  15.     end
  16.  
  17.     function ENT:GetEyePos()
  18.         return self:GetBottom() + self:GetUp() * 64
  19.     end
  20.  
  21.     function ENT:HasPlayer()
  22.         return self:GetOwner():IsPlayer()
  23.     end
  24.  
  25.     function ENT:GetPlayer()
  26.         return self:GetOwner():IsPlayer() and self:GetOwner() or NULL
  27.     end
  28.  
  29.     if CLIENT then
  30.  
  31.         function ENT:Draw()
  32.             self:DrawModel()
  33.         end
  34.        
  35.     else
  36.        
  37.         function ENT:Initialize()
  38.             self:SetModel("models/props_wasteland/controlroom_filecabinet002a.mdl")
  39.        
  40.             self:SetMoveType(MOVETYPE_VPHYSICS)
  41.             self:PhysicsInit(SOLID_VPHYSICS)
  42.             self:SetCollisionGroup(SOLID_VPHYSICS)
  43.            
  44.             self:SetMaterial("models/wireframe")
  45.            
  46.             self:StartMotionController()
  47.            
  48.             self:NextThink(CurTime()+2)
  49.         end
  50.  
  51.         function ENT:SetPlayer(ply)
  52.             self:RemovePlayer()
  53.            
  54.             self:SetPos(ply:EyePos())
  55.            
  56.             ply:SetPos(self:GetEyePos())
  57.        
  58.             ply:SetMoveType(MOVETYPE_NOCLIP)
  59.            
  60.             self:SetOwner(ply)
  61.             ply:SetOwner(self)
  62.             ply:SetParent(self)
  63.             ply:SetNotSolid(true)
  64.            
  65.             ply:SetViewOffset(vector_origin)
  66.             ply:SetViewOffsetDucked(vector_origin) -- view offset will fix player parent rotation
  67.         end
  68.            
  69.         function ENT:OnRemove()
  70.             local ply = self:GetPlayer()
  71.            
  72.             if ply:IsPlayer() then
  73.                 ply:SetParent()
  74.                 ply:SetOwner()
  75.                
  76.                 ply:SetPos(self:GetEyePos())
  77.                
  78.                 ply:SetMoveType(MOVETYPE_WALK)
  79.                
  80.                 ply:SetViewOffset(Vector(0,0,64))
  81.                 ply:SetViewOffsetDucked(Vector(0,0,28))
  82.             end
  83.         end
  84.        
  85.         ENT.RemovePlayer = ENT.OnRemove
  86.  
  87.         function ENT:PhysicsSimulate(phys, delta)
  88.             local ply = self:GetPlayer()
  89.            
  90.             if ply:IsPlayer() then
  91.                 hook.Call("PlayerPhysicsMove", nil, ply, phys)
  92.             end
  93.         end
  94.        
  95.         function ENT:Think()
  96.             if not self:HasPlayer() then self:Remove() end
  97.             self:NextThink(CurTime()+2)
  98.             return true
  99.         end
  100.     end
  101.  
  102.     scripted_ents.Register(ENT, ENT.ClassName, true)
  103. end
  104.  
  105. do -- meta 
  106.     do -- player
  107.        
  108.         local player_meta = FindMetaTable("Player")
  109.  
  110.         function player_meta:HasPlayerPhysics()
  111.             return self:GetParent().ClassName == "player_physics"
  112.         end
  113.  
  114.         function player_meta:GetPlayerPhysics()
  115.             return self:HasPlayerPhysics() and self:GetParent() or NULL
  116.         end
  117.        
  118.         if SERVER then
  119.             function player_meta:SetPlayerPhysics(bool)        
  120.                 if bool and not self:HasPlayerPhysics() then
  121.                     local entity = ents.Create(ENT.ClassName)
  122.                     entity:Spawn()
  123.                     entity:SetPlayer(self)
  124.                 elseif bool == false and self:HasPlayerPhysics() then
  125.                     self:GetPlayerPhysics():Remove()                   
  126.                 end
  127.             end
  128.         end
  129.     end
  130. end
  131.  
  132. do -- hooks
  133.     hook.Add("Move", "player_physics", function(ply)
  134.         if ply:HasPlayerPhysics() then
  135.             return true
  136.         end
  137.     end)
  138.  
  139.     if CLIENT then
  140.  
  141.         hook.Add("UpdateAnimation", "player_physics", function(ply)
  142.             if ply:HasPlayerPhysics() then
  143.                 if ply == LocalPlayer() and not ply:ShouldDrawLocalPlayer() then return end
  144.                
  145.                 local self = ply:GetPlayerPhysics()
  146.                
  147.                 ply:SetPos(self:GetBottom())
  148.                 ply:SetRenderOrigin(ply:GetPos())
  149.                 ply:SetAngles(self:GetAngles())
  150.                 ply:SetRenderAngles(ply:GetAngles())
  151.                 ply:SetupBones()
  152.                
  153.                 hook.Call("UdpdatePlayerPhysicsAnimation", nil, ply, self)
  154.             end
  155.         end)
  156.        
  157.     else
  158.  
  159.     end
  160. end
  161.  
  162. --[[
  163. do return end
  164.  
  165. timer.Simple(1, function()
  166.  
  167.     for key, entity in pairs(ents.FindByClass(ENT.ClassName)) do
  168.         table.Merge(entity:GetTable(), ENT)
  169.     --  entity:Initialize()
  170.     end
  171.  
  172.     if SERVER then
  173.         if #ents.FindByClass(ENT.ClassName) > 0 then return end
  174.  
  175.         local trace = me:GetEyeTrace()
  176.        
  177.         local entity = ents.Create(ENT.ClassName)
  178.         entity:Spawn()
  179.         entity:SetPos(trace.HitPos + Vector(0,0,entity:BoundingRadius()))
  180.         entity:DropToFloor()
  181.        
  182.         entity:SetPlayer(Entity(10))
  183.        
  184.         undo.Create(ENT.ClassName)
  185.             undo.SetPlayer(me)
  186.             undo.AddEntity(entity)
  187.         undo.Finish()
  188.     end
  189.    
  190. end)]]
Advertisement
Add Comment
Please, Sign In to add comment