Advertisement
Guest User

Untitled

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