Many Small changes: rank preset, debug and others

This commit is contained in:
Cooldude2606
2017-09-23 10:52:28 +01:00
parent 1e58b72f4e
commit c125f19f39
6 changed files with 22 additions and 55 deletions

View File

@@ -95,7 +95,7 @@ function load_command(command)
print('Command Complete')
game.write_file('commands.log','\n'..game.tick..' Player: <server> Used command: '..command.name..' With args of: '..table.tostring(args), true, 0)
end
debug_write({'COMMAND','RUN','END'},command.name)
debug_write({'COMMAND','RUN','END'},command.name,true)
end)
end
-- returns all the commands in a certain rank restriction

View File

@@ -72,15 +72,16 @@ function table.tostring( tbl )
end
return "{" .. table.concat( result, "," ) .. "}"
end
-- allows a simple way to debug code
function debug_write(idenitys,string)
if global.debug then
-- allows a simple way to debug code; idenitys = {'string1','string2'}; string will be writen to file; no_trigger dissables the trigger useful for on_tick events
function debug_write(idenitys,string,no_trigger)
if global.debug.state then
if type(string) == 'table' then string = table.tostring(string)
elseif type(string) ~= 'string' then string = tostring(string) end
game.write_file('debug.log', '\n['..table.concat(idenitys, " " )..'] '..string, true, 0)
if not no_trigger or global.debug.triggered then game.write_file('debug.log', '\n['..table.concat(idenitys, " " )..'] '..string, true, 0) end
if not no_trigger then global.debug.triggered = true end
end
end
Event.register(defines.events.on_tick,function() debug_write({'NEW TICK'},game.tick) end)
Event.register(-1,function() global.debug = false end)
Event.register(defines.events.on_tick,function() debug_write({'NEW TICK'},game.tick,true) end)
Event.register(-1,function() global.debug={state=false,triggered=false,force=false} end)
--Please Only Edit Above This Line-----------------------------------------------------------
return credits

View File

@@ -96,7 +96,7 @@ function give_rank(player,rank,by_player)
debug_write({'RANK','GIVE'},'player: '..player.name..' by player: <server> new rank: '..rank.name..' old rank: '..old_rank.name)
rank_print(player.name..' was '..message..' to '..rank.name..' by <server>','Guest')
end
if rank.name ~= 'Guest' then player.print('You have been given the '..rank.name..' Rank!') end
if rank.name ~= string_to_rank_group('User').lowest_rank.name then player.print('You have been given the '..rank.name..' Rank!') end
if player.tag ~= old_rank.tag and player.tag ~= '' then player.print('Your Tag was reset due to a Rank change') end
--rank change
player.permission_group = game.permissions.get_group(rank.name)
@@ -152,7 +152,7 @@ function find_new_rank(player)
end
debug_write({'RANK','NEW-RANK','GIVE','HIGHEST'},highest_rank.name)
--Give player new rank if availble
if highest_rank.name == 'Guest' then
if highest_rank.name == string_to_rank_group('User').lowest_rank.name then
-- to avoid spam in chat
debug_write({'RANK','NEW-RANK','GIVE','VIA-SERVER'},player.name..' '..highest_rank.name)
player.permission_group=game.permissions.get_group('Guest')

View File

@@ -18,6 +18,7 @@ local credits = {{
}}
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
--Please Only Edit Below This Line-----------------------------------------------------------
-- we run an exturnle script which syncs this table with discord, only top ranks are filled in case of error
local preset_ranks = {
Owner={'badgamernl'},
@@ -31,48 +32,9 @@ local preset_ranks = {
'mark9064',
'Smou'},
Mod={
'AcThPaU',
'Alanore',
'Aquaday',
'ayahuasca23',
'cafeslacker',
'CrashKonijn',
'Drahc_pro',
'everLord',
'FlipHalfling90',
'facere',
'freek18',
'Hobbitkicker',
'hud',
'Koroto',
'matthias60',
'MeDDish',
'Mindxt20',
'MottledPetrel',
'Mr_Happy_212',
'NextIdea',
'Phoenix27833',
'rezz',
'samy115',
'Sand3r205',
'scarbvis',
'steentje77',
'SuperWinner50',
'tophatgaming123',
'VR29',
'xenocyber',
'Ruuyji',
'mightycax',
'Gizan',
'mafisch3',
'cydes',
'Windbomb'},
Mod={},
Donator={
'M74132',
'Splicer',
'Nucklesamich'},
Donator={},
Veteran={},

View File

@@ -46,6 +46,8 @@ local ranks = {
lowest_timed_rank=nil,
number_of_ranks=0,
groups={
--note dont remove these groups but you may add more
--all but the management group is used to indentiy ranks by the script
{name='Management',
allow={'cheat-mode','debug'}
},

View File

@@ -32,10 +32,11 @@ define_command('server-interface','For use of the highest staff only',{'command'
end)
--runs a server interface command with debug on and does not return any values to the user
define_command('debug','For use of the highest staff only, this will lag A LOT',{'command',true},function(player,event,args)
global.debug = true
global.debug.state = true
debug_write({'START'},game.tick..' '..event.parameter)
global.debug.triggered = false
local returned,value = pcall(loadstring(event.parameter))
if #global.sudo.commands == 0 then debug_write({'END'},game.tick) global.debug = false end
if global.debug.triggered and #global.sudo.commands == 0 then debug_write({'END'},game.tick) global.debug.state = false end
end)
--this is used when changing permission groups when the person does not have permsion to, can also be used to split a large event accross multiple ticks
local commands_per_iteration = 50 --number of sudo commands ran every sudo iteration
@@ -85,9 +86,10 @@ function clear_sudo()
end
--sudo main loop
Event.register(defines.events.on_tick, function(event)
--used with debug command will stop debuging once atleast one message is send to file and there are no commands in sudo
if global.debug.state and global.debug.triggered and #global.sudo.commands == 0 then debug_write({'END'},game.tick) global.debug.state = global.debug.focre end
-- runs the commands in sudo
if global.debug and #global.sudo.commands == 0 then debug_write({'END'},game.tick) global.debug = global.force_debug end
debug_write({'SUDO'},get_sudo_info(true))
debug_write({'SUDO'},get_sudo_info(true),true)
if game.tick % ticks_per_iteration == 0 and global.sudo.commands and #global.sudo.commands > 0 then
local length = nil
if #global.sudo.commands > commands_per_iteration then length = commands_per_iteration else length = #global.sudo.commands end
@@ -112,6 +114,6 @@ Event.register(defines.events.on_tick, function(event)
if data.remove_time <= game.tick then global.sudo.temp_varibles[name] = nil end
end
end)
Event.register(-1,function() global.sudo = {commands={},temp_varibles={}} global.force_debug = false end)
Event.register(-1,function() global.sudo = {commands={},temp_varibles={}} end)
--Please Only Edit Above This Line-----------------------------------------------------------
return credits