CapsAdmin

Untitled

Jul 18th, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.57 KB | None | 0 0
  1. if LocalPlayer() ~= player.GetByUniqueID(--[[CapsAdmin (laptop)]] "267534611") then return end
  2.  
  3. do
  4.     tasks = tasks or {}
  5.  
  6.     tasks.Registered = {}
  7.     tasks.__hooks = tasks.__hooks or {}
  8.  
  9.     function tasks.Register(TASK)
  10.         tasks.Registered[TASK.Name] = TASK
  11.     end
  12.  
  13.     do
  14.         local CHAIN = {}
  15.         CHAIN.__index = CHAIN
  16.  
  17.         CHAIN.Tasks = {}
  18.         CHAIN.Index = 1
  19.  
  20.         function CHAIN:Add(name, ...)
  21.             local obj = tasks.CreateTask(name)
  22.             obj.args = {...}
  23.             obj.Chain = self
  24.             table.insert(self.Tasks, obj)
  25.         end
  26.  
  27.         function CHAIN:Think()
  28.             local task = self.Tasks[self.Index]
  29.             if task then
  30.                 local done, msg = task:Think()
  31.  
  32.                 if not task.started then
  33.                     task:OnStart(unpack(task.args))
  34.                     task.started = true
  35.                 end
  36.  
  37.                 if msg then
  38.                     self:OnMessage(task.Name, msg)
  39.                 end
  40.  
  41.                 if done or task.done then
  42.                     task:RemoveHooks()
  43.                     task:OnEnd()
  44.                     self.Index = self.Index + 1
  45.                 end
  46.             else
  47.                 self:OnEnd()
  48.                 return true
  49.             end
  50.         end
  51.  
  52.         function CHAIN:SetIndex(num)
  53.             self:Stop()
  54.             self.Index = num
  55.             self:Think()
  56.             self:Start()
  57.         end
  58.  
  59.         function CHAIN:Start()
  60.             tasks.__hooks.Think = self.hook_id
  61.  
  62.             hook.Add("Think", self.hook_id, function()
  63.                 if self:Think() then
  64.                     hook.Remove("Think", self.hook_id)
  65.                     self:OnEnd()
  66.                 end
  67.             end)
  68.         end
  69.  
  70.         function CHAIN:Stop()
  71.             local task = self.Tasks[self.Index]
  72.             if task then
  73.                 task:RemoveHooks()
  74.                 task.started = false
  75.             end
  76.  
  77.             hook.Remove("Think", self.hook_id)
  78.         end
  79.  
  80.         function CHAIN:OnEnd()
  81.  
  82.         end
  83.  
  84.         function CHAIN:OnMessage(name, msg)
  85.  
  86.         end
  87.  
  88.         tasks.ChainMeta = CHAIN
  89.     end
  90.  
  91.     do
  92.         local TASK = {}
  93.         TASK.__index = TASK
  94.  
  95.         TASK.Name = "base"
  96.         TASK.Hooks = {}
  97.  
  98.         function TASK:Hook(event)
  99.             tasks.__hooks[event] = tostring(self)
  100.             hook.Add(event, "task_" .. tostring(self), function(...) return self[event](self, ...) end)
  101.             self.Hooks[event] = true
  102.         end
  103.  
  104.         function TASK:RemoveHooks()
  105.             for event in pairs(self.Hooks) do
  106.                 hook.Remove(event, "task_" .. tostring(self))
  107.             end
  108.         end
  109.  
  110.         function TASK:OnStart(...)
  111.  
  112.         end
  113.  
  114.         function TASK:OnEnd()
  115.  
  116.             return nil
  117.         end
  118.  
  119.         function TASK:Think()
  120.  
  121.             --return true
  122.         end
  123.  
  124.         function TASK:Done()
  125.             self.done = true
  126.         end
  127.  
  128.         tasks.TaskMeta = TASK
  129.     end
  130.  
  131.     function tasks.CreateTask(name)
  132.         local meta = table.Merge(table.Copy(tasks.TaskMeta), table.Copy(tasks.Registered[name]))
  133.         local obj = setmetatable({}, meta)
  134.         return obj
  135.     end
  136.  
  137.     function tasks.CreateChain()
  138.         local obj = setmetatable({}, tasks.ChainMeta)
  139.         obj.hook_id = "chain_think_" .. tostring(obj)
  140.         return obj
  141.     end
  142.  
  143.     function tasks.Panic()
  144.         for key, val in pairs(tasks.__hooks) do
  145.             hook.Remove(key, val)
  146.             tasks.__hooks[key] = nil
  147.         end
  148.     end
  149. end
  150.  
  151. do
  152.     local TASK = {}
  153.     TASK.Name = "color"
  154.    
  155.     function TASK:OnStart(color, tolerance)
  156.         self.Color = color
  157.         self.Tolerance = tolerance
  158.         self:Hook("RenderScreenspaceEffects")
  159.     end
  160.    
  161.     function TASK:RenderScreenspaceEffects()
  162.         local samples = 64
  163.         local size = 256
  164.                    
  165.         local w = ScrW() / 2
  166.         local h = ScrH() / 2
  167.            
  168.         local a = Vector(0)
  169.        
  170.         render.CapturePixels()
  171.            
  172.         for i=1, samples do
  173.             a = a + Vector(render.ReadPixel(w + math.random(-size, size), h + math.random(-size, size)))
  174.         end
  175.        
  176.         a = (a / 32)
  177.        
  178.         a.r = math.floor(a.r / self.Tolerance) * self.Tolerance
  179.         a.g = math.floor(a.g / self.Tolerance) * self.Tolerance
  180.         a.b = math.floor(a.b / self.Tolerance) * self.Tolerance
  181.        
  182.        
  183.         local b = self.Color * 1
  184.        
  185.         b.r = math.floor(b.r / self.Tolerance) * self.Tolerance
  186.         b.g = math.floor(b.g / self.Tolerance) * self.Tolerance
  187.         b.b = math.floor(b.b / self.Tolerance) * self.Tolerance
  188.        
  189.         if a == b then
  190.             self:Done()
  191.         end
  192.     end
  193.    
  194.     tasks.Register(TASK)
  195. end
  196.  
  197. do
  198.     local TASK = {}
  199.     TASK.Name = "goto"
  200.  
  201.     function TASK:OnStart(pos, tolerance)
  202.         self:Hook("CreateMove")
  203.  
  204.         if type(pos) == "function" then
  205.             self.pos_func = pos
  206.         elseif type(pos) == "Vector" then
  207.             self.pos = pos
  208.         end
  209.  
  210.         self.tolerance = tolerance or 10
  211.     end
  212.  
  213.     function TASK:CreateMove(cmd)
  214.         if self.pos_func then
  215.             self.pos = self.pos_func()
  216.         end
  217.  
  218.         local eye = LocalPlayer():EyePos()
  219.  
  220.         cmd:SetViewAngles((self.pos - eye):Angle())
  221.         cmd:SetForwardMove(1000)
  222.  
  223.         if self.pos:Distance(eye) < self.tolerance then
  224.             self:Done()
  225.         end
  226.     end
  227.  
  228.     tasks.Register(TASK)
  229. end
  230.  
  231. do
  232.     local TASK = {}
  233.     TASK.Name = "say"
  234.  
  235.     function TASK:OnStart(str)
  236.         Say(str)
  237.         self:Done()
  238.     end
  239.  
  240.     tasks.Register(TASK)
  241. end
  242.  
  243. do
  244.     local TASK = {}
  245.     TASK.Name = "wait"
  246.  
  247.     function TASK:OnStart(sec)
  248.         timer.Simple(sec, function() self:Done() end)
  249.     end
  250.  
  251.     tasks.Register(TASK)
  252. end
  253.  
  254. do
  255.     local TASK = {}
  256.     TASK.Name = "cmd"
  257.  
  258.     function TASK:OnStart(cmd, ...)
  259.         RunConsoleCommand(cmd, ...)
  260.         self:Done()
  261.     end
  262.  
  263.     tasks.Register(TASK)
  264. end
  265.  
  266. do
  267.     local TASK = {}
  268.     TASK.Name = "aim"
  269.  
  270.     function TASK:OnStart(ang)
  271.         LocalPlayer():SetEyeAngles(ang())
  272.         self:Done()
  273.     end
  274.  
  275.     tasks.Register(TASK)
  276. end
  277.  
  278. do
  279.     local TASK = {}
  280.     TASK.Name = "callback"
  281.  
  282.     function TASK:OnStart(callback)
  283.         callback()
  284.         self:Done()
  285.     end
  286.  
  287.     tasks.Register(TASK)
  288. end
  289.  
  290. do
  291.     local TASK = {}
  292.     TASK.Name = "waituntil"
  293.  
  294.     function TASK:OnStart(callback)
  295.         self.callback = callback
  296.     end
  297.  
  298.     function TASK:Think()
  299.         return self.callback()
  300.     end
  301.  
  302.     tasks.Register(TASK)
  303. end
  304.  
  305. tasks.Panic()
  306.  
  307. test_chain = tasks.CreateChain()
  308. test_chain:Add("say", "show me something blue")
  309. test_chain:Add("color", Vector(0,0,255), 50)
  310. test_chain:Add("say", "thanks")
  311. test_chain:Start()
Advertisement
Add Comment
Please, Sign In to add comment