Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local functions = { }
- local added = false
- local function Stop()
- hook.Remove("Think", "NextThinkHelper")
- end
- local function error_func(line)
- ErrorNoHalt("NextThink Error: "..debug.traceback(line,2))
- end
- local function Think()
- local n = #functions
- if n == 0 then
- Stop()
- return
- end
- for i = 1, n do
- local func = table.remove(functions, 1)
- xpcall(func,error_func)
- end
- end
- local function Start()
- if added then
- return
- end
- hook.Add("Think", "NextThinkHelper", Think)
- end
- function RunNextThink(func)
- if not isfunction(func) then
- error("Expected function", 2)
- end
- functions[#functions + 1] = func
- Start()
- end
- local functions = { }
- local initialized = false
- local function error_func(line)
- ErrorNoHalt("OnInitialize: " .. debug.traceback(line, 2))
- end
- local function Initialize()
- initialized = true
- for i = 1, #functions do
- local func = functions[i]
- xpcall(func, error_func)
- end
- functions = nil
- RunOnInitialize = function()
- error("RunOnInitialize called too late",2)
- end
- hook.Remove("Initialize", "RunOnInitializeHelper")
- end
- function Init(func)
- if not isfunction(func) then
- error("Expected function", 2)
- end
- if initialized then
- error("RunOnInitialize called too late",2)
- end
- functions[#functions + 1] = func
- end
- hook.Add("Initialize", "RunOnInitializeHelper", Initialize)
Advertisement
Add Comment
Please, Sign In to add comment