Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. if SERVER then AddCSLuaFile"shared.lua" end
  2.  
  3.  
  4. ENT.Type = "anim"
  5. ENT.Base = "base_anim"
  6. ENT.PrintName = "Noclip Anchor"
  7. ENT.RenderGroup = RENDERGROUP_TRANSLUCENT
  8.  
  9. function ENT:Initialize()
  10. if ( SERVER ) then
  11. self.Entity:SetModel( "models/props_c17/TrapPropeller_Engine.mdl" )
  12. self.Entity:SetColor( 255, 0, 0, 255 )
  13.  
  14. self.Entity:PhysicsInit( SOLID_VPHYSICS )
  15. self.Entity:SetSolid( SOLID_VPHYSICS )
  16. self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
  17.  
  18. self:SetNWInt("Radius", 350)
  19. self:SetNWBool("Active", true)
  20. self:SetUseType( SIMPLE_USE ) --Don't keep using :/
  21.  
  22. --Wiremod support
  23. if not (WireAddon == nil) and Wire_CreateInputs then
  24. self.Inputs = Wire_CreateInputs( self, {"Active", "Anchor Distance"} )
  25. end
  26. else
  27. self.Mat = Material("sprites/sent_ball")
  28. end
  29. end
  30.  
  31. --Accessors for Active and Radius
  32. function ENT:Active()
  33. return self:GetNWBool("Active", false)
  34. end
  35.  
  36. function ENT:Radius()
  37. return self:GetNWInt("Radius", 350)
  38. end
  39.  
  40.  
  41. function ENT:SetActive( bool )
  42. self:SetNWBool( "Active", bool )
  43. end
  44.  
  45. function ENT:SetRadius( radius )
  46. self:SetNWInt( "Radius", radius )
  47. end
  48.  
  49. --Wiremod support
  50. function ENT:TriggerInput( name, value )
  51. if name == "Active" then
  52. if value >= 1 then
  53. self:SetActive( true )
  54. else
  55. self:SetActive( false )
  56. end
  57. elseif name == "Anchor Distance" then
  58. if value >= 0 then
  59. self:SetRadius( value )
  60. end
  61. end
  62. end
  63.  
  64. //
  65. // Note - the classname isn't always going to be the same
  66. // So use ClassName instead of a static string.
  67. //
  68. // This function puts the entity in the map.. and must be defined.
  69. //
  70. function ENT:SpawnFunction( ply, tr )
  71.  
  72. if ( !tr.Hit ) then return end
  73.  
  74. local SpawnPos = tr.HitPos + tr.HitNormal * 16
  75.  
  76. --Must be admin or in singleplayer
  77. if not ply:IsAdmin() and not SinglePlayer() then
  78. return
  79. end
  80.  
  81. local ent = ents.Create( ClassName )
  82. ent:SetPos( SpawnPos )
  83. ent:Spawn()
  84. ent:Activate()
  85.  
  86. self.Spawner = ply
  87.  
  88. return ent
  89. end
  90.  
  91. function ENT:TClass()
  92. return "noclip_anchor"
  93. end
  94.  
  95. --Stop people already noclipping
  96. --We don't really need to hook Tick here, this is good enough
  97. function ENT:Think()
  98. if self:Active() then
  99. local e = ents.FindInSphere(self:GetPos(), self:Radius())
  100. for _,v in ipairs(e) do
  101. if v:IsPlayer() and v:GetMoveType() == MOVETYPE_NOCLIP then
  102. v:SetMoveType(MOVETYPE_WALK)
  103. end
  104. end
  105. end
  106. end
  107.  
  108. --Use support (so simple!)
  109. function ENT:Use( activator, caller )
  110. self:SetActive( !self:Active() )
  111. end
  112.  
  113. if CLIENT then
  114. hook.Add("HUDPaint", "AnchorDist", function()
  115. local ent = LocalPlayer():GetEyeTrace().Entity
  116. if ent.TClass and ent:TClass() == "noclip_anchor" and ent:GetPos():Distance( LocalPlayer():GetPos() ) < 300 then
  117. local p = ( ent:GetPos() + ent:OBBCenter() ):ToScreen()
  118.  
  119. local Indicator = Color(0, 255, 0, 255)
  120. local Indicator_Text = "On"
  121.  
  122. if not ent:Active() then
  123. Indicator = Color(255, 0, 0, 255)
  124. Indicator_Text = "Off"
  125. end
  126.  
  127. surface.SetFont( "Default" )
  128. local Len = surface.GetTextSize( Indicator_Text )
  129.  
  130. surface.SetDrawColor( 80, 80, 80, 255 )
  131. surface.DrawRect( p.x - Len, p.y - 9 - 40, Len * 2, 18 )
  132.  
  133. surface.SetDrawColor( Indicator.r, Indicator.g, Indicator.b, 255 )
  134. surface.DrawOutlinedRect( p.x - Len, p.y - 9 - 40, Len * 2, 18 )
  135.  
  136. draw.SimpleText( Indicator_Text,
  137. "Default",
  138. p.x,
  139. p.y - 40,
  140. Indicator,
  141. TEXT_ALIGN_CENTER,
  142. TEXT_ALIGN_CENTER )
  143.  
  144. draw.SimpleText( "Distance: " .. ent:Radius(),
  145. "Default",
  146. p.x,
  147. p.y - 20,
  148. Color(255, 255, 255, 255),
  149. TEXT_ALIGN_CENTER,
  150. TEXT_ALIGN_CENTER )
  151. end
  152. end)
  153. end
  154.  
  155. --Stop people noclipping near
  156. --We use this as well because the think hook is a bit slow
  157. hook.Add("PlayerNoClip", "NoclipAnchor", function(ply)
  158. local e = ents.GetAll()
  159. for _,v in ipairs(e) do
  160. if v.TClass and v:TClass() == "noclip_anchor" and v:Active() then
  161. print(v:GetNWBool("Active", false))
  162. if v:GetPos():Distance(ply:GetPos()) <= v:Radius() then return false end
  163. end
  164. end
  165. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement