Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if LocalPlayer() ~= player.GetByUniqueID(--[[Morten's lagtop]] "2773847758") then return end
- do
- tasks = tasks or {}
- tasks.Registered = tasks.Registered or {}
- 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)
- local callbacks = {}
- obj.callbacks = callbacks
- return callbacks
- 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 task.callbacks.OnThink then
- task.callbacks.OnThink(task)
- 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(id)
- local obj = setmetatable({}, tasks.ChainMeta)
- obj.hook_id = "chain_think_" .. id
- 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, compare_hue, compare_sat, compare_val)
- self.CompareHue = compare_hue
- self.CompareSat = compare_sat
- self.CompareVal = compare_val
- self.Hue = compare_hue or compare_sat or compare_val
- self.Color = color
- self.Tolerance = tolerance
- self:Hook("RenderScreenspaceEffects")
- end
- function TASK:GetColor()
- return self.CurrentColor or Vector(255, 255, 255)
- 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)
- self.CurrentColor = a
- if self.Hue then
- local ah,as,av = ColorToHSV(Color(a.r, a.g, a.b))
- ah = math.floor(ah / self.Tolerance) * self.Tolerance
- as = math.floor(as / self.Tolerance) * self.Tolerance
- av = math.floor(av / self.Tolerance) * self.Tolerance
- local b = self.Color * 1
- local bh,bs,bv = ColorToHSV(Color(b.r, b.g, b.b))
- bh = math.floor(bh / self.Tolerance) * self.Tolerance
- bs = math.floor(bs / self.Tolerance) * self.Tolerance
- bv = math.floor(bv / self.Tolerance) * self.Tolerance
- if
- (self.CompareHue and ah == bh) or
- (self.CompareSat and as == bs) or
- (self.CompareVal and av == bv)
- then
- self:Done()
- end
- else
- 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
- 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 50
- end
- function TASK:GetDistance()
- return self.CurrentDistance or math.huge
- 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)
- local dist = self.pos:Distance(eye) < self.Tolerance
- self.CurrentDistance = dist
- if dist 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()
- local function start()
- local ply = table.Random(player.GetAll())
- local chain = tasks.CreateChain("UMM")
- chain:Add("say", "!goto " .. ply:Nick())
- chain:Add("goto", function() return ply:GetPos() end, 100).OnThink = function(obj) if ply:IsAFK() then self:Done() start() end end
- chain:Add("say", ply:Nick() .. "! show me something blue")
- chain:Add("color", Vector(0,0,255), 5, true)
- chain:Add("say", "good, now show me something red")
- chain:Add("color", Vector(255,0,0), 5, true)
- chain:Add("say", "chain completed")
- chain:Add("callback", start)
- chain:Start()
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement