Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. ENT.Type = "point"
  2. ENT.DisableDuplicator = true
  3.  
  4. AccessorFunc( ENT, "m_bDefaultCode", "DefaultCode" )
  5.  
  6. function ENT:Initialize()
  7.  
  8. end
  9.  
  10. function ENT:KeyValue( key, value )
  11.  
  12. if ( key == "Code" ) then
  13. self:SetDefaultCode( value )
  14. end
  15.  
  16. end
  17.  
  18. function ENT:SetupGlobals( activator, caller, code )
  19.  
  20. self.compiledCode = CompileString( code, tostring(self) )
  21. if ( not self.compiledCode ) then return end
  22.  
  23. local meta = {
  24. __index = _G
  25. }
  26.  
  27. local environment = {
  28. ACTIVATOR = activator,
  29. CALLER = caller
  30. }
  31.  
  32. if ( IsValid( activator ) && activator:IsPlayer() ) then
  33. environment.TRIGGER_PLAYER = activator
  34. end
  35.  
  36. setmetatable( environment, meta )
  37. self.compiledCode = setfenv( self.compiledCode, environment )
  38.  
  39. end
  40.  
  41. function ENT:RunCode( activator, caller, code )
  42.  
  43. self:SetupGlobals( activator, caller, code )
  44.  
  45. if ( not self.compiledCode ) then return end
  46. ProtectedCall( self.compiledCode )
  47.  
  48. end
  49.  
  50. function ENT:AcceptInput( name, activator, caller, data )
  51.  
  52. if ( name == "RunCode" ) then self:RunCode( activator, caller, self:GetDefaultCode() ) return true end
  53. if ( name == "RunPassedCode" ) then self:RunCode( activator, caller, data ) return true end
  54.  
  55. return false
  56.  
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement