Merge pull request #171 from Cooldude2606/feature/general-clean-up

Cleanup before master merge
This commit is contained in:
Cooldude2606
2020-08-14 03:50:27 +01:00
committed by GitHub
20 changed files with 204 additions and 222 deletions

View File

@@ -4,115 +4,117 @@
local Async = require 'expcore.async'
local format_time = _C.format_time --- @dep expcore.common
-- eg Async(async_message, is_command or player, message)
local async_message = Async.register(function(player, message)
player.print(message)
if player == true then game.print(message) else player.print(message) end
end)
-- luacheck:ignore 212/player 212/is_command
return {
allow_command_prefix_for_messages = true, --- @setting allow_command_prefix_for_messages when true any message trigger will print to all player when prefixed
messages = { --- @setting messages will trigger when ever the word is said
['discord']={'info.discord'},
['expgaming']={'info.website'},
['website']={'info.website'},
['wiki']={'info.wiki'},
['status']={'info.status'},
['github']={'info.github'},
['patreon']={'info.patreon'},
['donate']={'info.patreon'},
['command']={'info.custom-commands'},
['commands']={'info.custom-commands'},
['softmod']={'info.softmod'},
['script']={'info.softmod'},
['loop']={'chat-bot.loops'},
['rhd']={'info.lhd'},
['lhd']={'info.lhd'},
['roundabout']={'chat-bot.loops'},
['roundabouts']={'chat-bot.loops'},
['redmew']={'info.redmew'},
['afk']=function(player)
local max=player
for _,next_player in pairs(game.connected_players) do
['discord'] = {'info.discord'},
['expgaming'] = {'info.website'},
['website'] = {'info.website'},
['wiki'] = {'info.wiki'},
['status'] = {'info.status'},
['github'] = {'info.github'},
['patreon'] = {'info.patreon'},
['donate'] = {'info.patreon'},
['command'] = {'info.custom-commands'},
['commands'] = {'info.custom-commands'},
['softmod'] = {'info.softmod'},
['script'] = {'info.softmod'},
['loop'] = {'chat-bot.loops'},
['rhd'] = {'info.lhd'},
['lhd'] = {'info.lhd'},
['roundabout'] = {'chat-bot.loops'},
['roundabouts'] = {'chat-bot.loops'},
['redmew'] = {'info.redmew'},
['afk'] = function(player)
local max = player
for _, next_player in pairs(game.connected_players) do
if max.afk_time < next_player.afk_time then
max=next_player
max = next_player
end
end
return {'chat-bot.afk',max.name,format_time(max.afk_time,{minutes=true,seconds=true,long=true})}
return {'chat-bot.afk', max.name, format_time(max.afk_time, {minutes = true, seconds = true, long = true})}
end,
['players']=function()
return {'chat-bot.players',#game.players}
['players'] = function()
return {'chat-bot.players', #game.players}
end,
['online']=function()
return {'chat-bot.players-online',#game.connected_players}
['online'] = function()
return {'chat-bot.players-online', #game.connected_players}
end,
['r!verify']=function(player)
return {'chat-bot.verify',player.name}
['r!verify'] = function(player)
return {'chat-bot.verify', player.name}
end,
},
command_admin_only = false, --- @setting command_admin_only when true will only allow chat commands for admins
command_permission = 'command/chat-bot', --- @setting command_permission the permission used to allow command prefixes
command_prefix = '!', --- @setting command_prefix prefix used for commands below and to print to all players (if enabled above)
commands = { --- @setting commands will trigger only when command prefix is given
['dev']={'chat-bot.not-real-dev'},
['blame']=function(player)
local names = {'Cooldude2606','arty714','badgamernl', 'mark9064', 'aldldl', 'Drahc_pro',player.name}
for _,next_player in pairs(game.connected_players) do
['dev'] = {'chat-bot.not-real-dev'},
['blame'] = function(player)
local names = {'Cooldude2606', 'arty714', 'badgamernl', 'mark9064', 'aldldl', 'Drahc_pro', player.name}
for _, next_player in pairs(game.connected_players) do
names[#names + 1] = next_player.name
end
return {'chat-bot.blame',table.get_random_dictionary_entry(names)}
return {'chat-bot.blame', table.get_random_dictionary_entry(names)}
end,
['magic']={'chat-bot.magic'},
['aids']={'chat-bot.aids'},
['riot']={'chat-bot.riot'},
['lenny']={'chat-bot.lenny'},
['hodor']=function()
local options = {'?','.','!','!!!'}
return {'chat-bot.hodor',table.get_random_dictionary_entry(options)}
['magic'] = {'chat-bot.magic'},
['aids'] = {'chat-bot.aids'},
['riot'] = {'chat-bot.riot'},
['lenny'] = {'chat-bot.lenny'},
['hodor'] = function()
local options = {'?', '.', '!', '!!!'}
return {'chat-bot.hodor', table.get_random_dictionary_entry(options)}
end,
['evolution']=function()
return {'chat-bot.current-evolution',string.format('%.2f',game.forces['enemy'].evolution_factor)}
['evolution'] = function()
return {'chat-bot.current-evolution', string.format('%.2f', game.forces['enemy'].evolution_factor)}
end,
['makepopcorn']=function(player)
['makepopcorn'] = function(player)
local timeout = math.floor(180*(math.random()+0.5))
Async(async_message,player,{'chat-bot.reply',{'chat-bot.get-popcorn-1'}})
Async.wait(timeout,async_message,player,{'chat-bot.reply',{'chat-bot.get-popcorn-2',player.name}})
Async(async_message, true, {'chat-bot.reply', {'chat-bot.get-popcorn-1'}})
Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.get-popcorn-2', player.name}})
end,
['passsomesnaps']=function(player)
['passsomesnaps'] = function(player)
local timeout = math.floor(180*(math.random()+0.5))
Async(async_message,player,{'chat-bot.reply',{'chat-bot.get-snaps-1'}})
Async.wait(timeout,async_message,player,{'chat-bot.reply',{'chat-bot.get-snaps-2',player.name}})
Async.wait(timeout*(math.random()+0.5),async_message,player,{'chat-bot.reply',{'chat-bot.get-snaps-3',player.name}})
Async(async_message, player, {'chat-bot.reply', {'chat-bot.get-snaps-1'}})
Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.get-snaps-2', player.name}})
Async.wait(timeout*(math.random()+0.5), async_message, true, {'chat-bot.reply', {'chat-bot.get-snaps-3', player.name}})
end,
['makecocktail']=function(player)
['makecocktail'] = function(player)
local timeout = math.floor(180*(math.random()+0.5))
Async(async_message,player,{'chat-bot.reply',{'chat-bot.get-cocktail-1'}})
Async.wait(timeout,async_message,player,{'chat-bot.reply',{'chat-bot.get-cocktail-2',player.name}})
Async.wait(timeout*(math.random()+0.5),async_message,player,{'chat-bot.reply',{'chat-bot.get-cocktail-3',player.name}})
Async(async_message, true, {'chat-bot.reply', {'chat-bot.get-cocktail-1'}})
Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.get-cocktail-2', player.name}})
Async.wait(timeout*(math.random()+0.5), async_message, true, {'chat-bot.reply', {'chat-bot.get-cocktail-3', player.name}})
end,
['makecoffee']=function(player)
['makecoffee'] = function(player)
local timeout = math.floor(180*(math.random()+0.5))
Async(async_message,player,{'chat-bot.reply',{'chat-bot.make-coffee-1'}})
Async.wait(timeout,async_message,player,{'chat-bot.reply',{'chat-bot.make-coffee-2',player.name}})
Async(async_message, true, {'chat-bot.reply', {'chat-bot.make-coffee-1'}})
Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.make-coffee-2', player.name}})
end,
['orderpizza']=function(player)
['orderpizza'] = function(player)
local timeout = math.floor(180*(math.random()+0.5))
Async(async_message,player,{'chat-bot.reply',{'chat-bot.order-pizza-1'}})
Async.wait(timeout,async_message,player,{'chat-bot.reply',{'chat-bot.order-pizza-2',player.name}})
Async.wait(timeout*(math.random()+0.5),async_message,player,{'chat-bot.reply',{'chat-bot.order-pizza-3',player.name}})
Async(async_message, true, {'chat-bot.reply', {'chat-bot.order-pizza-1'}})
Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.order-pizza-2', player.name}})
Async.wait(timeout*(math.random()+0.5), async_message, true, {'chat-bot.reply', {'chat-bot.order-pizza-3', player.name}})
end,
['maketea']=function(player)
['maketea'] = function(player)
local timeout = math.floor(180*(math.random()+0.5))
Async(async_message,player,{'chat-bot.reply',{'chat-bot.make-tea-1'}})
Async.wait(timeout,async_message,player,{'chat-bot.reply',{'chat-bot.make-tea-2',player.name}})
Async(async_message, true, {'chat-bot.reply', {'chat-bot.make-tea-1'}})
Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.make-tea-2', player.name}})
end,
['meadplease']=function(player)
['meadplease'] = function(player)
local timeout = math.floor(180*(math.random()+0.5))
Async(async_message,player,{'chat-bot.reply',{'chat-bot.get-mead-1'}})
Async.wait(timeout,async_message,player,{'chat-bot.reply',{'chat-bot.get-mead-2',player.name}})
Async(async_message, true, {'chat-bot.reply', {'chat-bot.get-mead-1'}})
Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.get-mead-2', player.name}})
end,
['passabeer']=function(player)
['passabeer'] = function(player)
local timeout = math.floor(180*(math.random()+0.5))
Async(async_message,player,{'chat-bot.reply',{'chat-bot.get-beer-1'}})
Async.wait(timeout,async_message,player,{'chat-bot.reply',{'chat-bot.get-beer-2',player.name}})
Async(async_message, true, {'chat-bot.reply', {'chat-bot.get-beer-1'}})
Async.wait(timeout, async_message, true, {'chat-bot.reply', {'chat-bot.get-beer-2', player.name}})
end
}
}

View File

@@ -20,7 +20,6 @@ see ./expcore/commands.lua for more details
]]
local Commands = require 'expcore.commands' --- @dep expcore.commands
local Game = require 'utils.game' --- @dep utils.game
-- luacheck:ignore 212/player
Commands.add_parse('boolean',function(input, player)
@@ -94,7 +93,7 @@ end)
Commands.add_parse('player',function(input, player, reject)
if not input then return end -- nil check
local input_player = Game.get_player_from_any(input)
local input_player = game.players[input]
if not input_player then
return reject{'expcore-commands.reject-player',input}
else

View File

@@ -44,11 +44,11 @@ end)
Commands.add_parse('player-role-online',function(input, player, reject)
local input_player = Commands.parse('player-role',input, player, reject)
if not input_player then return end -- nil check
return Commands.parse('player-online',input_player, player, reject)
return Commands.parse('player-online',input_player.name, player, reject)
end)
Commands.add_parse('player-role-alive',function(input, player, reject)
local input_player = Commands.parse('player-role',input, player, reject)
if not input_player then return end -- nil check
return Commands.parse('player-alive',input_player, player, reject)
return Commands.parse('player-alive',input_player.name, player, reject)
end)

View File

@@ -5,7 +5,6 @@
-- @config Permission-Groups
--local Event = require 'utils.event' -- @dep utils.event
--local Game = require 'utils.game' -- @dep utils.game
local Permission_Groups = require 'expcore.permission_groups' --- @dep expcore.permission_groups
Permission_Groups.new_group('Admin')
@@ -120,17 +119,17 @@ local function assign_group(player)
end
Event.add(defines.events.on_player_joined_game,function(event)
local player = Game.get_player_by_index(event.player_index)
local player = game.players[event.player_index]
assign_group(player)
end)
Event.add(defines.events.on_player_promoted,function(event)
local player = Game.get_player_by_index(event.player_index)
local player = game.players[event.player_index]
assign_group(player)
end)
Event.add(defines.events.on_player_demoted,function(event)
local player = Game.get_player_by_index(event.player_index)
local player = game.players[event.player_index]
assign_group(player)
end)

View File

@@ -7,7 +7,6 @@
local Gui = require 'expcore.gui' --- @dep expcore.gui
local Roles = require 'expcore.roles' --- @dep expcore.roles
local Game = require 'utils.game' --- @dep utils.game
local Reports = require 'modules.control.reports' --- @dep modules.control.reports
local Warnings = require 'modules.control.warnings' --- @dep modules.control.warnings
local Jail = require 'modules.control.jail' --- @dep modules.control.jail
@@ -31,7 +30,7 @@ end
-- gets the action player and a coloured name for the action to be used on
local function get_action_player_name(player)
local selected_player_name = SelectedPlayer:get(player)
local selected_player = Game.get_player_from_any(selected_player_name)
local selected_player = game.players[selected_player_name]
local selected_player_color = format_chat_player_name(selected_player)
return selected_player_name, selected_player_color
end
@@ -64,7 +63,7 @@ end
local goto_player = new_button('utility/export',{'player-list.goto-player'})
:on_click(function(player)
local selected_player_name = get_action_player_name(player)
local selected_player = Game.get_player_from_any(selected_player_name)
local selected_player = game.players[selected_player_name]
if not player.character or not selected_player.character then
player.print({'expcore-commands.reject-player-alive'},Colors.orange_red)
else
@@ -77,7 +76,7 @@ end)
local bring_player = new_button('utility/import',{'player-list.bring-player'})
:on_click(function(player)
local selected_player_name = get_action_player_name(player)
local selected_player = Game.get_player_from_any(selected_player_name)
local selected_player = game.players[selected_player_name]
if not player.character or not selected_player.character then
player.print({'expcore-commands.reject-player-alive'},Colors.orange_red)
else
@@ -90,7 +89,7 @@ end)
local kill_player = new_button('utility/too_far',{'player-list.kill-player'})
:on_click(function(player)
local selected_player_name = get_action_player_name(player)
local selected_player = Game.get_player_from_any(selected_player_name)
local selected_player = game.players[selected_player_name]
if selected_player.character then
selected_player.character.die()
else

View File

@@ -101,16 +101,18 @@ end
--[[-- Gets the status of the given server
@tparam string server_id The internal server if for the server you want the status of
@treturn string The status of the given server, one of: Online, Modded, Protected, Offline
@tparam boolean raw When true Current will not be returned as status but rather the raw status for the server
@treturn string The status of the given server, one of: Online, Modded, Protected, Current, Offline
@usage-- Get the status of the given server
local status = External.get_server_status('eu-01')
]]
function External.get_server_status(server_id)
function External.get_server_status(server_id, raw)
assert(var, 'No external data was found, use External.valid() to ensure external data exists.')
local servers = assert(var.status, 'No server status was found, please ensure that the external service is running')
return servers[server_id]
local current = assert(ext.current, 'No current id was found, please ensure that the external service is running')
return not raw and server_id == current and 'Current' or servers[server_id]
end
--[[-- Gets the ups of the current server

View File

@@ -147,6 +147,7 @@ servers-d7=This is our event server, we try to run events at least once per week
servers-8=S8 T̷-̶s̶-̴:̷
servers-d8=N̵o̴ ̶o̷-̶e̵ ̴k̸n̷-̶w̵s̸ ̴w̷h̷a̶-̶ ̷h̴a̴p̷p̴e̷n̷s̸ ̷o̶n̴ ̷t̶h̴-̶s̶ ̷s̷e̶r̸v̸e̴r̷,̶ ̸i̸t̴ ̷m̶-̸g̴h̶t̷ ̸n̸-̶t̵ ̷e̴v̸e̸n̶t̷ ̵-̷x̴i̵s̶t̸.̸
servers-connect-Offline=Server is currently offline
servers-connect-Current=This is your current server
servers-connect-Version=Server is on a different version: __1__
servers-connect-Password=Server requires a password
servers-connect-Modded=Server requires mods to be downloaded

View File

@@ -2,12 +2,11 @@
-- @addon Advanced-Start
local Event = require 'utils.event' --- @dep utils.event
local Game = require 'utils.game' --- @dep utils.game
local config = require 'config.advanced_start' --- @dep config.advanced_start
local items = config.items
Event.add(defines.events.on_player_created, function(event)
local player = Game.get_player_by_index(event.player_index)
local player = game.players[event.player_index]
-- game init settings
if event.player_index == 1 then
player.force.friendly_fire = config.friendly_fire

View File

@@ -10,7 +10,7 @@ local send_text = Game.print_player_floating_text -- (player_index, text, color)
Event.add(defines.events.on_console_chat, function(event)
if not event.player_index or event.player_index < 1 then return end
local player = Game.get_player_by_index(event.player_index)
local player = game.players[event.player_index]
-- Some basic sanity checks
if not player then return end

View File

@@ -1,15 +1,14 @@
--- Adds auto replies to chat messages; aswell as chat commands
--- Adds auto replies to chat messages; as well as chat commands
-- @addon Chat-Reply
local Event = require 'utils.event' --- @dep utils.event
local Game = require 'utils.game' --- @dep utils.game
local Roles = require 'expcore.roles' --- @dep expcore.roles
local config = require 'config.chat_reply' --- @dep config.chat_reply
Event.add(defines.events.on_console_chat, function(event)
local player_index = event.player_index
if not player_index or player_index < 1 then return end
local player = Game.get_player_by_index(player_index)
local player = game.players[player_index]
local message = event.message:lower():gsub("%s+", "")
local allowed = true
if config.command_admin_only and not player.admin then allowed = false end
@@ -18,16 +17,15 @@ Event.add(defines.events.on_console_chat, function(event)
local prefix = config.command_prefix
for key_word, reply in pairs(config.messages) do
if message:find(key_word) then
local is_command = message:find(prefix..key_word)
if type(reply) == 'function' then
reply = reply(player)
reply = reply(player, is_command)
end
if message:find(prefix..key_word) then
if allowed then
game.print{'chat-bot.reply', reply}
else
player.print{'chat-bot.disallow'}
end
if is_command and allowed then
game.print{'chat-bot.reply', reply}
elseif is_command then
player.print{'chat-bot.disallow'}
elseif not allowed then
player.print{'chat-bot.reply', reply}
end
@@ -39,7 +37,7 @@ Event.add(defines.events.on_console_chat, function(event)
for key_word, reply in pairs(config.commands) do
if message:find(prefix..key_word) then
if type(reply) == 'function' then
reply = reply(player)
reply = reply(player, true)
if reply then
game.print{'chat-bot.reply', reply}

View File

@@ -3,7 +3,6 @@
local Event = require 'utils.event' --- @dep utils.event
local Global = require 'utils.global' --- @dep utils.global
local Game = require 'utils.game' --- @dep utils.game
local Task = require 'utils.task' --- @dep utils.task
local Token = require 'utils.token' --- @dep utils.token
local config = require 'config.compilatron' --- @dep config.compilatron
@@ -95,7 +94,7 @@ end
-- When the first player is created this will create all compilatrons that are resisted in the config
Event.add(defines.events.on_player_created, function(event)
if event.player_index ~= 1 then return end
local player = Game.get_player_by_index(event.player_index)
local player = game.players[event.player_index]
for location in pairs(locations) do
Public.spawn_compilatron(player.surface, location)
end

View File

@@ -2,7 +2,6 @@
-- @addon Death-Logger
local Event = require 'utils.event' --- @dep utils.event
local Game = require 'utils.game' --- @dep utils.game
local Global = require 'utils.global' --- @dep utils.global
local config = require 'config.death_logger' --- @dep config.death_logger
local format_time, move_items = _C.format_time, _C.move_items --- @dep expcore.common
@@ -17,7 +16,7 @@ end)
--- Creates a new death marker and saves it to the given death
local function create_map_tag(death)
local player = Game.get_player_from_any(death.player_name)
local player = game.players[death.player_name]
local message = player.name..' died'
if config.include_time_of_death then
local time = format_time(death.time_of_death, {hours=true, minutes=true, string=true})
@@ -59,7 +58,7 @@ end
-- when a player dies a new death is added to the records and a map marker is made
Event.add(defines.events.on_player_died, function(event)
local player = Game.get_player_by_index(event.player_index)
local player = game.players[event.player_index]
local corpse = player.surface.find_entity('character-corpse', player.position)
if config.use_chests_as_bodies then
local items = corpse.get_inventory(defines.inventory.character_corpse).get_contents()

View File

@@ -2,13 +2,12 @@
-- @addon Discord-Alerts
local Event = require 'utils.event' --- @dep utils.event
local Game = require 'utils.game' --- @dep utils.game
local Colors = require 'utils.color_presets' --- @dep utils.color_presets
local write_json, format_time = _C.write_json, _C.format_time --- @dep expcore.common
local config = require 'config.discord_alerts' --- @dep config.discord_alerts
local function get_player_name(event)
local player = Game.get_player_by_index(event.player_index)
local player = game.players[event.player_index]
return player.name, event.by_player_name
end
@@ -32,8 +31,8 @@ local function emit_event(args)
color = to_hex(color)
end
local tick = args.tick or 0
local tick_formated = format_time(tick, {hours = true, minutes = true, string = true, long = true})
local tick = args.tick or game.tick
local tick_formatted = format_time(tick, {days = true, hours = true, minutes = true, string = true, long = true})
local players_online = 0
local admins_online = 0
@@ -47,7 +46,7 @@ local function emit_event(args)
local done = {title=true, color=true, description=true}
local fields = {{
name='Server Details',
value=string.format('Server name: ${serverName} Players: %d Admins: %d Time: %s', players_online, admins_online, tick_formated)
value=string.format('Server: ${serverName} Time: %s\nTotal: %d Online: %d Admins: %d', tick_formatted, #game.players, players_online, admins_online)
}}
for key, value in pairs(args) do
@@ -86,9 +85,9 @@ if config.player_reports then
title='Report',
description='A player was reported',
color=Colors.yellow,
['Player:']='<inline>'..player_name,
['By:']='<inline>'..by_player_name,
['Reason:']=event.reason
['Player']='<inline>'..player_name,
['By']='<inline>'..by_player_name,
['Reason']=event.reason
}
end)
Event.add(Reports.events.on_report_removed, function(event)
@@ -98,9 +97,9 @@ if config.player_reports then
title='Reports Removed',
description='A player has a report removed',
color=Colors.green,
['Player:']='<inline>'..player_name,
['By:']='<inline>'..event.removed_by_name,
['Amount:']='<inline>'..event.batch_count
['Player']='<inline>'..player_name,
['By']='<inline>'..event.removed_by_name,
['Amount']='<inline>'..event.batch_count
}
end)
end
@@ -114,9 +113,9 @@ if config.player_warnings then
title='Warning',
description='A player has been given a warning',
color=Colors.yellow,
['Player:']='<inline>'..player_name,
['By:']='<inline>'..by_player_name,
['Reason:']=event.reason
['Player']='<inline>'..player_name,
['By']='<inline>'..by_player_name,
['Reason']=event.reason
}
end)
Event.add(Warnings.events.on_warning_removed, function(event)
@@ -126,9 +125,9 @@ if config.player_warnings then
title='Warnings Removed',
description='A player has a warning removed',
color=Colors.green,
['Player:']='<inline>'..player_name,
['By:']='<inline>'..event.removed_by_name,
['Amount:']='<inline>'..event.batch_count
['Player']='<inline>'..player_name,
['By']='<inline>'..event.removed_by_name,
['Amount']='<inline>'..event.batch_count
}
end)
end
@@ -142,9 +141,9 @@ if config.player_jail then
title='Jail',
description='A player has been jailed',
color=Colors.yellow,
['Player:']='<inline>'..player_name,
['By:']='<inline>'..by_player_name,
['Reason:']=event.reason
['Player']='<inline>'..player_name,
['By']='<inline>'..by_player_name,
['Reason']=event.reason
}
end)
Event.add(Jail.events.on_player_unjailed, function(event)
@@ -153,8 +152,8 @@ if config.player_jail then
title='Unjail',
description='A player has been unjailed',
color=Colors.green,
['Player:']='<inline>'..player_name,
['By:']='<inline>'..by_player_name
['Player']='<inline>'..player_name,
['By']='<inline>'..by_player_name
}
end)
end
@@ -168,9 +167,9 @@ if config.player_temp_ban then
title='Temp Ban',
description='A player has been temp banned',
color=Colors.red,
['Player:']='<inline>'..player_name,
['By:']='<inline>'..by_player_name,
['Reason:']=event.reason
['Player']='<inline>'..player_name,
['By']='<inline>'..by_player_name,
['Reason']=event.reason
}
end)
Event.add(Jail.events.on_player_untemp_banned, function(event)
@@ -179,8 +178,8 @@ if config.player_temp_ban then
title='Temp Ban Removed',
description='A player has been untemp banned',
color=Colors.green,
['Player:']='<inline>'..player_name,
['By:']='<inline>'..by_player_name
['Player']='<inline>'..player_name,
['By']='<inline>'..by_player_name
}
end)
end
@@ -189,26 +188,26 @@ end
if config.player_bans then
Event.add(defines.events.on_player_banned, function(event)
if event.by_player then
local by_player = Game.get_player_by_index(event.by_player)
local by_player = game.players[event.by_player]
emit_event{
title='Banned',
description='A player has been banned',
color=Colors.red,
['Player:']='<inline>'..event.player_name,
['By:']='<inline>'..by_player.name,
['Reason:']=event.reason
['Player']='<inline>'..event.player_name,
['By']='<inline>'..by_player.name,
['Reason']=event.reason
}
end
end)
Event.add(defines.events.on_player_unbanned, function(event)
if event.by_player then
local by_player = Game.get_player_by_index(event.by_player)
local by_player = game.players[event.by_player]
emit_event{
title='Un-Banned',
description='A player has been un-banned',
color=Colors.green,
['Player:']='<inline>'..event.player_name,
['By:']='<inline>'..by_player.name
['Player']='<inline>'..event.player_name,
['By']='<inline>'..by_player.name
}
end
end)
@@ -222,7 +221,7 @@ if config.player_mutes then
title='Muted',
description='A player has been muted',
color=Colors.yellow,
['Player:']='<inline>'..player_name
['Player']='<inline>'..player_name
}
end)
Event.add(defines.events.on_player_unmuted, function(event)
@@ -231,7 +230,7 @@ if config.player_mutes then
title='Un-Muted',
description='A player has been un-muted',
color=Colors.green,
['Player:']='<inline>'..player_name
['Player']='<inline>'..player_name
}
end)
end
@@ -241,14 +240,14 @@ if config.player_kicks then
Event.add(defines.events.on_player_kicked, function(event)
if event.by_player then
local player_name = get_player_name(event)
local by_player = Game.get_player_by_index(event.by_player)
local by_player = game.players[event.by_player]
emit_event{
title='Kick',
description='A player has been kicked',
color=Colors.orange,
['Player:']='<inline>'..player_name,
['By:']='<inline>'..by_player.name,
['Reason:']=event.reason
['Player']='<inline>'..player_name,
['By']='<inline>'..by_player.name,
['Reason']=event.reason
}
end
end)
@@ -262,7 +261,7 @@ if config.player_promotes then
title='Promote',
description='A player has been promoted',
color=Colors.green,
['Player:']='<inline>'..player_name
['Player']='<inline>'..player_name
}
end)
Event.add(defines.events.on_player_demoted, function(event)
@@ -271,7 +270,7 @@ if config.player_promotes then
title='Demote',
description='A player has been demoted',
color=Colors.yellow,
['Player:']='<inline>'..player_name
['Player']='<inline>'..player_name
}
end)
end
@@ -285,8 +284,8 @@ Event.add(defines.events.on_console_command, function(event)
title=event.command:gsub('^%l', string.upper),
description='/'..event.command..' was used',
color=Colors.grey,
['By:']='<inline>'..player_name,
['Details:'] = event.parameters ~= '' and event.parameters or nil
['By']='<inline>'..player_name,
['Details'] = event.parameters ~= '' and event.parameters or nil
}
end
end

