Advertisement
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()
- render.CullMode(1)
- render.SetBlend(0.9)
- render.SetColorModulation(0.2, 0.2, 0.2)
- self:DrawModel()
- render.SetColorModulation(1, 1, 1)
- render.SetBlend(1)
- render.CullMode(0)
- end
- else
- function ENT:Initialize()
- self:SetModel("models/props_wasteland/controlroom_filecabinet002a.mdl")
- self:SetMoveType(MOVETYPE_VPHYSICS)
- self:PhysicsInit(SOLID_VPHYSICS)
- self:SetMaterial("models/debug/debugwhite")
- self:StartMotionController()
- self:NextThink(CurTime()+2)
- end
- function ENT:SetPlayer(ply)
- self:RemovePlayer()
- ply:SetViewOffset(vector_origin)
- ply:SetViewOffsetDucked(vector_origin + Vector(0,0,1)) -- view offset will fix player parent rotation
- self:SetPos(ply:GetPos())
- ply:SetMoveType(MOVETYPE_NOCLIP)
- ply:SetParent(self)
- ply:SetNotSolid(true)
- self:SetOwner(ply)
- ply:SetOwner(self)
- ply.__player_physics_request_duck = true
- self:PhysWake()
- end
- function ENT:OnRemove()
- local ply = self:GetPlayer()
- if ply:IsPlayer() then
- ply:SetParent()
- ply:SetOwner()
- ply:SetMoveType(MOVETYPE_WALK)
- ply.__player_physics_request_duck = true
- 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("PPhys", nil, ply, self, phys)
- end
- end
- function ENT:Think()
- if not self:HasPlayer() then self:Remove() return end
- if self:GetPlayer():GetPos():Distance(self:GetPos()) > 200 then
- self:GetPlayer():SetPos(self:GetEyePos())
- end
- self:NextThink(CurTime()+2)
- return true
- end
- end
- scripted_ents.Register(ENT, ENT.ClassName, true)
- end
- do -- meta
- do -- player
- ENT.OldMetaFunctions = ENT.OldMetaFunctions or {
- entity = {},
- player = {},
- }
- local oldmeta = ENT.OldMetaFunctions
- local player_meta = FindMetaTable("Player")
- local entity_meta = FindMetaTable("Entity")
- function player_meta:HasPlayerPhysics()
- return self:GetParent().ClassName == "player_physics"
- end
- function player_meta:GetPlayerPhysics()
- return self:HasPlayerPhysics() and self:GetParent() or NULL
- end
- oldmeta.player.GetPlayerTrace = oldmeta.player.GetPlayerTrace or util.GetPlayerTrace
- function util.GetPlayerTrace(ply, dir, ...)
- if ply and ply:IsPlayer() and ply:HasPlayerPhysics() then
- dir = dir or ply:GetAimVector()
- local trace = {}
- trace.start = ply:EyePos()
- trace.endpos = trace.start + (dir * 4096 * 4)
- trace.filter = {ply, ply:GetPlayerPhysics()}
- return trace
- end
- return oldmeta.player.GetPlayerTrace(ply, dir, ...)
- 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)
- return entity
- elseif bool == false and self:HasPlayerPhysics() then
- self:GetPlayerPhysics():Remove()
- end
- end
- oldmeta.entity.SetPos = oldmeta.entity.SetPos or entity_meta.SetPos
- function entity_meta:SetPos(command, ...)
- if self and not (self:IsPlayer() and self:HasPlayerPhysics()) then
- return oldmeta.entity.SetPos(self, command, ...)
- end
- end
- oldmeta.player.Give = oldmeta.player.Give or player_meta.Give
- function player_meta:Give(class, ...)
- if self and type(class) == "string" and self:HasPlayerPhysics() then
- local player_phys = self:GetPlayerPhysics()
- self:SetParent()
- local ent = self:Give(class, ...)
- self:SetParent(player_phys)
- return ent
- end
- return oldmeta.player.Give(self, class, ...)
- end
- end
- end
- end
- do -- hooks
- hook.Add("ShouldCollide", "player_physics", function(a, b)
- if a:IsPlayer() and a:GetPlayerPhysics() == b or b:IsPlayer() and b:GetPlayerPhysics() == a then
- return false
- end
- end)
- hook.Add("Move", "player_physics", function(ply, ucmd)
- if ply.__player_physics_request_duck then
- ucmd:SetVelocity(vector_origin)
- ply.__player_physics_request_duck = nil
- end
- if ply:HasPlayerPhysics() then
- return true
- end
- end)
- local function Disallow(ply, ent)
- if ply:GetPlayerPhysics() == ent then
- return false
- end
- end
- hook.Add("GravGunPickupAllowed", "player_physics", Disallow)
- hook.Add("GravGunPunt", "player_physics", Disallow)
- hook.Add("PhysgunPickup", "player_physics", Disallow)
- if CLIENT then
- local ply = LocalPlayer()
- hook.Add("CreateMove", "player_physics", function(ucmd)
- ply = ply:IsPlayer() and ply or LocalPlayer()
- if ply:HasPlayerPhysics() then
- ucmd:SetButtons(ucmd:GetButtons() | IN_DUCK)
- end
- end)
- hook.Add("UpdateAnimation", "player_physics", function(ply)
- if ply:HasPlayerPhysics() then
- local self = ply:GetPlayerPhysics()
- if ply == LocalPlayer() and not ply:ShouldDrawLocalPlayer() then return end
- ply:SetPos(self:GetBottom())
- ply:SetRenderOrigin(ply:GetPos())
- ply:SetAngles(self:GetAngles())
- ply:SetRenderAngles(ply:GetAngles())
- ply:SetupBones()
- hook.Call("PPhys", nil, ply, self, NULL)
- end
- end)
- hook.Add("CalcView", "player_physics", function(ply,pos,ang,fov)
- if LocalPlayer():HasPlayerPhysics() then
- local new_pos, new_ang = hook.Call("PPhys", nil, ply, ply:GetPlayerPhysics(), NULL)
- if new_pos or new_ang then
- pos = new_pos or pos
- pos = new_ang or ang
- return GAMEMODE:CalcView(ply,pos,ang,fov)
- end
- end
- end)
- else
- local me = nero.GetPlayer"oh"
- me:SetPlayerPhysics(false)
- timer.Simple(0.2, function()
- local ent = me:SetPlayerPhysics(true)
- undo.Create("player_physics")
- undo.SetPlayer(me)
- undo.AddEntity(ent)
- undo.Finish()
- end)
- end
- end
- do -- example
- hook.Add("PPhys", 0, function(ply, ent, phys)
- if CLIENT then
- --prediction
- end
- if SERVER then
- phys:EnableGravity(false)
- local ang = ply:EyeAngles()
- phys:AddAngleVelocity(ang * 0.12)
- phys:AddAngleVelocity(phys:GetAngleVelocity() * - 0.1)
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement