Sudo Speed increase

This commit is contained in:
Cooldude2606
2017-07-23 22:14:19 +01:00
parent eff1fa5a3a
commit c1e32b3849

View File

@@ -30,15 +30,19 @@ define_command('server-interface','For use of the highest staff only',{'command'
else game.write_file('log.txt', '\n Ran by: '..player.name..'\n Code: '..event.parameter..'\n $£$ '..tostring(value), true, 0) player.print(value) end
end
end)
--this is used when changing permsion groups when the person does not have permsion to
--this is used when changing permsion groups when the person does not have permsion to, can also be used to split a large event accross mutilple ticks
function sudo(command,args) table.insert(global.sudo,{fun=command,var=args}) end
--runs one sudo command every second if one is present
--runs at most five sudo commandd every five ticks if one is present
Event.register(defines.events.on_tick, function(event)
if game.tick % 60 == 0 and global.sudo and #global.sudo > 0 then
command=table.remove(global.sudo)
if command and command.fun and type(command.fun) == 'function' then
local args = command.var or {}
command.fun(unpack(args))
if game.tick % 5 == 0 and global.sudo and #global.sudo > 0 then
local lenth = nil
if #global.sudo > 5 then lenth = 5 else lenth = #global.sudo end
for i = 1,lenth do
command=table.remove(global.sudo)
if command and command.fun and type(command.fun) == 'function' then
local args = command.var or {}
command.fun(unpack(args))
end
end
end
end)