Rank control clean

This commit is contained in:
Cooldude2606
2017-10-14 23:26:51 +01:00
parent ffc9f85c72
commit 6513e25c3f
13 changed files with 115 additions and 143 deletions

View File

@@ -5,25 +5,14 @@ This file can be used with permission but this and the credit below must remain
Contact a member of management on our discord to seek permission to use our code.
Any changes that you may make to the code are yours but that does not make the script yours.
Discord: https://discord.gg/XSsBV6b
The credit below may be used by another script - do not remove.
]]
local credits = {{
name='Control',
owner='Explosive Gaming',
dev='Cooldude2606',
description='Core Factorio File',
factorio_version='0.15.23',
show=false
}}
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
--Please Only Edit Below This Line-----------------------------------------------------------
--set up to run other code and events
require("mod-gui")
credit_loop(require("locale/StdLib/event"))
require("locale/StdLib/event")
--this is the main code that starts the softmod
Event.soft_init = script.generate_event_name()
local function init() if not global.soft_init then script.raise_event(Event.soft_init,{tick=game.tick}) global.soft_init = true global.credits = credits end end
local function init() if not global.soft_init then script.raise_event(Event.soft_init,{tick=game.tick}) global.soft_init = true end end
Event.register(defines.events.on_player_joined_game,init)
Event.register(defines.events.on_tick,init)
--below 'game.tick/(3600*game.speed)) % 15 == 0' raises the gui_update event every 15 minutes - feel free to change the update time
@@ -38,9 +27,9 @@ Event.register(defines.events.on_tick, function(event)
elseif ((event.tick/(3600*game.speed))+(15/2))% 15 == 0 then
-- this is the system to auto rank players
for i,player in pairs(game.connected_players) do
sudo(find_new_rank,{player,event.tick})
sudo(ranking.find_new_rank,{player,event.tick})
end
end
end)
--loads all the other scripts
credit_loop(require("locale/file-header"))
require("locale/file-header")

View File

@@ -40,19 +40,19 @@ See code for more details.
* ExpGui.add_input.draw_text(frame,name,display)
* display (opt)
## Ranks
* get_rank(player)
* ranking.get_player_rank(player)
* Get the players rank
* string_to_rank(string)
* ranking.string_to_rank(string)
* Convert a rank name to the rank object
* rank_print(msg, rank, inv)
* ranking.rank_print(msg, rank, inv)
* rank = 'rank name'
* inv = lower ranks rather than higher -> true/false/nil
* give_rank(player,rank,by_player)
* ranking.give_rank(player,rank,by_player)
* rank = 'rank name'
* by_player = player or nil
* revert_rank(player,by_player)
* ranking.revert_rank(player,by_player)
* by_player = player or nil
* find_new_rank(player)
* ranking.find_new_rank(player)
* Looks in presets if play time under 5 minutes
* Otherwise looks at play time
* Event.rank_change
@@ -74,13 +74,13 @@ See code for more details.
* returens a list if the data returend by thefunction if any
* get_sudo_info(string)
* return either a list or string based on the string boliean
* get_ranks(part)
* ranking.get_ranks(part)
* returns a list of all the ranks
* part (opt) = part of the rank you want to return ie name
* get_rank_presets(rank)
* ranking.get_player_rank_presets(rank)
* returns the current rank presets
* rank (opt) = rank name if only one rank is needed
* get_ranked_players(rank)
* ranking.get_ranked_players(rank)
* returns the ranks and online time of every player
* rank (opt) = limits it to only this rank
* get_commands(rank)

View File

@@ -69,7 +69,7 @@ function load_command(command)
debug_write({'COMMAND','RUN','PLAYER-INDEX'},event.player_index)
if event.player_index then
local player = game.players[event.player_index]
if not rank_allowed(get_rank(player),command.name) then
if not ranking.rank_allowed(ranking.get_player_rank(player),command.name) then
debug_write({'COMMAND','RUN','ALLOWED'},false)
player.print('401 - Unauthorized: Access is denied due to invalid credentials')
game.write_file('commands.log','\n'..game.tick..' Player: '..player.name..' Failed to use command (Unauthorized): '..command.name..' With args of: '..table.tostring(get_command_args(event,command,true)), true, 0)
@@ -102,12 +102,12 @@ end
function get_commands(rank)
local rank = rank or 'Owner'
local to_return = {}
for _,command in pairs(global.commands) do
if rank_allowed(string_to_rank(rank),command.name) then table.insert(to_return,command) end
for _,command in pairs(global.exp_core.commands) do
if ranking.rank_allowed(ranking.string_to_rank(rank),command.name) then table.insert(to_return,command) end
end
return to_return
end
Event.register(-1,function() global.commands = Exp_commands for _,command in pairs(Exp_commands) do load_command(command) end end)
Event.register(Event.soft_init,function() global.exp_core.commands = Exp_commands for _,command in pairs(Exp_commands) do load_command(command) end end)
Event.register(defines.events.on_player_joined_game,function() for _,command in pairs(Exp_commands) do load_command(command) end end)
--Please Only Edit Above This Line-----------------------------------------------------------
return credits

View File

@@ -74,14 +74,14 @@ function table.tostring( tbl )
end
-- 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 global.exp_core.debug.state then
if type(string) == 'table' then string = table.tostring(string)
elseif type(string) ~= 'string' then string = tostring(string) end
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
if not no_trigger or global.exp_core.debug.triggered then game.write_file('debug.log', '\n['..table.concat(idenitys, " " )..'] '..string, true, 0) end
if not no_trigger then global.exp_core.debug.triggered = true end
end
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)
Event.register(Event.soft_init,function() global.exp_core.debug={state=false,triggered=false,force=false} end)
--Please Only Edit Above This Line-----------------------------------------------------------
return credits

View File

