From 63bb4e6a835c821420b78a72c51b516839773659 Mon Sep 17 00:00:00 2001 From: Matthew Heguy Date: Wed, 30 Jan 2019 14:42:42 -0500 Subject: [PATCH] improve table doc add instructions for changing ranks in ranks add missing config entry refine regular and probation commands --- config.lua | 4 ++++ features/admin_commands.lua | 38 +++++++++++++++++++++++++++++++++---- resources/ranks.lua | 1 + utils/table.lua | 2 +- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/config.lua b/config.lua index b190b5aa..cf11fbeb 100644 --- a/config.lua +++ b/config.lua @@ -39,6 +39,10 @@ global.config = { map_settings = true, difficulty = true }, + -- time before a player gets the auto-trusted rank, allowing them access to the deconstructions planner, nukes, etc. + rank_system = { + time_for_trust = 3*60*60*60 -- 3 hours + }, -- saves players' lives if they have a small-plane in their inventory, also adds the small-plane to the market and must therefor be loaded first train_saviour = { enabled = true diff --git a/features/admin_commands.lua b/features/admin_commands.lua index b97d0ca2..130a89d4 100644 --- a/features/admin_commands.lua +++ b/features/admin_commands.lua @@ -7,6 +7,7 @@ local Utils = require 'utils.core' local Game = require 'utils.game' local Event = require 'utils.event' local Command = require 'utils.command' +local Color = require 'resources.color_presets' local Ranks = require 'resources.ranks' local format = string.format @@ -76,10 +77,23 @@ local function regular(args) local add_target = args['name|remove'] local remove_target = args['name'] + if not game.players[remove_target] then + Game.player_print('The player you targeted has never joined this game, please ensure no typo in name.', Color.red) + return + end + if remove_target and add_target == 'remove' then - Rank.set_rank(remove_target, Ranks.guest) + if Rank.decrease_player_rank(remove_target) then + game.print(format("%s removed %s's regular rank.", Utils.get_actor(), remove_target), Color.yellow) + else + Game.player_print(format('%s is already a regular.', remove_target), Color.red) + end else - Rank.set_rank(add_target, Ranks.regular) + if Rank.set_rank(add_target, Ranks.regular) then + game.print(format('%s promoted %s to regular.', Utils.get_actor(), remove_target), Color.yellow) + else + Game.player_print(format('%s is already a regular.', remove_target), Color.red) + end end end @@ -87,11 +101,27 @@ end local function probation(args) local add_target = args['name|remove'] local remove_target = args['name'] + local target_player = game.players[remove_target] + + if not target_player then + Game.player_print('The player you targeted has never joined this game, please ensure no typo in name.', Color.red) + return + end if remove_target and add_target == 'remove' then - Rank.set_rank(remove_target, Ranks.guest) + if Rank.reset_rank(remove_target) then + game.print(format('%s took %s off of probation.', Utils.get_actor(), remove_target), Color.yellow) + target_player.print('Your probation status has been removed. You may now perform functions as usual', Color.yellow) + else + Game.player_print(format('%s is not on probation.', remove_target), Color.red) + end else - Rank.set_rank(add_target, Ranks.probation) + if Rank.set_rank(add_target, Ranks.probation) then + game.print(format('%s put %s on probation.', Utils.get_actor(), remove_target), Color.yellow) + target_player.print('You have been placed on probation. You have limited access to normal functions.', Color.yellow) + else + Game.player_print(format('%s is already on probation.', remove_target), Color.red) + end end end diff --git a/resources/ranks.lua b/resources/ranks.lua index a6b3c05a..49df822e 100644 --- a/resources/ranks.lua +++ b/resources/ranks.lua @@ -1,3 +1,4 @@ +-- When adding/removing/changing ranks, rank_system has a migrate_data() function you can use to adjust the existing data. return { probation = -1, guest = 0, diff --git a/utils/table.lua b/utils/table.lua index ee0840fb..bc979a36 100644 --- a/utils/table.lua +++ b/utils/table.lua @@ -109,7 +109,7 @@ end --- Chooses a random entry from a table -- because this uses math.random, it cannot be used outside of events --- @param t to select an element from +-- @param t
-- @param key to indicate whether to return the key or value -- @return a random element of table t function table.get_random_dictionary_entry(t, key)