View File

@@ -2,7 +2,6 @@
-- @addon Scorched-Earth
local Event = require 'utils.event' --- @dep utils.event
local Game = require 'utils.game' --- @dep utils.game
local Global = require 'utils.global' --- @dep utils.global
local print_grid_value, clear_flying_text = _C.print_grid_value, _C.clear_flying_text --- @dep expcore.common
local config = require 'config.scorched_earth' --- @dep config.scorched_earth
@@ -94,7 +93,7 @@ end
-- When the player changes position the tile will have a chance to downgrade, debug check is here
Event.add(defines.events.on_player_changed_position, function(event)
local player = Game.get_player_by_index(event.player_index)
local player = game.players[event.player_index]
local surface = player.surface
local position = player.position
local strength = get_tile_strength(surface, position)
@@ -133,7 +132,7 @@ end)
-- Used as a way to access the global table
return function(player_name, state)
local player = Game.get_player_from_any(player_name)
local player = game.players[player_name]
clear_flying_text(player.surface)
debug_players[player_name] = state
end

View File

@@ -3,7 +3,6 @@
local Global = require 'utils.global' --- @dep utils.global
local Event = require 'utils.event' --- @dep utils.event
local Game = require 'utils.game' --- @dep utils.game
local config = require 'config.spawn_area' --- @dep config.spawn_area
local tiles = config.tiles
local entities = config.entities
@@ -134,7 +133,7 @@ end)
Event.add(defines.events.on_player_created, function(event)
if event.player_index ~= 1 then return end
local player = Game.get_player_by_index(event.player_index)
local player = game.players[event.player_index]
local p = {x=0, y=0}
local s = player.surface
spawn_base(s, p)

View File

@@ -2,7 +2,6 @@
-- @addon Tree-Decon
local Event = require 'utils.event' --- @dep utils.event
local Game = require 'utils.game' --- @dep utils.game
local Global = require 'utils.global' --- @dep utils.global
local Roles = require 'expcore.roles' --- @dep expcore.roles
@@ -19,7 +18,7 @@ Event.add(defines.events.on_marked_for_deconstruction, function(event)
-- Check which type of decon a player is allowed
local index = event.player_index
if chache[index] == nil then
local player = Game.get_player_by_index(index)
local player = game.players[index]
if Roles.player_allowed(player, 'fast-tree-decon') then chache[index] = 'fast'
elseif Roles.player_allowed(player, 'standard-decon') then chache[index] = 'standard'
else chache[index] = player.force end

View File

@@ -11,10 +11,13 @@ require 'config.expcore.command_role_parse'
-- @command clear-inventory
-- @tparam LuaPlayer player the player to clear the inventory of
Commands.new_command('clear-inventory', 'Clears a players inventory')
:add_param('player', false, 'player-role-alive')
:add_param('player', false, 'player-role')
:add_alias('clear-inv', 'move-inventory', 'move-inv')
:register(function(_, player)
local inv = player.get_main_inventory()
if not inv then
return Commands.error{'expcore-commands.reject-player-alive'}
end
move_items(inv.get_contents())
inv.clear()
end)

View File

@@ -8,7 +8,6 @@
local Gui = require 'expcore.gui' --- @dep expcore.gui
local Roles = require 'expcore.roles' --- @dep expcore.roles
local Datastore = require 'expcore.datastore' --- @dep expcore.datastore
local Game = require 'utils.game' --- @dep utils.game
local Event = require 'utils.event' --- @dep utils.event
local config = require 'config.gui.player_list_actions' --- @dep config.gui.player_list_actions
local Colors = require 'utils.color_presets' --- @dep utils.color_presets
@@ -115,7 +114,7 @@ Gui.element(function(event_trigger, parent, player_data)
end)
:on_click(function(player, element, event)
local selected_player_name = element.caption
local selected_player = Game.get_player_from_any(selected_player_name)
local selected_player = game.players[selected_player_name]
if event.button == defines.mouse_button_type.left then
-- LMB will open the map to the selected player
local position = selected_player.position
@@ -177,7 +176,7 @@ local function update_action_bar(element)
element.visible = false
else
local selected_player = Game.get_player_from_any(selected_player_name)
local selected_player = game.players[selected_player_name]
if not selected_player.connected then
-- If the player is offline then reest stores
element.visible = false
@@ -357,7 +356,7 @@ end)
--- When a player leaves only remove they entry
Event.add(defines.events.on_player_left_game, function(event)
local remove_player = Game.get_player_by_index(event.player_index)
local remove_player = game.players[event.player_index]
for _, player in pairs(game.connected_players) do
local frame = Gui.get_left_element(player, player_list_container)
local scroll_table = frame.container.scroll.table
@@ -390,7 +389,7 @@ Event.add(Roles.events.on_role_unassigned, redraw_player_list)
--- When the action player is changed the action bar will update
SelectedPlayer:on_update(function(player_name, selected_player)
local player = Game.get_player_from_any(player_name)
local player = game.players[player_name]
local frame = Gui.get_left_element(player, player_list_container)
local scroll_table = frame.container.scroll.table
update_action_bar(frame.container.action_bar)
@@ -410,13 +409,13 @@ end)
--- When the action name is changed the reason input will update
SelectedAction:on_update(function(player_name, selected_action)
local player = Game.get_player_from_any(player_name)
local player = game.players[player_name]
local frame = Gui.get_left_element(player, player_list_container)
local element = frame.container.reason_bar
if selected_action then
-- if there is a new value then check the player is still online
local selected_player_name = SelectedPlayer:get(player_name)
local selected_player = Game.get_player_from_any(selected_player_name)
local selected_player = game.players[selected_player_name]
if selected_player.connected then
element.visible = true
else

View File

@@ -78,7 +78,8 @@ Gui.element{
-- @element join_server
local join_server =
Gui.element(function(event_trigger, parent, server_id, wrong_version)
local status = wrong_version and 'Version' or External.get_server_status(server_id) or 'Offline'
local status = External.get_server_status(server_id) or 'Offline'
if wrong_version then status = 'Version' end
local flow = parent.add{ name = server_id, type = 'flow' }
local button = flow.add{
name = event_trigger,
@@ -88,7 +89,7 @@ Gui.element(function(event_trigger, parent, server_id, wrong_version)
tooltip = {'readme.servers-connect-'..status, wrong_version}
}
if status == 'Offline' then
if status == 'Offline' or status == 'Current' then
button.enabled = false
button.sprite = 'utility/circuit_network_panel_black'
elseif status == 'Version' then

View File

@@ -1,64 +1,39 @@
local Global = require 'utils.global' --- @dep utils.global
local Color = require 'utils.color_presets' --- @dep utils.color_presets
local pairs = pairs
local Color = require 'utils.color_presets' --- @dep utils.color_presets
local Game = {}
local bad_name_players = {}
Global.register(
bad_name_players,
function(tbl)
bad_name_players = tbl
end
)
--[[ Note to readers
Game.get_player_from_name was removed because game.players[name] works without any edge cases
always true: game.players[name].name == name
Game.get_player_by_index was added originally as a workaround for the following edge case:
player with index of 5 and name of "Cooldude2606"
player with index of 10 and name of "5"
game.players[5].name == "5"
Discovered the following logic:
all keys are first converted to string and search against player names
if this fails it attempts to convert it to a number and search against player indexes
sometimes fails: game.players[index].index == index
Game.get_player_by_index was removed after the above logic was corrected to the following:
when a key is a number it is searched against player indexes, and only their indexes
when a key is a string it is searched against player names, and then against their indexes
always true: game.players[name].name == name; game.players[index].index == index
--[[
Due to a bug in the Factorio api the following expression isn't guaranteed to be true.
game.players[player.index] == player
get_player_by_index(index) will always return the correct player.
When looking up players by name or iterating through all players use game.players instead.
]]
function Game.get_player_by_index(index)
local p = game.players[index]
if not p then
return nil
end
if p.index == index then
return p
end
p = bad_name_players[index]
if p then
if p.valid then
return p
else
return nil
end
end
for k, v in pairs(game.players) do
if k == index then
bad_name_players[index] = v
return v
end
end
end
--- Returns a valid LuaPlayer if given a number, string, or LuaPlayer. Returns nil otherwise.
-- obj <number|string|LuaPlayer>
function Game.get_player_from_any(obj)
local o_type = type(obj)
local p
if o_type == 'number' then
p = Game.get_player_by_index(obj)
elseif o_type == 'string' then
local o_type, p = type(obj)
if o_type == 'table' then
p = obj
elseif o_type == 'string' or o_type == 'number' then
p = game.players[obj]
elseif o_type == 'table' and obj.valid and obj.is_player() then
return obj
end
if p and p.valid then
if p and p.valid and p.is_player() then
return p
end
end
@@ -95,16 +70,18 @@ function Game.print_floating_text(surface, position, text, color)
end
--[[
Creates a floating text entity at the player location with the specified color in {r, g, b} format.
Creates a floating text entity at the player location with the specified color and offset.
Example: "+10 iron" or "-10 coins"
@param text String to display
@param color table in {r = 0~1, g = 0~1, b = 0~1}, defaults to white.
@param x_offset number the x offset for the floating text
@param y_offset number the y offset for the floating text
@return the created entity
]]
function Game.print_player_floating_text_position(player_index, text, color, x_offset, y_offset)
local player = Game.get_player_by_index(player_index)
function Game.print_player_floating_text_position(player, text, color, x_offset, y_offset)
player = Game.get_player_from_any(player)
if not player or not player.valid then
return
end
@@ -113,8 +90,17 @@ function Game.print_player_floating_text_position(player_index, text, color, x_o
return Game.print_floating_text(player.surface, {x = position.x + x_offset, y = position.y + y_offset}, text, color)
end
function Game.print_player_floating_text(player_index, text, color)
Game.print_player_floating_text_position(player_index, text, color, 0, -1.5)
--[[
Creates a floating text entity at the player location with the specified color in {r, g, b} format.
Example: "+10 iron" or "-10 coins"
@param text String to display
@param color table in {r = 0~1, g = 0~1, b = 0~1}, defaults to white.
@return the created entity
]]
function Game.print_player_floating_text(player, text, color)
Game.print_player_floating_text_position(player, text, color, 0, -1.5)
end
return Game
return Game