@@ -5,34 +5,25 @@ This file can be used with permission but this and the credit below must remain
Contact a member of management on our discord to seek permission to use our code.
Any changes that you may make to the code are yours but that does not make the script yours.
Discord: https://discord.gg/XSsBV6b
The credit below may be used by another script do not remove.
]]
local credits = {{
name='Explosive Gaming Rank System',
owner='Explosive Gaming',
dev='Cooldude2606',
description='The very core upon which all of the others are based on',
factorio_version='0.15.23',
show=true
}}
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
--Please Only Edit Below This Line-----------------------------------------------------------
ranking = {}
local ranking.get_ranks, ranking.get_rank_groups = require("ExpGaming - Rank Table")
--Return the rank of a given player
function get_rank(player)
function ranking.get_player_rank(player)
if player then
debug_write({'RANK','PLAYER-GET'},player.name)
for _,rank in pairs(get_ranks()) do
for _,rank in pairs(ranking.get_ranks()) do
if player.permission_group == game.permissions.get_group(rank.name) then return rank end
end
return string_to_rank_group('User').lowest_rank
return ranking.string_to_rank_group('User').lowest_rank
end
end
--Convert the name of a rank into the rank object
function string_to_rank(string)
function ranking.string_to_rank(string)
if type(string) == 'string' then
local found_ranks={}
for _,rank in pairs(get_ranks()) do
for _,rank in pairs(ranking.get_ranks()) do
if rank.name:lower() == string:lower() then return rank end
if rank.name:lower():find(string:lower()) then table.insert(found_ranks,rank) end
end
@@ -40,10 +31,10 @@ function string_to_rank(string)
end
end
--converts the name of a group to the group object
function string_to_rank_group(string)
function ranking.string_to_rank_group(string)
if type(string) == 'string' then
local found_groups={}
for _,group in pairs(get_rank_groups()) do
for _,group in pairs(ranking.get_rank_groups()) do
if group.name:lower() == string:lower() then return group end
if group.name:lower():find(string:lower()) then table.insert(found_groups,group) end
end
@@ -51,7 +42,7 @@ function string_to_rank_group(string)
end
end
-- surches the rank for a certain allow command
function rank_allowed(rank,is_allowed)
function ranking.rank_allowed(rank,is_allowed)
for _,allow in pairs(rank.allow) do
if allow == is_allowed then return true end
end
@@ -59,59 +50,59 @@ function rank_allowed(rank,is_allowed)
end
--Send a message to all members of this rank and above, if no rank given default is mod
--inv sends message to all lower ranks rather than higher
function rank_print(msg, rank, inv)
local rank = string_to_rank(rank) or string_to_rank_group('Moderation').lowest_rank -- default mod or higher
function ranking.rank_print(msg, rank, inv)
local rank = ranking.string_to_rank(rank) or ranking.string_to_rank_group('Moderation').lowest_rank -- default mod or higher
local inv = inv or false
debug_write({'RANK','PRINT'},rank.name..': '..msg)
for _, player in pairs(game.players) do
--this part uses sudo to soread it other many ticks
player_rank_power = get_rank(player).power
player_rank_power = ranking.get_player_rank(player).power
if inv then
sudo(function(player_rank_power,rank)
if player_rank_power >= rank.power then player.print(('[Everyone]: '..msg)) end
if player_rank_power >= rank.power then player.print({'ranking.all-rank-print',msg}) end
end,{player_rank_power,rank})
else
sudo(function(player_rank_power,rank)
if player_rank_power <= rank.power then
if rank.short_hand ~= '' then player.print(('['..(rank.short_hand)..']: '..msg)) else player.print(('[Everyone]: '..msg)) end
if rank.short_hand ~= '' then player.print(('['..(rank.short_hand)..']: '..msg)) else player.print({'ranking.all-rank-print',msg}) end
end
end,{player_rank_power,rank})
end
end
end
--Give the user their new rank and raise the Event.rank_change event
function give_rank(player,rank,by_player,group_tick)
function ranking.give_rank(player,rank,by_player,group_tick)
local tick = group_tick or game.tick
local by_player = by_player or 'server'
local rank = string_to_rank(rank) or rank or string_to_rank_group('User').lowest_rank
local old_rank = get_rank(player)
local rank = ranking.string_to_rank(rank) or rank or ranking.string_to_rank_group('User').lowest_rank
local old_rank = ranking.get_player_rank(player)
-- to reducse lag if the ranks are all ready given it does not cheak
if old_rank == rank then return end
--messaging
local message = 'demoted'
if rank.power <= old_rank.power then message = 'promoted' end
local message = 'ranking.rank-down'
if rank.power <= old_rank.power then message = 'ranking.rank-down' end
if by_player.name then
debug_write({'RANK','GIVE'},'player: '..player.name..' by player: '..by_player.name..' new rank: '..rank.name..' old rank: '..old_rank.name)
rank_print(player.name..' was '..message..' to '..rank.name..' by '..by_player.name,'Guest')
ranking.rank_print({message,player.name,rank.name,by_player.name},'Guest')
else
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')
ranking.rank_print({message,player.name,rank.name,'<server>'},'Guest')
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
if rank.name ~= ranking.string_to_rank_group('User').lowest_rank.name then player.print({'ranking.rank-given',rank.name}) end
if player.tag ~= old_rank.tag and player.tag ~= '' then player.print({'ranking.tag-reset'}) end
--rank change
player.permission_group = game.permissions.get_group(rank.name)
player.tag = get_rank(player).tag
if old_rank.name ~= 'Jail' then global.old_ranks[player.index]=old_rank.name end
player.tag = ranking.get_player_rank(player).tag
if old_rank.name ~= 'Jail' then global.exp_core.old_ranks[player.index]=old_rank.name end
script.raise_event(Event.rank_change, {tick=tick, player=player, by_player=by_player, new_rank=rank, old_rank=old_rank})
end
--Revert the user's rank to what it was before the lastest change
function revert_rank(player,by_player)
local rank = string_to_rank(global.old_ranks[player.index])
give_rank(player,rank,by_player)
function ranking.revert_rank(player,by_player)
local rank = ranking.string_to_rank(global.exp_core.old_ranks[player.index])
ranking.give_rank(player,rank,by_player)
end
--Give the player a new rank based on playtime and/or preset ranks
function find_new_rank(player,group_tick)
function ranking.find_new_rank(player,group_tick)
debug_write({'RANK','NEW-RANK','START'},player.name)
local function loop_preset_rank(players,rank)
debug_write({'RANK','NEW-RANK','LOOP-PRESET'},rank)
@@ -120,25 +111,25 @@ function find_new_rank(player,group_tick)
end
end
local tick = group_tick or game.tick
local current_rank = get_rank(player)
local old_rank = get_rank(player)
local current_rank = ranking.get_player_rank(player)
local old_rank = ranking.get_player_rank(player)
local possible_ranks = {current_rank}
--Loop through preset ranks only if playtime is less than 5 minutes
debug_write({'RANK','NEW-RANK','PRESET-CHEAK'},tick_to_min(player.online_time))
if tick_to_min(player.online_time) < 5 then
debug_write({'RANK','NEW-RANK','PRESET-START'},player.name)
for rank,players in pairs(global.preset_ranks) do
for rank,players in pairs(global.exp_core.preset_ranks) do
local found_rank = loop_preset_rank(players, rank)
if found_rank then debug_write({'RANK','NEW-RANK','ADD'},found_rank) table.insert(possible_ranks,string_to_rank(found_rank)) break end
if found_rank then debug_write({'RANK','NEW-RANK','ADD'},found_rank) table.insert(possible_ranks,ranking.string_to_rank(found_rank)) break end
end
end
-- to reduce lag if the player is already higher than any time rank then it does not cheak
-- also there play time must be higher than the lowest required for a rank
debug_write({'RANK','NEW-RANK','TIME-CHEAK'},tick_to_min(player.online_time))
if current_rank.power > global.ranks.highest_timed_rank.power and tick_to_min(player.online_time) >= global.ranks.lowest_timed_rank.time then
if current_rank.power > global.exp_core.exp_core.ranks.highest_timed_rank.power and tick_to_min(player.online_time) >= global.exp_core.exp_core.ranks.lowest_timed_rank.time then
debug_write({'RANK','NEW-RANK','TIME-START'},player.name)
--Loop through rank times
for _,rank in pairs(get_ranks()) do
for _,rank in pairs(ranking.get_ranks()) do
if rank.time then debug_write({'RANK','NEW-RANK','START'},rank.name..' '..rank.time) end
if rank.time and tick_to_min(player.online_time) >= rank.time then debug_write({'RANK','NEW-RANK','ADD'},rank.name) table.insert(possible_ranks,rank) end
end
@@ -154,29 +145,29 @@ function find_new_rank(player,group_tick)
end
debug_write({'RANK','NEW-RANK','GIVE','HIGHEST'},highest_rank.name)
--Give player new rank if availble
if highest_rank.name == string_to_rank_group('User').lowest_rank.name then
if highest_rank.name == ranking.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.tag = highest_rank.tag
player.permission_group=game.permissions.get_group('Guest')
script.raise_event(Event.rank_change, {tick=tick, player=player, by_player='server', new_rank=string_to_rank_group('User').lowest_rank, old_rank=string_to_rank_group('User').lowest_rank})
script.raise_event(Event.rank_change, {tick=tick, player=player, by_player='server', new_rank=ranking.string_to_rank_group('User').lowest_rank, old_rank=ranking.string_to_rank_group('User').lowest_rank})
else
debug_write({'RANK','NEW-RANK','GIVE','VIA-GIVE-RANK'},player.name..' '..highest_rank.name)
if highest_rank ~= current_rank then give_rank(player,highest_rank,nil,tick) end
if highest_rank ~= current_rank then ranking.give_rank(player,highest_rank,nil,tick) end
end
debug_write({'RANK','NEW-RANK','GIVE','END'},player.name)
end
--Lose ends
if get_rank(player).power <= string_to_rank_group('Moderation').lowest_rank.power and not player.admin then rank_print(player.name..' needs to be promoted.') end
if old_rank.name ~= get_rank(player).name then global.old_ranks[player.index]=old_rank.name end
if ranking.get_player_rank(player).power <= ranking.string_to_rank_group('Moderation').lowest_rank.power and not player.admin then ranking.rank_print(player.name..' needs to be promoted.') end
if old_rank.name ~= ranking.get_player_rank(player).name then global.exp_core.old_ranks[player.index]=old_rank.name end
debug_write({'RANK','NEW-RANK','END'},player.name)
end
-- returns a list with every players current rank, or just the players of the rank given, includes online time
function get_ranked_players(rank)
function ranking.get_ranked_players(rank)
local to_return = {}
for _,player in pairs(game.players) do
if not rank or rank == get_rank(player).name then
table.insert(to_return,{player.name,tick_to_display_format(player.online_time),get_rank(player).name})
if not rank or rank == ranking.get_player_rank(player).name then
table.insert(to_return,{player.name,tick_to_display_format(player.online_time),ranking.get_player_rank(player).name})
end
end
return to_return
@@ -190,10 +181,10 @@ Event.register(Event.rank_change,function(event)
game.write_file('rank-change.log','\n'..game.tick..' Player: '..event.player.name..' Was given rank: '..event.new_rank.name..' By: '..event.by_player.name..' Their rank was: '..event.old_rank.name, true, 0)
end
end)
Event.register(-1,function()
Event.register(Event.soft_init,function()
debug_write({'RANK','SETUP'},'start')
global.old_ranks = {}
for _,rank in pairs(get_ranks()) do
global.exp_core.old_ranks = {}
for _,rank in pairs(ranking.get_ranks()) do
debug_write({'RANK','SETUP'},'added: '..rank.name)
game.permissions.create_group(rank.name)
for _,toRemove in pairs(rank.disallow) do
@@ -202,7 +193,7 @@ Event.register(-1,function()
end
end
end)
Event.register(defines.events.on_player_joined_game,function(event) find_new_rank(game.players[event.player_index]) end)
Event.register(-1,function() global.preset_ranks = {} end)
Event.register(defines.events.on_player_joined_game,function(event) ranking.find_new_rank(game.players[event.player_index]) end)
Event.register(Event.soft_init,function() global.exp_core.preset_ranks = {} end)
--Please Only Edit Above This Line-----------------------------------------------------------
return credits
return ranking

View File

@@ -5,20 +5,7 @@ This file can be used with permission but this and the credit below must remain
Contact a member of management on our discord to seek permission to use our code.
Any changes that you may make to the code are yours but that does not make the script yours.
Discord: https://discord.gg/XSsBV6b
The credit below may be used by another script do not remove.
]]
local credits = {{
name='ExpGaming - Ranks Table',
owner='Explosive Gaming',
dev='Cooldude2606',
description='Table holding the ranks used',
factorio_version='0.15.23',
show=false
}}
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
--Please Only Edit Below This Line-----------------------------------------------------------
--[[
How to use groups:
name the name that you can use to refence it.
colour if present then all ranks in this group will have this colour.
@@ -259,19 +246,19 @@ end
function get_ranks(part)
local to_return = {}
if part then
for _,rank in pairs(global.ranks.ranks) do table.insert(to_return,rank[part]) end
else to_return = global.ranks.ranks end
for _,rank in pairs(global.exp_core.ranks.ranks) do table.insert(to_return,rank[part]) end
else to_return = global.exp_core.ranks.ranks end
return to_return
end
-- returns a list off all the groups, return only one part if given
function get_rank_groups(part)
local to_return = {}
if part then
for _,group in pairs(global.ranks.groups) do table.insert(to_return,group[part]) end
else to_return = global.ranks.groups end
for _,group in pairs(global.exp_core.ranks.groups) do table.insert(to_return,group[part]) end
else to_return = global.exp_core.ranks.groups end
return to_return
end
-- Move the ranks to the global array
Event.register(-1,function() global.ranks = ranks end)
Event.register(Event.soft_init,function() global.exp_core.ranks = ranks end)
--Please Only Edit Above This Line-----------------------------------------------------------
return credits
return get_ranks, get_rank_groups

View File

@@ -32,11 +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.state = true
global.exp_core.debug.state = true
debug_write({'START'},game.tick..' '..event.parameter)
global.debug.triggered = false
global.exp_core.debug.triggered = false
local returned,value = pcall(loadstring(event.parameter))
if global.debug.triggered and #global.sudo.commands == 0 then debug_write({'END'},game.tick) global.debug.state = false end
if global.exp_core.debug.triggered and #global.exp_core.sudo.commands == 0 then debug_write({'END'},game.tick) global.exp_core.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
@@ -45,9 +45,9 @@ local temp_var_time = 1000/commands_per_iteration*ticks_per_iteration --temp var
function sudo(command,args,custom_return_name)
if type(command) == 'function' then
local args = args or {}
local return_name = custom_return_name or tostring(game.tick)..tostring(command)..tostring(#global.sudo.commands)
local return_name = custom_return_name or tostring(game.tick)..tostring(command)..tostring(#global.exp_core.sudo.commands)
debug_write({'SUDO','ADD'},return_name)
table.insert(global.sudo.commands,{fun=command,args=args,return_name=return_name})
table.insert(global.exp_core.sudo.commands,{fun=command,args=args,return_name=return_name})
refresh_temp_var(return_name,'temp-var-temp-value')
return {sudo='sudo-temp-var',name=return_name}
end
@@ -60,47 +60,47 @@ end
--update the time on a temp var or add it as a new one
function refresh_temp_var(name,value,offset)
local offset = offset or temp_var_time
if global.sudo.temp_varibles[name] and not value then
global.sudo.temp_varibles[name].remove_time = game.tick+offset
if global.exp_core.sudo.temp_varibles[name] and not value then
global.exp_core.sudo.temp_varibles[name].remove_time = game.tick+offset
else
global.sudo.temp_varibles[name] = {data=value,remove_time=game.tick+offset}
global.exp_core.sudo.temp_varibles[name] = {data=value,remove_time=game.tick+offset}
end
end
-- gets the data stored in a temp varible
function get_temp_var_data(var)
local to_return = nil
if global.sudo.temp_varibles[var] then to_return = global.sudo.temp_varibles[var].data debug_write({'SUDO','TEMP-VAR'},var)
elseif var.name and global.sudo.temp_varibles[var.name] then to_return = global.sudo.temp_varibles[var.name].data debug_write({'SUDO','TEMP-VAR'},var.name) end
if global.exp_core.sudo.temp_varibles[var] then to_return = global.exp_core.sudo.temp_varibles[var].data debug_write({'SUDO','TEMP-VAR'},var)
elseif var.name and global.exp_core.sudo.temp_varibles[var.name] then to_return = global.exp_core.sudo.temp_varibles[var.name].data debug_write({'SUDO','TEMP-VAR'},var.name) end
return to_return
end
-- returns the lenth of the temp varible list and command queue, is string is true then it is retured as a string
function get_sudo_info(string)
local lenth = 0
for _,v in pairs(global.sudo.temp_varibles) do lenth = lenth + 1 end
if string then return 'At game tick: '..game.tick..' Queue Lenth: '..#global.sudo.commands..' Number of temp vars: '..lenth
else return {tick=game.tick,commands=#global.sudo.commands,temp_varibles=#global.sudo.temp_varibles} end
for _,v in pairs(global.exp_core.sudo.temp_varibles) do lenth = lenth + 1 end
if string then return 'At game tick: '..game.tick..' Queue Lenth: '..#global.exp_core.sudo.commands..' Number of temp vars: '..lenth
else return {tick=game.tick,commands=#global.exp_core.sudo.commands,temp_varibles=#global.exp_core.sudo.temp_varibles} end
end
-- stops all sudo commands
function clear_sudo()
global.sudo = {commands={},temp_varibles={}}
global.exp_core.sudo = {commands={},temp_varibles={}}
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
if global.exp_core.debug.state and global.exp_core.debug.triggered and #global.exp_core.sudo.commands == 0 then debug_write({'END'},game.tick) global.exp_core.debug.state = global.exp_core.debug.focre end
-- runs the commands in sudo
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
if game.tick % ticks_per_iteration == 0 and global.exp_core.sudo.commands and #global.exp_core.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
if #global.exp_core.sudo.commands > commands_per_iteration then length = commands_per_iteration else length = #global.exp_core.sudo.commands end
-- runs the right number of commands as set
for i = 1,length do
local command=table.remove(global.sudo.commands,1)
local command=table.remove(global.exp_core.sudo.commands,1)
if command and command.fun and type(command.fun) == 'function' then
local args = {}
-- retrives and temp varibles
for n,value in pairs(command.args) do
if type(value) == 'table' and not value.__self and value.sudo and value.sudo == 'sudo-temp-var' then args[n] = {data=global.sudo.temp_varibles[value.name].data,temp_var_name=value.name}
if type(value) == 'table' and not value.__self and value.sudo and value.sudo == 'sudo-temp-var' then args[n] = {data=global.exp_core.sudo.temp_varibles[value.name].data,temp_var_name=value.name}
else args[n] = value end
end
-- makes new temp value and runs command
@@ -110,10 +110,10 @@ Event.register(defines.events.on_tick, function(event)
end
end
-- removes old temp varibles
for name,data in pairs(global.sudo.temp_varibles) do
if data.remove_time <= game.tick then global.sudo.temp_varibles[name] = nil end
for name,data in pairs(global.exp_core.sudo.temp_varibles) do
if data.remove_time <= game.tick then global.exp_core.sudo.temp_varibles[name] = nil end
end
end)
Event.register(-1,function() global.sudo = {commands={},temp_varibles={}} end)
Event.register(Event.soft_init,function() global.exp_core.sudo = {commands={},temp_varibles={}} end)
--Please Only Edit Above This Line-----------------------------------------------------------
return credits

View File

@@ -51,7 +51,7 @@ function draw_frame.center(player,element)
local tab_bar_scroll = frame.add{type = "scroll-pane", name= "tab_bar_scroll", vertical_scroll_policy="never", horizontal_scroll_policy="always"}
local tab_bar = tab_bar_scroll.add{type='flow',direction='horizontal',name='tab_bar'}
local tab = frame.add{type = "scroll-pane", name= "tab", vertical_scroll_policy="auto", horizontal_scroll_policy="never"}
for n,t in pairs(frame_data.tabs) do if rank_allowed(get_rank(player),t.name..'_tab') then debug_write({'GUI','CENTER','ADD'},t.name) ExpGui.add_input.draw_button(tab_bar,t.name) end end
for n,t in pairs(frame_data.tabs) do if ranking.rank_allowed(ranking.get_player_rank(player),t.name..'_tab') then debug_write({'GUI','CENTER','ADD'},t.name) ExpGui.add_input.draw_button(tab_bar,t.name) end end
draw_frame.tab(player,tab_bar[frame_data.tabs[1].name])
ExpGui.add_input.draw_button(tab_bar,'close_center')
tab.style.minimal_height = 300

View File

@@ -68,7 +68,7 @@ Event.register(defines.events.on_gui_click, function(event)
if event.element.type == 'button' or event.element.type == 'sprite-button' then
for _,button in pairs(inputs.buttons) do
if button.name == event.element.name then
if button.event then button.event(player,event.element) else rank_print('Button without Function '..button.name,'Mod') end break
if button.event then button.event(player,event.element) else ranking.rank_print('Button without Function '..button.name,'Mod') end break
end
end
end

View File

@@ -29,7 +29,7 @@ player_table_functions.filters = {
{name='online',is_text=false,test=function(player) return player.connected end},
{name='offline',is_text=false,test=function(player) return not player.connected end},
{name='online_time',is_text=true,test=function(player,input) if input and tonumber(input) and tonumber(input) < tick_to_min(player.online_time) then return true elseif not input or not tonumber(input) then return true end end},
{name='rank',is_text=true,test=function(player,input) if input and string_to_rank(input) and get_rank(player).power <= string_to_rank(input).power then return true elseif not input or not string_to_rank(input) then return true end end}
{name='rank',is_text=true,test=function(player,input) if input and ranking.string_to_rank(input) and ranking.get_player_rank(player).power <= ranking.string_to_rank(input).power then return true elseif not input or not ranking.string_to_rank(input) then return true end end}
}
--set up all the text inputs
for _,filter in pairs(player_table_functions.filters) do
@@ -70,15 +70,15 @@ function player_table_functions.player_match(player,filter,input)
end
--used by script on filter texts
function player_table_functions.redraw(player,element)
local frame = global.current_filters[player.index][2]
local filters = global.current_filters[player.index][1]
local frame = global.exp_core.current_filters[player.index][2]
local filters = global.exp_core.current_filters[player.index][1]
player_table_functions.draw(player,frame,filters,element.parent.parent)
end
--used to draw the player table with filter that you want
--filter = {{'is_admin',true},{'offline',true},{'player_name'}} ; if the length is 2 then it will not attempt to get a user input
function player_table_functions.draw(player,frame,filters,input_location)
debug_write({'GUI','PLAYER-TABLE','START'},player.name)
global.current_filters[player.index] = {filters,frame}
global.exp_core.current_filters[player.index] = {filters,frame}
--setup the table
if frame.player_table then frame.player_table.destroy() end
player_table = frame.add{name='player_table', type="table", colspan=5}
@@ -116,11 +116,11 @@ function player_table_functions.draw(player,frame,filters,input_location)
then player_table.add{name=p.name.."status", type="label", caption="Online"}
else player_table.add{name=p.name.."s", type="label", caption="Offline"} end
player_table.add{name=p.name.."online_time", type="label", caption=tick_to_display_format(p.online_time)}
player_table.add{name=p.name.."rank", type="label", caption=get_rank(p).short_hand}
player_table.add{name=p.name.."rank", type="label", caption=ranking.get_player_rank(p).short_hand}
end
end
end
Event.register(-1,function() global.current_filters = {} end)
Event.register(Event.soft_init,function() global.exp_core.current_filters = {} end)
--Please Only Edit Above This Line-----------------------------------------------------------
return credits

View File

@@ -32,8 +32,8 @@ function toolbar.draw(player)
local toolbar_frame = mod_gui.get_button_flow(player)
toolbar_frame.clear()
for _,button in pairs(toolbar.buttons) do
local rank = get_rank(player)
if rank_allowed(get_rank(player),button.name) then
local rank = ranking.get_player_rank(player)
if ranking.rank_allowed(ranking.get_player_rank(player),button.name) then
debug_write({'GUI','TOOLBAR','ADD'},button.name)
ExpGui.add_input.draw_button(toolbar_frame,button.name)
end

View File

@@ -20,7 +20,6 @@ local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits
--Please Only Edit Below This Line-----------------------------------------------------------
--As this is the core file, the order in which the files are loaded does matter. Do not change!
credit_loop(require("ExpGaming - Lib"))
credit_loop(require("ExpGaming - Rank Table"))
credit_loop(require("ExpGaming - Rank Control"))
credit_loop(require("GUI/file-header"))
credit_loop(require("ExpGaming - Command Maker"))

6
locale/en/exp_core.cfg Normal file
View File

@@ -0,0 +1,6 @@
[ranking]
all-rank-print=\[Everyone\]: __1__
rank-up=__1__ was promoted to __2__ by __3__
rank-down=__1__ was demoted to __2__ by __3__
rank-given=You have been given the __1__ Rank!
tag-reset=Your Tag was reset due to a Rank change