mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-11-06 09:09:26 +02:00
Add player renaming (#428)
* Add player renaming from auto-generated names * Give admins IDs on name changes
This commit is contained in:
@@ -18,6 +18,8 @@ global.scenario.config.nuke_control.enable_autokick = true
|
||||
global.scenario.config.nuke_control.enable_autoban = true
|
||||
global.scenario.custom_functions = {}
|
||||
global.scenario.config.nuke_control.nuke_min_time_hours = 3 --how long a player must be on the server to be allowed to use the nuke
|
||||
global.scenario.config.players_assigned_names = false -- assigns players random names when they first join
|
||||
global.scenario.config.players_roll_names = false -- allows players to roll random names
|
||||
global.newline = '\n'
|
||||
newline = '\n'
|
||||
|
||||
|
||||
159
features/silly_player_names.lua
Normal file
159
features/silly_player_names.lua
Normal file
@@ -0,0 +1,159 @@
|
||||
require 'utils.list_utils'
|
||||
local Game = require 'utils.game'
|
||||
local Event = require 'utils.event'
|
||||
local naming_words = require 'resources.naming_words'
|
||||
local Utils = require('utils.utils')
|
||||
global.actual_name = {}
|
||||
global.silly_names = {}
|
||||
global.silly_names.count = 0
|
||||
|
||||
local name_combinations = #naming_words.adverbs * #naming_words.adjectives * #naming_words.nouns
|
||||
|
||||
--- Creates name by combining elements from the passed table
|
||||
-- @param1 table including adverbs, adjectives, and nouns
|
||||
-- @returns name as a string
|
||||
local function create_name(words_table)
|
||||
local adverb, adjective, noun
|
||||
adverb = table.get_random(words_table.adverbs)
|
||||
adjective = table.get_random(words_table.adjectives)
|
||||
noun = table.get_random(words_table.nouns)
|
||||
return adverb .. '_' .. adjective .. '_' .. noun
|
||||
end
|
||||
|
||||
--- Calls create_name until a unique name is returned
|
||||
-- @param1 table including adverbs, adjectives, and nouns
|
||||
-- @returns name as a string
|
||||
local function create_unique_name(words_table)
|
||||
local silly_names = global.silly_names
|
||||
local name = create_name(words_table)
|
||||
|
||||
while table.contains(silly_names, name) do
|
||||
name = create_name(words_table)
|
||||
end
|
||||
return name
|
||||
end
|
||||
|
||||
--- Assigns a player a name, stores their old and silly names
|
||||
-- @param1 Takes a LuaPlayer
|
||||
local function name_player(player)
|
||||
-- Store a player's original name in case they want it back.
|
||||
if not global.actual_name[player.index] then
|
||||
global.actual_name[player.index] = player.name
|
||||
end
|
||||
|
||||
-- Because create_unique_name enters a while loop looking for a unique name, ensure we never get stuck.
|
||||
local ceiling = math.min(name_combinations * 0.25, 10000)
|
||||
if global.silly_names.count > ceiling then
|
||||
global.silly_names = {}
|
||||
global.silly_names.count = 0
|
||||
end
|
||||
|
||||
local name = create_unique_name(naming_words)
|
||||
|
||||
table.insert(global.silly_names, name)
|
||||
global.silly_names.count = global.silly_names.count + 1
|
||||
local str = player.name .. ' will now be known as: ' .. name
|
||||
game.print(str)
|
||||
Utils.print_admins(str .. ' (ID: ' .. player.index .. ')', false)
|
||||
player.name = name
|
||||
end
|
||||
|
||||
--- Restores a player's actual name
|
||||
local function restore_name(cmd)
|
||||
local player = Game.get_player_by_index(cmd.player_index)
|
||||
player.name = global.actual_name[player.index]
|
||||
player.print('Your true name has been restored.')
|
||||
end
|
||||
|
||||
--- Passes _event_ on to name_players
|
||||
local function name_player_event(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
name_player(player)
|
||||
end
|
||||
|
||||
--- Passes target or player on to name_players
|
||||
local function name_player_command(cmd)
|
||||
local player = game.player
|
||||
local param = cmd.parameter
|
||||
local target
|
||||
|
||||
if param then
|
||||
target = game.players[param]
|
||||
if player and not player.admin then
|
||||
-- Yes param, yes player, no admin/server = fail, non-admins, non-server cannot use command on others
|
||||
Game.player_print("Sorry you don't have permission to use the roll-name command on other players.")
|
||||
return
|
||||
else
|
||||
-- Yes param, yes admin/server = check target
|
||||
if target then
|
||||
-- Yes param, yes admin/server, yes target = change name
|
||||
name_player(target)
|
||||
return
|
||||
else
|
||||
-- Yes param, yes admin/server, no target = fail, wrong player name
|
||||
Game.player_print(table.concat {"Sorry, player '", param, "' was not found."})
|
||||
return
|
||||
end
|
||||
end
|
||||
else
|
||||
-- No param = check if server
|
||||
if not player then
|
||||
-- No param, no player = server trying to change its name
|
||||
Game.player_print('The server cannot change its name')
|
||||
return
|
||||
end
|
||||
-- No param, not server = change self name
|
||||
name_player(player)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
--- Prints the original name of the target
|
||||
local function check_name(cmd)
|
||||
local current_name = cmd.parameter
|
||||
if not current_name then
|
||||
Game.player_print('Usage: /name-check <player>')
|
||||
return
|
||||
end
|
||||
|
||||
local target = game.players[current_name]
|
||||
if not target then
|
||||
Game.player_print('player ' .. current_name .. ' not found')
|
||||
return
|
||||
end
|
||||
|
||||
local actual_name = global.actual_name[target.index]
|
||||
Game.player_print(target.name .. ' is actually: ' .. actual_name)
|
||||
end
|
||||
|
||||
--- Prints the index of the target
|
||||
local function get_player_id(cmd)
|
||||
local player = game.player
|
||||
-- Check if the player can run the command
|
||||
if player and not player.admin then
|
||||
Utils.cant_run(cmd.name)
|
||||
return
|
||||
end
|
||||
-- Check if the target is valid
|
||||
local target_name = cmd['parameter']
|
||||
if not target_name then
|
||||
Game.player_print('Usage: /get-player-id <player>')
|
||||
return
|
||||
end
|
||||
local target_index = game.players[target_name].index
|
||||
Game.player_print(target_name .. ' -- ' .. target_index)
|
||||
end
|
||||
|
||||
if global.scenario.config.players_assigned_names == true then
|
||||
Event.add(defines.events.on_player_created, name_player_event)
|
||||
end
|
||||
|
||||
if global.scenario.config.players_roll_names == true then
|
||||
commands.add_command('name-roll', 'Assigns you a random, silly name', name_player_command)
|
||||
end
|
||||
|
||||
if global.scenario.config.players_roll_names == true or global.scenario.config.players_assigned_names == true then
|
||||
commands.add_command('name-restore', 'Removes your fun name and gives you back your actual name', restore_name)
|
||||
commands.add_command('name-check', '<player> Check the original name of a player', check_name)
|
||||
commands.add_command('get-player-id', 'Gets the ID of a player (Admin only)', get_player_id)
|
||||
end
|
||||
159
map_gen/misc/silly_player_names.lua
Normal file
159
map_gen/misc/silly_player_names.lua
Normal file
@@ -0,0 +1,159 @@
|
||||
require 'utils.list_utils'
|
||||
local Game = require 'utils.game'
|
||||
local Event = require 'utils.event'
|
||||
local naming_words = require 'resources.naming_words'
|
||||
local Utils = require('utils.utils')
|
||||
global.actual_name = {}
|
||||
global.silly_names = {}
|
||||
global.silly_names.count = 0
|
||||
|
||||
local name_combinations = #naming_words.adverbs * #naming_words.adjectives * #naming_words.nouns
|
||||
|
||||
--- Creates name by combining elements from the passed table
|
||||
-- @param1 table including adverbs, adjectives, and nouns
|
||||
-- @returns name as a string
|
||||
local function create_name(words_table)
|
||||
local adverb, adjective, noun
|
||||
adverb = table.get_random(words_table.adverbs)
|
||||
adjective = table.get_random(words_table.adjectives)
|
||||
noun = table.get_random(words_table.nouns)
|
||||
return adverb .. '_' .. adjective .. '_' .. noun
|
||||
end
|
||||
|
||||
--- Calls create_name until a unique name is returned
|
||||
-- @param1 table including adverbs, adjectives, and nouns
|
||||
-- @returns name as a string
|
||||
local function create_unique_name(words_table)
|
||||
local silly_names = global.silly_names
|
||||
local name = create_name(words_table)
|
||||
|
||||
while table.contains(silly_names, name) do
|
||||
name = create_name(words_table)
|
||||
end
|
||||
return name
|
||||
end
|
||||
|
||||
--- Assigns a player a name, stores their old and silly names
|
||||
-- @param1 Takes a LuaPlayer
|
||||
local function name_player(player)
|
||||
-- Store a player's original name in case they want it back.
|
||||
if not global.actual_name[player.index] then
|
||||
global.actual_name[player.index] = player.name
|
||||
end
|
||||
|
||||
-- Because create_unique_name enters a while loop looking for a unique name, ensure we never get stuck.
|
||||
local ceiling = math.min(name_combinations * 0.25, 10000)
|
||||
if global.silly_names.count > ceiling then
|
||||
global.silly_names = {}
|
||||
global.silly_names.count = 0
|
||||
end
|
||||
|
||||
local name = create_unique_name(naming_words)
|
||||
|
||||
table.insert(global.silly_names, name)
|
||||
global.silly_names.count = global.silly_names.count + 1
|
||||
local str = player.name .. ' will now be known as: ' .. name
|
||||
game.print(str)
|
||||
Utils.print_admins(str .. ' (ID: ' .. player.index .. ')', false)
|
||||
player.name = name
|
||||
end
|
||||
|
||||
--- Restores a player's actual name
|
||||
local function restore_name(cmd)
|
||||
local player = Game.get_player_by_index(cmd.player_index)
|
||||
player.name = global.actual_name[player.index]
|
||||
player.print('Your true name has been restored.')
|
||||
end
|
||||
|
||||
--- Passes _event_ on to name_players
|
||||
local function name_player_event(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
name_player(player)
|
||||
end
|
||||
|
||||
--- Passes target or player on to name_players
|
||||
local function name_player_command(cmd)
|
||||
local player = game.player
|
||||
local param = cmd.parameter
|
||||
local target
|
||||
|
||||
if param then
|
||||
target = game.players[param]
|
||||
if player and not player.admin then
|
||||
-- Yes param, yes player, no admin/server = fail, non-admins, non-server cannot use command on others
|
||||
Game.player_print("Sorry you don't have permission to use the roll-name command on other players.")
|
||||
return
|
||||
else
|
||||
-- Yes param, yes admin/server = check target
|
||||
if target then
|
||||
-- Yes param, yes admin/server, yes target = change name
|
||||
name_player(target)
|
||||
return
|
||||
else
|
||||
-- Yes param, yes admin/server, no target = fail, wrong player name
|
||||
Game.player_print(table.concat {"Sorry, player '", param, "' was not found."})
|
||||
return
|
||||
end
|
||||
end
|
||||
else
|
||||
-- No param = check if server
|
||||
if not player then
|
||||
-- No param, no player = server trying to change its name
|
||||
Game.player_print('The server cannot change its name')
|
||||
return
|
||||
end
|
||||
-- No param, not server = change self name
|
||||
name_player(player)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
--- Prints the original name of the target
|
||||
local function check_name(cmd)
|
||||
local current_name = cmd.parameter
|
||||
if not current_name then
|
||||
Game.player_print('Usage: /name-check <player>')
|
||||
return
|
||||
end
|
||||
|
||||
local target = game.players[current_name]
|
||||
if not target then
|
||||
Game.player_print('player ' .. current_name .. ' not found')
|
||||
return
|
||||
end
|
||||
|
||||
local actual_name = global.actual_name[target.index]
|
||||
Game.player_print(target.name .. ' is actually: ' .. actual_name)
|
||||
end
|
||||
|
||||
--- Prints the index of the target
|
||||
local function get_player_id(cmd)
|
||||
local player = game.player
|
||||
-- Check if the player can run the command
|
||||
if player and not player.admin then
|
||||
Utils.cant_run(cmd.name)
|
||||
return
|
||||
end
|
||||
-- Check if the target is valid
|
||||
local target_name = cmd['parameter']
|
||||
if not target_name then
|
||||
Game.player_print('Usage: /get-player-id <player>')
|
||||
return
|
||||
end
|
||||
local target_index = game.players[target_name].index
|
||||
Game.player_print(target_name .. ' -- ' .. target_index)
|
||||
end
|
||||
|
||||
if global.scenario.config.players_assigned_names == true then
|
||||
Event.add(defines.events.on_player_created, name_player_event)
|
||||
end
|
||||
|
||||
if global.scenario.config.players_roll_names == true then
|
||||
commands.add_command('name-roll', 'Assigns you a random, silly name', name_player_command)
|
||||
end
|
||||
|
||||
if global.scenario.config.players_roll_names == true or global.scenario.config.players_assigned_names == true then
|
||||
commands.add_command('name-restore', 'Removes your fun name and gives you back your actual name', restore_name)
|
||||
commands.add_command('name-check', '<player> Check the original name of a player', check_name)
|
||||
commands.add_command('get-player-id', 'Gets the ID of a player (Admin only)', get_player_id)
|
||||
end
|
||||
@@ -139,6 +139,7 @@ local terrain_modules = {
|
||||
--require 'map_gen.misc.nightfall'
|
||||
--require 'map_gen.misc.creep_spread'
|
||||
--require 'map_gen.misc.car_body'
|
||||
--require 'features.silly_player_names'
|
||||
|
||||
if #entity_modules > 0 then
|
||||
shape = shape or b.full_shape
|
||||
|
||||
253
resources/naming_words.lua
Normal file
253
resources/naming_words.lua
Normal file
@@ -0,0 +1,253 @@
|
||||
-- Currently geared towards the winter holidays but we can always revise if needed.
|
||||
-- (Ex. a table of standard/common words and tables for season-specific words, then combined for specific purposes/use-cases)
|
||||
|
||||
local Module = {}
|
||||
|
||||
Module.adverbs = {
|
||||
'Abnormally',
|
||||
'Accidentally',
|
||||
'Adventurously',
|
||||
'Anxiously',
|
||||
'Arrogantly',
|
||||
'Awkwardly',
|
||||
'Bashfully',
|
||||
'Beautifully',
|
||||
'Blindly',
|
||||
'Blissfully',
|
||||
'Boastfully',
|
||||
'Boldly',
|
||||
'Bravely',
|
||||
'Calmly',
|
||||
'Carefully',
|
||||
'Carelessly',
|
||||
'Cautiously',
|
||||
'Certainly',
|
||||
'Cheerfully',
|
||||
'Clearly',
|
||||
'Closely',
|
||||
'Continually',
|
||||
'Courageously',
|
||||
'Cruelly',
|
||||
'Curiously',
|
||||
'Dearly',
|
||||
'Deeply',
|
||||
'Defiantly',
|
||||
'Deliberately',
|
||||
'Delightfully',
|
||||
'Dimly',
|
||||
'Doubtfully',
|
||||
'Dreamily',
|
||||
'Easily',
|
||||
'Elegantly',
|
||||
'Energetically',
|
||||
'Enormously',
|
||||
'Enthusiastically',
|
||||
'Especially',
|
||||
'Eventually',
|
||||
'Excitedly',
|
||||
'Extremely',
|
||||
'Fairly',
|
||||
'Faithfully',
|
||||
'Famously',
|
||||
'Fatally',
|
||||
'Ferociously',
|
||||
'Fervently',
|
||||
'Fiercely',
|
||||
'Fondly',
|
||||
'Foolishly',
|
||||
'Frantically',
|
||||
'Frightfully',
|
||||
'Furiously',
|
||||
'Generally',
|
||||
'Generously',
|
||||
'Gently',
|
||||
'Gladly',
|
||||
'Gleefully',
|
||||
'Gracefully',
|
||||
'Greatly',
|
||||
'Happily',
|
||||
'Heavily',
|
||||
'Helpfully',
|
||||
'Helplessly',
|
||||
'Honestly',
|
||||
'Hopelessly',
|
||||
'Hungrily',
|
||||
'Innocently',
|
||||
'Inquisitively',
|
||||
'Intensely',
|
||||
'Interestingly',
|
||||
'Irritably',
|
||||
'Jovially',
|
||||
'Joyfully',
|
||||
'Kindheartedly',
|
||||
'Kindly',
|
||||
'Knowingly',
|
||||
'Lazily',
|
||||
'Lively',
|
||||
'Longingly',
|
||||
'Loosely',
|
||||
'Loudly',
|
||||
'Lovingly',
|
||||
'Loyally',
|
||||
'Madly',
|
||||
'Majestically',
|
||||
'Merrily',
|
||||
'Miserably',
|
||||
'Mockingly',
|
||||
'Mostly',
|
||||
'Mysteriously',
|
||||
'Naturally',
|
||||
'Nearly',
|
||||
'Nicely',
|
||||
'Noisily',
|
||||
'Obnoxiously',
|
||||
'Offensively',
|
||||
'Optimistically',
|
||||
'Painfully',
|
||||
'Patiently',
|
||||
'Perfectly',
|
||||
'Playfully',
|
||||
'Politely',
|
||||
'Positively',
|
||||
'Powerfully',
|
||||
'Questionably',
|
||||
'Quickly',
|
||||
'Quietly',
|
||||
'Randomly',
|
||||
'Rapidly',
|
||||
'Readily',
|
||||
'Reluctantly',
|
||||
'Righteously',
|
||||
'Safely',
|
||||
'Seemingly',
|
||||
'Selfishly',
|
||||
'Silently',
|
||||
'Sleepily',
|
||||
'Stealthily',
|
||||
'Successfully',
|
||||
'Suddenly',
|
||||
'Surprisingly',
|
||||
'Suspiciously',
|
||||
'Sweetly',
|
||||
'Tenderly',
|
||||
'Thankfully',
|
||||
'Unbearably',
|
||||
'Unexpectedly',
|
||||
'Unfortunately',
|
||||
'Unimpressively',
|
||||
'Unnecessarily',
|
||||
'Urgently',
|
||||
'Uselessly',
|
||||
'Vaguely',
|
||||
'Warmly',
|
||||
'Wildly',
|
||||
'Wisely',
|
||||
'Wrongly',
|
||||
'Youthfully',
|
||||
}
|
||||
|
||||
Module.adjectives = {
|
||||
'Amazing',
|
||||
'Attractive',
|
||||
'Awesome',
|
||||
'Beautiful',
|
||||
'Big',
|
||||
'Blissful',
|
||||
'Brave',
|
||||
'Breathtaking',
|
||||
'Careful',
|
||||
'Caroling',
|
||||
'Chubby',
|
||||
'Clever',
|
||||
'Clumsy',
|
||||
'Dazzling',
|
||||
'Delightful',
|
||||
'Eager',
|
||||
'Excitable',
|
||||
'Fabulous',
|
||||
'Faithful',
|
||||
'Fancy',
|
||||
'Fantastic',
|
||||
'Fantastical',
|
||||
'Fierce',
|
||||
'Gentle',
|
||||
'Glamorous',
|
||||
'Gorgeous',
|
||||
'Great',
|
||||
'Grumpy',
|
||||
'Happy',
|
||||
'Helpful',
|
||||
'Interesting',
|
||||
'Jolly',
|
||||
'Kind',
|
||||
'Lazy',
|
||||
'Magical',
|
||||
'Magnificent',
|
||||
'Merry',
|
||||
'Muscular',
|
||||
'Mystical',
|
||||
'Naughty',
|
||||
'Nice',
|
||||
'Obedient',
|
||||
'Peaceful',
|
||||
'Plump',
|
||||
'Polite',
|
||||
'Quaint',
|
||||
'Remarkable',
|
||||
'Roasting',
|
||||
'Scary',
|
||||
'Silly',
|
||||
'Small',
|
||||
'Tender',
|
||||
'Thoughtful',
|
||||
'White',
|
||||
'Witty',
|
||||
'Wonderful',
|
||||
}
|
||||
|
||||
Module.nouns = {
|
||||
'Advent',
|
||||
'Angel',
|
||||
'Bear',
|
||||
'Bell',
|
||||
'Candy Cane',
|
||||
'Caroler',
|
||||
'Chestnut',
|
||||
'Christmas Stocking',
|
||||
'Decoration',
|
||||
'Elf',
|
||||
'Feast',
|
||||
'Fruit Cake',
|
||||
'Garland',
|
||||
'Gift',
|
||||
'Grinch',
|
||||
'Ham',
|
||||
'Helper',
|
||||
'Holiday Dinner',
|
||||
'Holiday Sweater',
|
||||
'Holly',
|
||||
'Ice Skate',
|
||||
'Ivy',
|
||||
'Menora',
|
||||
'Miracle',
|
||||
'Mistletoe',
|
||||
'Ornament',
|
||||
'Package',
|
||||
'Party',
|
||||
'Present',
|
||||
'Reindeer',
|
||||
'Ribbon',
|
||||
'Scarf',
|
||||
'Scrooge',
|
||||
'Sleigh',
|
||||
'Snowball',
|
||||
'Snowflake',
|
||||
'Snowman',
|
||||
'Sugarplum',
|
||||
'Toy',
|
||||
'Tree',
|
||||
'Turkey',
|
||||
'Wreath',
|
||||
}
|
||||
|
||||
return Module
|
||||
Reference in New Issue
Block a user