Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if LocalPlayer() ~= player.GetByUniqueID(--[[CapsAdmin (laptop)]] "267534611") then return end
- do
- tasks = tasks or {}
- tasks.Registered = {}
- tasks.__hooks = tasks.__hooks or {}
- function tasks.Register(TASK)
- tasks.Registered[TASK.Name] = TASK
- end
- do
- local CHAIN = {}
- CHAIN.__index = CHAIN
- CHAIN.Tasks = {}
- CHAIN.Index = 1
- function CHAIN:Add(name, ...)
- local obj = tasks.CreateTask(name)
- obj.args = {...}
- obj.Chain = self
- table.insert(self.Tasks, obj)
- end
- function CHAIN:Think()
- local task = self.Tasks[self.Index]
- if task then
- local done, msg = task:Think()
- if not task.started then
- task:OnStart(unpack(task.args))
- task.started = true
- end
- if msg then
- self:OnMessage(task.Name, msg)
- end
- if done or task.done then
- task:RemoveHooks()
- task:OnEnd()
- self.Index = self.Index + 1
- end
- else
- self:OnEnd()
- return true
- end
- end
- function CHAIN:SetIndex(num)
- self:Stop()
- self.Index = num
- self:Think()
- self:Start()
- end
- function CHAIN:Start()
- tasks.__hooks.Think = self.hook_id
- hook.Add("Think", self.hook_id, function()
- if self:Think() then
- hook.Remove("Think", self.hook_id)
- self:OnEnd()
- end
- end)
- end
- function CHAIN:Stop()
- local task = self.Tasks[self.Index]
- if task then
- task:RemoveHooks()
- task.started = false
- end
- hook.Remove("Think", self.hook_id)
- end
- function CHAIN:OnEnd()
- end
- function CHAIN:OnMessage(name, msg)
- end
- tasks.ChainMeta = CHAIN
- end
- do
- local TASK = {}
- TASK.__index = TASK
- TASK.Name = "base"
- TASK.Hooks = {}
- function TASK:Hook(event)
- tasks.__hooks[event] = tostring(self)
- hook.Add(event, "task_" .. tostring(self), function(...) return self[event](self, ...) end)
- self.Hooks[event] = true
- end
- function TASK:RemoveHooks()
- for event in pairs(self.Hooks) do
- hook.Remove(event, "task_" .. tostring(self))
- end
- end
- function TASK:OnStart(...)
- end
- function TASK:OnEnd()
- return nil
- end
- function TASK:Think()
- --return true
- end
- function TASK:Done()
- self.done = true
- end
- tasks.TaskMeta = TASK
- end
- function tasks.CreateTask(name)
- local meta = table.Merge(table.Copy(tasks.TaskMeta), table.Copy(tasks.Registered[name]))
- local obj = setmetatable({}, meta)
- return obj
- end
- function tasks.CreateChain()
- local obj = setmetatable({}, tasks.ChainMeta)
- obj.hook_id = "chain_think_" .. tostring(obj)
- return obj
- end
- function tasks.Panic()
- for key, val in pairs(tasks.__hooks) do
- hook.Remove(key, val)
- tasks.__hooks[key] = nil
- end
- end
- end
- do
- local TASK = {}
- TASK.Name = "color"
- function TASK:OnStart(color, tolerance)
- self.Color = color
- self.Tolerance = tolerance
- self:Hook("RenderScreenspaceEffects")
- end
- function TASK:RenderScreenspaceEffects()
- local samples = 64
- local size = 256
- local w = ScrW() / 2
- local h = ScrH() / 2
- local a = Vector(0)
- render.CapturePixels()
- for i=1, samples do
- a = a + Vector(render.ReadPixel(w + math.random(-size, size), h + math.random(-size, size)))
- end
- a = (a / 32)
- a.r = math.floor(a.r / self.Tolerance) * self.Tolerance
- a.g = math.floor(a.g / self.Tolerance) * self.Tolerance
- a.b = math.floor(a.b / self.Tolerance) * self.Tolerance
- local b = self.Color * 1
- b.r = math.floor(b.r / self.Tolerance) * self.Tolerance
- b.g = math.floor(b.g / self.Tolerance) * self.Tolerance
- b.b = math.floor(b.b / self.Tolerance) * self.Tolerance
- if a == b then
- self:Done()
- end
- end
- tasks.Register(TASK)
- end
- do
- local TASK = {}
- TASK.Name = "goto"
- function TASK:OnStart(pos, tolerance)
- self:Hook("CreateMove")
- if type(pos) == "function" then
- self.pos_func = pos
- elseif type(pos) == "Vector" then
- self.pos = pos
- end
- self.tolerance = tolerance or 10
- end
- function TASK:CreateMove(cmd)
- if self.pos_func then
- self.pos = self.pos_func()
- end
- local eye = LocalPlayer():EyePos()
- cmd:SetViewAngles((self.pos - eye):Angle())
- cmd:SetForwardMove(1000)
- if self.pos:Distance(eye) < self.tolerance then
- self:Done()
- end
- end
- tasks.Register(TASK)
- end
- do
- local TASK = {}
- TASK.Name = "say"
- function TASK:OnStart(str)
- Say(str)
- self:Done()
- end
- tasks.Register(TASK)
- end
- do
- local TASK = {}
- TASK.Name = "wait"
- function TASK:OnStart(sec)
- timer.Simple(sec, function() self:Done() end)
- end
- tasks.Register(TASK)
- end
- do
- local TASK = {}
- TASK.Name = "cmd"
- function TASK:OnStart(cmd, ...)
- RunConsoleCommand(cmd, ...)
- self:Done()
- end
- tasks.Register(TASK)
- end
- do
- local TASK = {}
- TASK.Name = "aim"
- function TASK:OnStart(ang)
- LocalPlayer():SetEyeAngles(ang())
- self:Done()
- end
- tasks.Register(TASK)
- end
- do
- local TASK = {}
- TASK.Name = "callback"
- function TASK:OnStart(callback)
- callback()
- self:Done()
- end
- tasks.Register(TASK)
- end
- do
- local TASK = {}
- TASK.Name = "waituntil"
- function TASK:OnStart(callback)
- self.callback = callback
- end
- function TASK:Think()
- return self.callback()
- end
- tasks.Register(TASK)
- end
- tasks.Panic()
- test_chain = tasks.CreateChain()
- test_chain:Add("say", "show me something blue")
- test_chain:Add("color", Vector(0,0,255), 50)
- test_chain:Add("say", "thanks")
- test_chain:Start()
Advertisement
Add Comment
Please, Sign In to add comment