Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if SERVER then AddCSLuaFile"shared.lua" end
- ENT.Type = "anim"
- ENT.Base = "base_anim"
- ENT.PrintName = "Noclip Anchor"
- ENT.RenderGroup = RENDERGROUP_TRANSLUCENT
- function ENT:Initialize()
- if ( SERVER ) then
- self.Entity:SetModel( "models/props_c17/TrapPropeller_Engine.mdl" )
- self.Entity:SetColor( 255, 0, 0, 255 )
- self.Entity:PhysicsInit( SOLID_VPHYSICS )
- self.Entity:SetSolid( SOLID_VPHYSICS )
- self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
- self:SetNWInt("Radius", 350)
- self:SetNWBool("Active", true)
- self:SetUseType( SIMPLE_USE ) --Don't keep using :/
- --Wiremod support
- if not (WireAddon == nil) and Wire_CreateInputs then
- self.Inputs = Wire_CreateInputs( self, {"Active", "Anchor Distance"} )
- end
- else
- self.Mat = Material("sprites/sent_ball")
- end
- end
- --Accessors for Active and Radius
- function ENT:Active()
- return self:GetNWBool("Active", false)
- end
- function ENT:Radius()
- return self:GetNWInt("Radius", 350)
- end
- function ENT:SetActive( bool )
- self:SetNWBool( "Active", bool )
- end
- function ENT:SetRadius( radius )
- self:SetNWInt( "Radius", radius )
- end
- --Wiremod support
- function ENT:TriggerInput( name, value )
- if name == "Active" then
- if value >= 1 then
- self:SetActive( true )
- else
- self:SetActive( false )
- end
- elseif name == "Anchor Distance" then
- if value >= 0 then
- self:SetRadius( value )
- end
- end
- end
- //
- // Note - the classname isn't always going to be the same
- // So use ClassName instead of a static string.
- //
- // This function puts the entity in the map.. and must be defined.
- //
- function ENT:SpawnFunction( ply, tr )
- if ( !tr.Hit ) then return end
- local SpawnPos = tr.HitPos + tr.HitNormal * 16
- --Must be admin or in singleplayer
- if not ply:IsAdmin() and not SinglePlayer() then
- return
- end
- local ent = ents.Create( ClassName )
- ent:SetPos( SpawnPos )
- ent:Spawn()
- ent:Activate()
- self.Spawner = ply
- return ent
- end
- function ENT:TClass()
- return "noclip_anchor"
- end
- --Stop people already noclipping
- --We don't really need to hook Tick here, this is good enough
- function ENT:Think()
- if self:Active() then
- local e = ents.FindInSphere(self:GetPos(), self:Radius())
- for _,v in ipairs(e) do
- if v:IsPlayer() and v:GetMoveType() == MOVETYPE_NOCLIP then
- v:SetMoveType(MOVETYPE_WALK)
- end
- end
- end
- end
- --Use support (so simple!)
- function ENT:Use( activator, caller )
- self:SetActive( !self:Active() )
- end
- if CLIENT then
- hook.Add("HUDPaint", "AnchorDist", function()
- local ent = LocalPlayer():GetEyeTrace().Entity
- if ent.TClass and ent:TClass() == "noclip_anchor" and ent:GetPos():Distance( LocalPlayer():GetPos() ) < 300 then
- local p = ( ent:GetPos() + ent:OBBCenter() ):ToScreen()
- local Indicator = Color(0, 255, 0, 255)
- local Indicator_Text = "On"
- if not ent:Active() then
- Indicator = Color(255, 0, 0, 255)
- Indicator_Text = "Off"
- end
- surface.SetFont( "Default" )
- local Len = surface.GetTextSize( Indicator_Text )
- surface.SetDrawColor( 80, 80, 80, 255 )
- surface.DrawRect( p.x - Len, p.y - 9 - 40, Len * 2, 18 )
- surface.SetDrawColor( Indicator.r, Indicator.g, Indicator.b, 255 )
- surface.DrawOutlinedRect( p.x - Len, p.y - 9 - 40, Len * 2, 18 )
- draw.SimpleText( Indicator_Text,
- "Default",
- p.x,
- p.y - 40,
- Indicator,
- TEXT_ALIGN_CENTER,
- TEXT_ALIGN_CENTER )
- draw.SimpleText( "Distance: " .. ent:Radius(),
- "Default",
- p.x,
- p.y - 20,
- Color(255, 255, 255, 255),
- TEXT_ALIGN_CENTER,
- TEXT_ALIGN_CENTER )
- end
- end)
- end
- --Stop people noclipping near
- --We use this as well because the think hook is a bit slow
- hook.Add("PlayerNoClip", "NoclipAnchor", function(ply)
- local e = ents.GetAll()
- for _,v in ipairs(e) do
- if v.TClass and v:TClass() == "noclip_anchor" and v:Active() then
- print(v:GetNWBool("Active", false))
- if v:GetPos():Distance(ply:GetPos()) <= v:Radius() then return false end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement