Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.84 KB | None | 0 0
  1. "script"
  2. {
  3. "scriptid" "57"
  4. "name" "Noclip Anchor"
  5. "dataname" ""
  6.  
  7. }
  8.  
  9. --[[ Changelog:
  10. Revision 36:
  11. -> [Fix] Stupid wiremod error where it says it exists but doesn't define CreateInputs.
  12.  
  13. Revision 29-35:
  14. -> [Added] (Bad) Button image!!!! :D
  15. -> [Change] Indicator should now look better
  16.  
  17. Revision 26-28:
  18. -> [Added] +USE on the entity will now toggle use
  19. -> [Change] Made the indicator smaller and shadowed :)
  20.  
  21. -> [Fix] Fixed the "Active" Problem (overlooked the Tick block)
  22. -> [Change] On/Off indicator is better
  23.  
  24. Revision 25:
  25. -> [Category] Now in the "Utility" category
  26.  
  27. -> [Added] Wiremod support (Anchor Distance, Active)
  28. -> [Added] "Active" networked variable
  29. -> [Change] The indicator now won't show if you hover over it from a distance of 300 units or more
  30. -> [Change] "_Radius" moved to a networked variable, "Radius"
  31. -> The networked stuff is so that in the event that cloudscript goes multiplayer, it will work
  32.  
  33. If this breaks, please tell me, especially if it's my fault
  34. ]]--
  35.  
  36. ENT.Type = "anim"
  37. ENT.Base = "base_anim"
  38. ENT.PrintName = "Noclip Anchor"
  39. ENT.RenderGroup = RENDERGROUP_TRANSLUCENT
  40.  
  41. function ENT:Initialize()
  42. if ( SERVER ) then
  43. self.Entity:SetModel( "models/props_c17/TrapPropeller_Engine.mdl" )
  44. self.Entity:SetColor( 255, 0, 0, 255 )
  45.  
  46. self.Entity:PhysicsInit( SOLID_VPHYSICS )
  47. self.Entity:SetSolid( SOLID_VPHYSICS )
  48. self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
  49.  
  50. self:SetNWInt("Radius", 350)
  51. self:SetNWBool("Active", true)
  52. self:SetUseType( SIMPLE_USE ) --Don't keep using :/
  53.  
  54. --Wiremod support
  55. if not (WireAddon == nil) and Wire_CreateInputs then
  56. self.Inputs = Wire_CreateInputs( self, {"Active", "Anchor Distance"} )
  57. end
  58. else
  59. self.Mat = Material("sprites/sent_ball")
  60. end
  61. end
  62.  
  63. --Accessors for Active and Radius
  64. function ENT:Active()
  65. return self:GetNWBool("Active", false)
  66. end
  67.  
  68. function ENT:Radius()
  69. return self:GetNWInt("Radius", 350)
  70. end
  71.  
  72.  
  73. function ENT:SetActive( bool )
  74. self:SetNWBool( "Active", bool )
  75. end
  76.  
  77. function ENT:SetRadius( radius )
  78. self:SetNWInt( "Radius", radius )
  79. end
  80.  
  81. --Wiremod support
  82. function ENT:TriggerInput( name, value )
  83. if name == "Active" then
  84. if value >= 1 then
  85. self:SetActive( true )
  86. else
  87. self:SetActive( false )
  88. end
  89. elseif name == "Anchor Distance" then
  90. if value >= 0 then
  91. self:SetRadius( value )
  92. end
  93. end
  94. end
  95.  
  96. //
  97. // Note - the classname isn't always going to be the same
  98. // So use ClassName instead of a static string.
  99. //
  100. // This function puts the entity in the map.. and must be defined.
  101. //
  102. function ENT:SpawnFunction( ply, tr )
  103.  
  104. if ( !tr.Hit ) then return end
  105.  
  106. local SpawnPos = tr.HitPos + tr.HitNormal * 16
  107.  
  108. --Must be admin or in singleplayer
  109. if not ply:IsAdmin() and not SinglePlayer() then
  110. return
  111. end
  112.  
  113. local ent = ents.Create( ClassName )
  114. ent:SetPos( SpawnPos )
  115. ent:Spawn()
  116. ent:Activate()
  117.  
  118. self.Spawner = ply
  119.  
  120. return ent
  121. end
  122.  
  123. function ENT:TClass()
  124. return "noclip_anchor"
  125. end
  126.  
  127. --Stop people already noclipping
  128. --We don't really need to hook Tick here, this is good enough
  129. function ENT:Think()
  130. if self:Active() then
  131. local e = ents.FindInSphere(self:GetPos(), self:Radius())
  132. for _,v in ipairs(e) do
  133. if v:IsPlayer() and v:GetMoveType() == MOVETYPE_NOCLIP then
  134. v:SetMoveType(MOVETYPE_WALK)
  135. end
  136. end
  137. end
  138. end
  139.  
  140. --Use support (so simple!)
  141. function ENT:Use( activator, caller )
  142. self:SetActive( !self:Active() )
  143. end
  144.  
  145. if CLIENT then
  146. hook.Add("HUDPaint", "AnchorDist", function()
  147. local ent = LocalPlayer():GetEyeTrace().Entity
  148. if ent.TClass and ent:TClass() == "noclip_anchor" and ent:GetPos():Distance( LocalPlayer():GetPos() ) < 300 then
  149. local p = ( ent:GetPos() + ent:OBBCenter() ):ToScreen()
  150.  
  151. local Indicator = Color(0, 255, 0, 255)
  152. local Indicator_Text = "On"
  153.  
  154. if not ent:Active() then
  155. Indicator = Color(255, 0, 0, 255)
  156. Indicator_Text = "Off"
  157. end
  158.  
  159. surface.SetFont( "Default" )
  160. local Len = surface.GetTextSize( Indicator_Text )
  161.  
  162. surface.SetDrawColor( 80, 80, 80, 255 )
  163. surface.DrawRect( p.x - Len, p.y - 9 - 40, Len * 2, 18 )
  164.  
  165. surface.SetDrawColor( Indicator.r, Indicator.g, Indicator.b, 255 )
  166. surface.DrawOutlinedRect( p.x - Len, p.y - 9 - 40, Len * 2, 18 )
  167.  
  168. draw.SimpleText( Indicator_Text,
  169. "Default",
  170. p.x,
  171. p.y - 40,
  172. Indicator,
  173. TEXT_ALIGN_CENTER,
  174. TEXT_ALIGN_CENTER )
  175.  
  176. draw.SimpleText( "Distance: " .. ent:Radius(),
  177. "Default",
  178. p.x,
  179. p.y - 20,
  180. Color(255, 255, 255, 255),
  181. TEXT_ALIGN_CENTER,
  182. TEXT_ALIGN_CENTER )
  183. end
  184. end)
  185. end
  186.  
  187. --Stop people noclipping near
  188. --We use this as well because the think hook is a bit slow
  189. hook.Add("PlayerNoClip", "NoclipAnchor", function(ply)
  190. local e = ents.GetAll()
  191. for _,v in ipairs(e) do
  192. if v.TClass and v:TClass() == "noclip_anchor" and v:Active() then
  193. print(v:GetNWBool("Active", false))
  194. if v:GetPos():Distance(ply:GetPos()) <= v:Radius() then return false end
  195. end
  196. end
  197. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement