diff --git a/custom_commands.lua b/custom_commands.lua index 89ae78eb..73781ca2 100644 --- a/custom_commands.lua +++ b/custom_commands.lua @@ -247,6 +247,45 @@ local function regular(cmd) end end +local function donator(cmd) + local player = game.player + if player and not player.admin then + cant_run(cmd.name) + return + end + + if cmd.parameter == nil then + player_print('Command failed. Usage: /donator ') + return + end + + local params = {} + for param in string.gmatch(cmd.parameter, '%S+') do + table.insert(params, param) + end + if params[2] == nil then + player_print('Command failed. Usage: /donator ') + return + end + + local perks = params[2] + if perks == 'nil' then + perks = nil + end + + if (tonumber(perks) == nil and perks ~= nil) then + player_print("Command failed. perks must be number or the string 'nil' to remove donator.") + return + end + + local target = params[1] + + UserGroups.set_donator(target, perks) + + local message = table.concat {'Player ', target, ' donator perks set to ', perks} + player_print(message) +end + local function afk() for _, v in pairs(game.players) do if v.afk_time > 300 then @@ -657,6 +696,8 @@ commands.add_command('tppos', 'Teleports you to a selected entity. (Admins only) commands.add_command('walkabout', ' - Send someone on a walk. (Admins only)', walkabout) commands.add_command('regulars', 'Prints a list of game regulars.', UserGroups.print_regulars) commands.add_command('regular', ', Change regular status of a player. (Admins only)', regular) +commands.add_command('donator', ' Change donator perks for a player. (Admins only)', donator) +commands.add_command('donators', 'Prints a list of game donators and thier perks.', UserGroups.print_donators) commands.add_command('afk', 'Shows how long players have been afk.', afk) commands.add_command( 'follow', diff --git a/server.lua b/server.lua index 25eedebc..de742eea 100644 --- a/server.lua +++ b/server.lua @@ -16,6 +16,7 @@ local discord_admin_embed_tag = '[DISCORD-ADMIN-EMBED]' local discord_admin_embed_raw_tag = '[DISCORD-ADMIN-EMBED-RAW]' local regular_promote_tag = '[REGULAR-PROMOTE]' local regular_deomote_tag = '[REGULAR-DEOMOTE]' +local donator_set_tag = '[DONATOR-SET]' Public.raw_print = raw_print @@ -70,4 +71,12 @@ function Public.regular_deomote(target, demotor) raw_print(discord_message) end +function Public.donator_set(target, perks) + perks = perks or 'nil' + + local message = table.concat {donator_set_tag, target, ' ', perks} + + raw_print(message) +end + return Public diff --git a/user_groups.lua b/user_groups.lua index a994d214..a3ad6b18 100644 --- a/user_groups.lua +++ b/user_groups.lua @@ -1,10 +1,10 @@ local Event = require 'utils.event' local Utils = require 'utils.utils' local Server = require 'server' ---local Donators = require 'resources.donators' +local Donators = require 'resources.donators' global.regulars = {} -global.donators = {} +global.donators = Donators.donators global.donator_welcome_messages = {} local Game = require 'utils.game' @@ -118,11 +118,34 @@ function Module.get_donator_welcome_message(player_name) return global.donator_welcome_messages[player_name] end +function Module.set_donator(player_name, perks) + global.donators[player_name] = perks + Server.donator_set(player_name, perks) +end + function Module.sync_donators(donators, messages) global.donators = donators global.donator_welcome_messages = messages end +function Module.server_set_donator(player_name, perks) + global.donators[player_name] = perks +end + +function Module.print_donators() + local result = {} + for k, v in pairs(global.donators) do + table.insert(result, k) + table.insert(result, ' : ') + table.insert(result, v) + table.insert(result, ', ') + end + table.remove(result) + + result = table.concat(result) + game.print(result) +end + Event.add( defines.events.on_player_joined_game, function(event)