Advertisement
CapsAdmin

Untitled

Apr 12th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.31 KB | None | 0 0
  1. if LocalPlayer() ~= player.GetByUniqueID(--[[Morten's lagtop]] "2773847758") then return end
  2.  
  3. do
  4.     tasks = tasks or {}
  5.  
  6.     tasks.Registered = tasks.Registered or {}
  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.            
  26.             local callbacks = {}
  27.            
  28.             obj.callbacks = callbacks
  29.            
  30.             return callbacks
  31.         end
  32.  
  33.         function CHAIN:Think()
  34.             local task = self.Tasks[self.Index]
  35.             if task then
  36.                 local done, msg = task:Think()
  37.  
  38.                 if not task.started then
  39.                     task:OnStart(unpack(task.args))
  40.                     task.started = true
  41.                 end
  42.            
  43.                 if task.callbacks.OnThink then
  44.                     task.callbacks.OnThink(task)
  45.                 end
  46.            
  47.                 if msg then
  48.                     self:OnMessage(task.Name, msg)
  49.                 end
  50.  
  51.                 if done or task.done then
  52.                     task:RemoveHooks()
  53.                     task:OnEnd()
  54.                     self.Index = self.Index + 1
  55.                 end
  56.             else
  57.                 self:OnEnd()
  58.                 return true
  59.             end
  60.         end
  61.  
  62.         function CHAIN:SetIndex(num)
  63.             self:Stop()
  64.             self.Index = num
  65.             self:Think()
  66.             self:Start()
  67.         end
  68.  
  69.         function CHAIN:Start()
  70.             tasks.__hooks.Think = self.hook_id
  71.  
  72.             hook.Add("Think", self.hook_id, function()
  73.                 if self:Think() then
  74.                     hook.Remove("Think", self.hook_id)
  75.                     self:OnEnd()
  76.                 end
  77.             end)
  78.         end
  79.  
  80.         function CHAIN:Stop()
  81.             local task = self.Tasks[self.Index]
  82.             if task then
  83.                 task:RemoveHooks()
  84.                 task.started = false
  85.             end
  86.  
  87.             hook.Remove("Think", self.hook_id)
  88.         end
  89.  
  90.         function CHAIN:OnEnd()
  91.  
  92.         end
  93.  
  94.         function CHAIN:OnMessage(name, msg)
  95.  
  96.         end
  97.  
  98.         tasks.ChainMeta = CHAIN
  99.     end
  100.  
  101.     do
  102.         local TASK = {}
  103.         TASK.__index = TASK
  104.  
  105.         TASK.Name = "base"
  106.         TASK.Hooks = {}
  107.  
  108.         function TASK:Hook(event)
  109.             tasks.__hooks[event] = tostring(self)
  110.             hook.Add(event, "task_" .. tostring(self), function(...) return self[event](self, ...) end)
  111.             self.Hooks[event] = true
  112.         end
  113.  
  114.         function TASK:RemoveHooks()
  115.             for event in pairs(self.Hooks) do
  116.                 hook.Remove(event, "task_" .. tostring(self))
  117.             end
  118.         end
  119.  
  120.         function TASK:OnStart(...)
  121.  
  122.         end
  123.  
  124.         function TASK:OnEnd()
  125.  
  126.             return nil
  127.         end
  128.  
  129.         function TASK:Think()
  130.  
  131.             --return true
  132.         end
  133.  
  134.         function TASK:Done()
  135.             self.done = true
  136.         end
  137.  
  138.         tasks.TaskMeta = TASK
  139.     end
  140.  
  141.     function tasks.CreateTask(name)
  142.         local meta = table.Merge(table.Copy(tasks.TaskMeta), table.Copy(tasks.Registered[name]))
  143.         local obj = setmetatable({}, meta)
  144.         return obj
  145.     end
  146.  
  147.     function tasks.CreateChain(id)
  148.         local obj = setmetatable({}, tasks.ChainMeta)
  149.         obj.hook_id = "chain_think_" .. id
  150.         return obj
  151.     end
  152.  
  153.     function tasks.Panic()
  154.         for key, val in pairs(tasks.__hooks) do
  155.             hook.Remove(key, val)
  156.             tasks.__hooks[key] = nil
  157.         end
  158.     end
  159. end
  160.  
  161. do
  162.     local TASK = {}
  163.     TASK.Name = "color"
  164.    
  165.     function TASK:OnStart(color, tolerance, compare_hue, compare_sat, compare_val)
  166.         self.CompareHue = compare_hue
  167.         self.CompareSat = compare_sat
  168.         self.CompareVal = compare_val
  169.        
  170.         self.Hue = compare_hue or compare_sat or compare_val
  171.        
  172.         self.Color = color
  173.         self.Tolerance = tolerance
  174.        
  175.         self:Hook("RenderScreenspaceEffects")
  176.     end
  177.    
  178.     function TASK:GetColor()
  179.         return self.CurrentColor or Vector(255, 255, 255)
  180.     end
  181.    
  182.     function TASK:RenderScreenspaceEffects()
  183.         local samples = 64
  184.         local size = 256
  185.                    
  186.         local w = ScrW() / 2
  187.         local h = ScrH() / 2
  188.            
  189.         local a = Vector(0)
  190.        
  191.         render.CapturePixels()
  192.            
  193.         for i=1, samples do
  194.             a = a + Vector(render.ReadPixel(w + math.random(-size, size), h + math.random(-size, size)))
  195.         end
  196.        
  197.         a = (a / 32)
  198.        
  199.         self.CurrentColor = a
  200.        
  201.         if self.Hue then   
  202.             local ah,as,av = ColorToHSV(Color(a.r, a.g, a.b))
  203.            
  204.             ah = math.floor(ah / self.Tolerance) * self.Tolerance
  205.             as = math.floor(as / self.Tolerance) * self.Tolerance
  206.             av = math.floor(av / self.Tolerance) * self.Tolerance
  207.            
  208.            
  209.             local b = self.Color * 1
  210.             local bh,bs,bv = ColorToHSV(Color(b.r, b.g, b.b))
  211.            
  212.             bh = math.floor(bh / self.Tolerance) * self.Tolerance
  213.             bs = math.floor(bs / self.Tolerance) * self.Tolerance
  214.             bv = math.floor(bv / self.Tolerance) * self.Tolerance
  215.            
  216.             if
  217.                 (self.CompareHue and ah == bh) or
  218.                 (self.CompareSat and as == bs) or
  219.                 (self.CompareVal and av == bv)
  220.             then
  221.                 self:Done()
  222.             end
  223.         else
  224.             a.r = math.floor(a.r / self.Tolerance) * self.Tolerance
  225.             a.g = math.floor(a.g / self.Tolerance) * self.Tolerance
  226.             a.b = math.floor(a.b / self.Tolerance) * self.Tolerance
  227.            
  228.            
  229.             local b = self.Color * 1
  230.            
  231.             b.r = math.floor(b.r / self.Tolerance) * self.Tolerance
  232.             b.g = math.floor(b.g / self.Tolerance) * self.Tolerance
  233.             b.b = math.floor(b.b / self.Tolerance) * self.Tolerance
  234.            
  235.             if a == b then
  236.                 self:Done()
  237.             end
  238.         end
  239.     end
  240.    
  241.     tasks.Register(TASK)
  242. end
  243.  
  244. do
  245.     local TASK = {}
  246.     TASK.Name = "goto"
  247.  
  248.     function TASK:OnStart(pos, tolerance)
  249.         self:Hook("CreateMove")
  250.  
  251.         if type(pos) == "function" then
  252.             self.pos_func = pos
  253.         elseif type(pos) == "Vector" then
  254.             self.pos = pos
  255.         end
  256.  
  257.         self.Tolerance = tolerance or 50
  258.     end
  259.    
  260.     function TASK:GetDistance()
  261.         return self.CurrentDistance or math.huge
  262.     end
  263.  
  264.     function TASK:CreateMove(cmd)
  265.         if self.pos_func then
  266.             self.pos = self.pos_func()
  267.         end
  268.  
  269.         local eye = LocalPlayer():EyePos()
  270.  
  271.         cmd:SetViewAngles((self.pos - eye):Angle())
  272.         cmd:SetForwardMove(1000)
  273.  
  274.         local dist = self.pos:Distance(eye) < self.Tolerance
  275.        
  276.         self.CurrentDistance = dist
  277.        
  278.         if dist then
  279.             self:Done()
  280.         end
  281.     end
  282.  
  283.     tasks.Register(TASK)
  284. end
  285.  
  286. do
  287.     local TASK = {}
  288.     TASK.Name = "say"
  289.  
  290.     function TASK:OnStart(str)
  291.         Say(str)
  292.         self:Done()
  293.     end
  294.  
  295.     tasks.Register(TASK)
  296. end
  297.  
  298. do
  299.     local TASK = {}
  300.     TASK.Name = "wait"
  301.  
  302.     function TASK:OnStart(sec)
  303.         timer.Simple(sec, function() self:Done() end)
  304.     end
  305.  
  306.     tasks.Register(TASK)
  307. end
  308.  
  309. do
  310.     local TASK = {}
  311.     TASK.Name = "cmd"
  312.  
  313.     function TASK:OnStart(cmd, ...)
  314.         RunConsoleCommand(cmd, ...)
  315.         self:Done()
  316.     end
  317.  
  318.     tasks.Register(TASK)
  319. end
  320.  
  321. do
  322.     local TASK = {}
  323.     TASK.Name = "aim"
  324.  
  325.     function TASK:OnStart(ang)
  326.         LocalPlayer():SetEyeAngles(ang())
  327.         self:Done()
  328.     end
  329.  
  330.     tasks.Register(TASK)
  331. end
  332.  
  333. do
  334.     local TASK = {}
  335.     TASK.Name = "callback"
  336.  
  337.     function TASK:OnStart(callback)
  338.         callback()
  339.         self:Done()
  340.     end
  341.  
  342.     tasks.Register(TASK)
  343. end
  344.  
  345. do
  346.     local TASK = {}
  347.     TASK.Name = "waituntil"
  348.  
  349.     function TASK:OnStart(callback)
  350.         self.callback = callback
  351.     end
  352.  
  353.     function TASK:Think()
  354.         return self.callback()
  355.     end
  356.  
  357.     tasks.Register(TASK)
  358. end
  359.  
  360. tasks.Panic()
  361.  
  362. local function start()
  363.     local ply = table.Random(player.GetAll())
  364.     local chain = tasks.CreateChain("UMM")
  365.     chain:Add("say", "!goto " .. ply:Nick())
  366.     chain:Add("goto", function() return ply:GetPos() end, 100).OnThink = function(obj) if ply:IsAFK() then self:Done() start() end end
  367.     chain:Add("say", ply:Nick() .. "! show me something blue")
  368.     chain:Add("color", Vector(0,0,255), 5, true)
  369.     chain:Add("say", "good, now show me something red")
  370.     chain:Add("color", Vector(255,0,0), 5, true)
  371.     chain:Add("say", "chain completed")
  372.     chain:Add("callback", start)
  373.     chain:Start()
  374. end
  375.  
  376. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement