mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Update all code styles
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
--- Stores if you use alt mode or not and auto applies it
|
||||
-- @data Alt-View
|
||||
|
||||
local Event = require("modules/exp_legacy/utils/event") ---@dep utils.event
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
|
||||
--- Stores the visible state of alt mode
|
||||
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
|
||||
local UsesAlt = PlayerData.Settings:combine('UsesAlt')
|
||||
local UsesAlt = PlayerData.Settings:combine("UsesAlt")
|
||||
UsesAlt:set_default(false)
|
||||
UsesAlt:set_metadata{
|
||||
stringify = function(value) return value and 'Visible' or 'Hidden' end
|
||||
stringify = function(value) return value and "Visible" or "Hidden" end,
|
||||
}
|
||||
|
||||
--- When your data loads apply alt view if you have it enabled
|
||||
@@ -21,4 +21,4 @@ end)
|
||||
Event.add(defines.events.on_player_toggled_alt_mode, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
UsesAlt:set(player, player.game_view_settings.show_entity_info)
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -11,17 +11,17 @@ require("modules.exp_legacy.config.expcore.command_general_parse")
|
||||
|
||||
-- Stores the bonus for the player
|
||||
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
|
||||
local PlayerBonus = PlayerData.Settings:combine('Bonus')
|
||||
local PlayerBonus = PlayerData.Settings:combine("Bonus")
|
||||
PlayerBonus:set_default(0)
|
||||
PlayerBonus:set_metadata{
|
||||
permission = 'command/bonus',
|
||||
permission = "command/bonus",
|
||||
stringify = function(value)
|
||||
if not value or value == 0 then
|
||||
return 'None set'
|
||||
return "None set"
|
||||
end
|
||||
|
||||
return value
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
--- Apply a bonus to a player
|
||||
@@ -34,7 +34,7 @@ local function apply_bonus(player, stage)
|
||||
player[k] = v.value * stage / 10
|
||||
|
||||
if v.combined_bonus then
|
||||
for i=1, #v.combined_bonus, 1 do
|
||||
for i = 1, #v.combined_bonus, 1 do
|
||||
player[v.combined_bonus[i]] = v.value * stage / 10
|
||||
end
|
||||
end
|
||||
@@ -49,18 +49,18 @@ end)
|
||||
--- Changes the amount of bonus you receive
|
||||
-- @command bonus
|
||||
-- @tparam number amount range 0-10 the increase for your bonus
|
||||
Commands.new_command('bonus', {'expcom-bonus.description'}, 'Changes the amount of bonus you receive')
|
||||
:add_param('amount', 'integer-range', 0, 10)
|
||||
:register(function(player, amount)
|
||||
if not Roles.player_allowed(player, 'command/bonus') then
|
||||
Commands.print{'expcom-bonus.perm', 1}
|
||||
return
|
||||
end
|
||||
Commands.new_command("bonus", "Changes the amount of bonus you receive")
|
||||
:add_param("amount", "integer-range", 0, 10)
|
||||
:register(function(player, amount)
|
||||
if not Roles.player_allowed(player, "command/bonus") then
|
||||
Commands.print{ "expcom-bonus.perm", 1 }
|
||||
return
|
||||
end
|
||||
|
||||
PlayerBonus:set(player, amount)
|
||||
PlayerBonus:set(player, amount)
|
||||
|
||||
Commands.print{'expcom-bonus.set', amount}
|
||||
end)
|
||||
Commands.print{ "expcom-bonus.set", amount }
|
||||
end)
|
||||
|
||||
--- When a player respawns re-apply bonus
|
||||
Event.add(defines.events.on_player_respawned, function(event)
|
||||
@@ -71,7 +71,7 @@ end)
|
||||
--- Remove bonus if a player no longer has access to the command
|
||||
local function role_update(event)
|
||||
local player = game.players[event.player_index]
|
||||
if not Roles.player_allowed(player, 'command/bonus') then
|
||||
if not Roles.player_allowed(player, "command/bonus") then
|
||||
apply_bonus(player, 0)
|
||||
end
|
||||
end
|
||||
@@ -80,7 +80,7 @@ end
|
||||
Event.add(defines.events.on_player_died, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
if Roles.player_has_flag(player, 'instant-respawn') then
|
||||
if Roles.player_has_flag(player, "instant-respawn") then
|
||||
player.ticks_to_respawn = 120
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
-- @data Greetings
|
||||
|
||||
local config = require("modules.exp_legacy.config.join_messages") --- @dep config.join_messages
|
||||
local Commands = require("modules.exp_legacy.expcore.commands") ---@dep expcore.commands
|
||||
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
|
||||
require("modules.exp_legacy.config.expcore.command_general_parse")
|
||||
|
||||
--- Stores the join message that the player have
|
||||
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
|
||||
local CustomMessages = PlayerData.Settings:combine('JoinMessage')
|
||||
local CustomMessages = PlayerData.Settings:combine("JoinMessage")
|
||||
CustomMessages:set_metadata{
|
||||
permission = 'command/join-message'
|
||||
permission = "command/join-message",
|
||||
}
|
||||
|
||||
--- When a players data loads show their message
|
||||
@@ -19,25 +19,25 @@ CustomMessages:on_load(function(player_name, player_message)
|
||||
if custom_message then
|
||||
game.print(custom_message, player.color)
|
||||
else
|
||||
player.print{'join-message.greet', {'links.discord'}}
|
||||
player.print{ "join-message.greet", { "links.discord" } }
|
||||
end
|
||||
end)
|
||||
|
||||
--- Set your custom join message
|
||||
-- @command join-message
|
||||
-- @tparam string message The custom join message that will be used
|
||||
Commands.new_command('join-message', 'Sets your custom join message')
|
||||
:add_param('message', false, 'string-max-length', 255)
|
||||
:enable_auto_concat()
|
||||
:register(function(player, message)
|
||||
if not player then return end
|
||||
CustomMessages:set(player, message)
|
||||
return {'join-message.message-set'}
|
||||
end)
|
||||
Commands.new_command("join-message", "Sets your custom join message")
|
||||
:add_param("message", false, "string-max-length", 255)
|
||||
:enable_auto_concat()
|
||||
:register(function(player, message)
|
||||
if not player then return end
|
||||
CustomMessages:set(player, message)
|
||||
return { "join-message.message-set" }
|
||||
end)
|
||||
|
||||
Commands.new_command('join-message-clear', 'Clear your join message')
|
||||
:register(function(player)
|
||||
if not player then return end
|
||||
CustomMessages:remove(player)
|
||||
return {'join-message.message-cleared'}
|
||||
end)
|
||||
Commands.new_command("join-message-clear", "Clear your join message")
|
||||
:register(function(player)
|
||||
if not player then return end
|
||||
CustomMessages:remove(player)
|
||||
return { "join-message.message-cleared" }
|
||||
end)
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
--- Stores the language used to join the server
|
||||
-- @data Language
|
||||
|
||||
local Event = require("modules/exp_legacy/utils/event") ---@dep utils.event
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
|
||||
local LocalLanguage = PlayerData.Statistics:combine('LocalLanguage')
|
||||
local LocalLanguage = PlayerData.Statistics:combine("LocalLanguage")
|
||||
LocalLanguage:set_default("Unknown")
|
||||
|
||||
--- Creates translation request on_load of a player
|
||||
LocalLanguage:on_load(function(player_name, _)
|
||||
local player = game.players[player_name]
|
||||
player.request_translation({"language.local-language"})
|
||||
player.request_translation{ "language.local-language" }
|
||||
end)
|
||||
|
||||
--- Resolves translation request for language setting
|
||||
@@ -31,4 +31,4 @@ Event.add(defines.events.on_string_translated, function(event)
|
||||
-- Change LocalLanguage value for the player to the recognized one
|
||||
local language = event.result
|
||||
LocalLanguage:set(player, language)
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -1,26 +1,22 @@
|
||||
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
|
||||
local config = require("modules.exp_legacy.config.personal_logistic") --- @dep config.personal-logistic
|
||||
|
||||
local pl = {}
|
||||
|
||||
function pl.pl(type, target, amount)
|
||||
local function pl(type, target, amount)
|
||||
local c
|
||||
local s
|
||||
|
||||
if type == 'p' then
|
||||
if type == "p" then
|
||||
c = target.clear_personal_logistic_slot
|
||||
s = target.set_personal_logistic_slot
|
||||
|
||||
elseif type == 's' then
|
||||
elseif type == "s" then
|
||||
c = target.clear_vehicle_logistic_slot
|
||||
s = target.set_vehicle_logistic_slot
|
||||
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
for _, v in pairs(config.request) do
|
||||
c(v.key)
|
||||
c(config.start + v.key)
|
||||
end
|
||||
|
||||
if (amount < 0) then
|
||||
@@ -33,65 +29,58 @@ function pl.pl(type, target, amount)
|
||||
local v_min = math.ceil(v.min * amount)
|
||||
local v_max = math.ceil(v.max * amount)
|
||||
|
||||
if v.stack and v.stack ~= 1 and v.type ~= 'weapon' then
|
||||
if v.stack ~= nil and v.stack ~= 1 and v.type ~= "weapon" then
|
||||
v_min = math.floor(v_min / v.stack) * v.stack
|
||||
v_max = math.ceil(v_max / v.stack) * v.stack
|
||||
end
|
||||
|
||||
if v.upgrade_of == nil then
|
||||
if v.type then
|
||||
if v.type ~= nil then
|
||||
if stats.get_input_count(k) < config.production_required[v.type] then
|
||||
if v_min > 0 then
|
||||
if v_min == v_max then
|
||||
v_min = math.floor((v_max * 0.5) / v.stack) * v.stack
|
||||
end
|
||||
|
||||
else
|
||||
v_min = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
s(v.key, {name=k, min=v_min, max=v_max})
|
||||
|
||||
s(config.start + v.key, { name = k, min = v_min, max = v_max })
|
||||
else
|
||||
if v.type then
|
||||
if v.type ~= nil then
|
||||
if stats.get_input_count(k) >= config.production_required[v.type] then
|
||||
s(v.key, {name=k, min=v_min, max=v_max})
|
||||
s(config.start + v.key, { name = k, min = v_min, max = v_max })
|
||||
local vuo = v.upgrade_of
|
||||
|
||||
while vuo do
|
||||
s(config.request[vuo].key, {name=vuo, min=0, max=0})
|
||||
while (vuo ~= nil) do
|
||||
s(config.start + config.request[vuo].key, { name = vuo, min = 0, max = 0 })
|
||||
vuo = config.request[vuo].upgrade_of
|
||||
end
|
||||
|
||||
else
|
||||
s(v.key, {name=k, min=0, max=v_max})
|
||||
s(config.start + v.key, { name = k, min = 0, max = v_max })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Commands.new_command('personal-logistic', {'expcom-personal-logistics'}, 'Set Personal Logistic (-1 to cancel all) (Select spidertron to edit spidertron)')
|
||||
:add_param('amount', 'integer-range', -1, 10)
|
||||
:add_alias('pl')
|
||||
:register(function(player, amount)
|
||||
if player.force.technologies['logistic-robotics'].researched then
|
||||
if player.selected then
|
||||
if player.selected.name == 'spidertron' then
|
||||
pl.pl('s', player.selected, amount / 10)
|
||||
Commands.new_command("personal-logistic", "Set Personal Logistic (-1 to cancel all) (Select spidertron to edit spidertron)")
|
||||
:add_param("amount", "integer-range", -1, 10)
|
||||
:add_alias("pl")
|
||||
:register(function(player, amount)
|
||||
if player.force.technologies["logistic-robotics"].researched then
|
||||
if player.selected ~= nil then
|
||||
if player.selected.name == "spidertron" then
|
||||
pl("s", player.selected, amount / 10)
|
||||
return Commands.success
|
||||
end
|
||||
else
|
||||
pl("p", player, amount / 10)
|
||||
return Commands.success
|
||||
end
|
||||
|
||||
else
|
||||
pl.pl('p', player, amount / 10)
|
||||
return Commands.success
|
||||
player.print("Personal Logistic not researched")
|
||||
end
|
||||
|
||||
else
|
||||
player.print('Personal Logistic not researched')
|
||||
end
|
||||
end)
|
||||
|
||||
return pl
|
||||
end)
|
||||
|
||||
@@ -7,13 +7,13 @@ local config = require("modules.exp_legacy.config.preset_player_colours") --- @d
|
||||
|
||||
--- Stores the colour that the player wants
|
||||
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
|
||||
local PlayerColours = PlayerData.Settings:combine('Colour')
|
||||
local PlayerColours = PlayerData.Settings:combine("Colour")
|
||||
PlayerColours:set_metadata{
|
||||
stringify = function(value)
|
||||
if not value then return 'None set' end
|
||||
if not value then return "None set" end
|
||||
local c = value[1]
|
||||
return string.format('Red: %d Green: %d Blue: %d', c[1], c[2], c[3])
|
||||
end
|
||||
return string.format("Red: %d Green: %d Blue: %d", c[1], c[2], c[3])
|
||||
end,
|
||||
}
|
||||
|
||||
--- Used to compact player colours to take less space
|
||||
@@ -22,13 +22,13 @@ local function compact(colour)
|
||||
return {
|
||||
floor(colour.r * 255),
|
||||
floor(colour.g * 255),
|
||||
floor(colour.b * 255)
|
||||
floor(colour.b * 255),
|
||||
}
|
||||
end
|
||||
|
||||
--- Returns a colour that is a bit lighter than the one given
|
||||
local function lighten(c)
|
||||
return {r = 255 - (255 - c.r) * 0.5, g = 255 - (255 - c.g) * 0.5, b = 255 - (255 - c.b) * 0.5, a = 255}
|
||||
return { r = 255 - (255 - c.r) * 0.5, g = 255 - (255 - c.g) * 0.5, b = 255 - (255 - c.b) * 0.5, a = 255 }
|
||||
end
|
||||
|
||||
--- When your data loads apply the players colour, or a random on if none is saved
|
||||
@@ -36,13 +36,14 @@ PlayerColours:on_load(function(player_name, player_colour)
|
||||
if not player_colour then
|
||||
local preset = config.players[player_name]
|
||||
if preset then
|
||||
player_colour = {preset, lighten(preset)}
|
||||
player_colour = { preset, lighten(preset) }
|
||||
else
|
||||
local colour_name = 'white'
|
||||
local colour_name = "white"
|
||||
while config.disallow[colour_name] do
|
||||
colour_name = table.get_random_dictionary_entry(Colours, true)
|
||||
end
|
||||
player_colour = {Colours[colour_name], lighten(Colours[colour_name])}
|
||||
|
||||
player_colour = { Colours[colour_name], lighten(Colours[colour_name]) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -53,10 +54,10 @@ end)
|
||||
|
||||
--- Save the players color when they use the color command
|
||||
Event.add(defines.events.on_console_command, function(event)
|
||||
if event.command ~= 'color' then return end
|
||||
if event.parameters == '' then return end
|
||||
if event.command ~= "color" then return end
|
||||
if event.parameters == "" then return end
|
||||
if not event.player_index then return end
|
||||
local player = game.players[event.player_index]
|
||||
if not player or not player.valid then return end
|
||||
PlayerColours:set(player, {compact(player.color), compact(player.chat_color)})
|
||||
end)
|
||||
PlayerColours:set(player, { compact(player.color), compact(player.chat_color) })
|
||||
end)
|
||||
|
||||
@@ -8,15 +8,16 @@ local config = require("modules.exp_legacy.config.preset_player_quickbar") --- @
|
||||
|
||||
--- Stores the quickbar filters for a player
|
||||
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
|
||||
local PlayerFilters = PlayerData.Settings:combine('QuickbarFilters')
|
||||
local PlayerFilters = PlayerData.Settings:combine("QuickbarFilters")
|
||||
PlayerFilters:set_metadata{
|
||||
permission = 'command/save-quickbar',
|
||||
permission = "command/save-quickbar",
|
||||
stringify = function(value)
|
||||
if not value then return 'No filters set' end
|
||||
if not value then return "No filters set" end
|
||||
local count = 0
|
||||
for _ in pairs(value) do count = count + 1 end
|
||||
return count..' filters set'
|
||||
end
|
||||
|
||||
return count .. " filters set"
|
||||
end,
|
||||
}
|
||||
|
||||
--- Loads your quickbar preset
|
||||
@@ -25,7 +26,7 @@ PlayerFilters:on_load(function(player_name, filters)
|
||||
if not filters then return end
|
||||
local player = game.players[player_name]
|
||||
for i, item_name in pairs(filters) do
|
||||
if item_name ~= nil and item_name ~= '' then
|
||||
if item_name ~= nil and item_name ~= "" then
|
||||
player.set_quick_bar_slot(i, item_name)
|
||||
end
|
||||
end
|
||||
@@ -36,32 +37,32 @@ local ignoredItems = {
|
||||
["blueprint-book"] = true,
|
||||
["deconstruction-planner"] = true,
|
||||
["spidertron-remote"] = true,
|
||||
["upgrade-planner"] = true
|
||||
["upgrade-planner"] = true,
|
||||
}
|
||||
|
||||
--- Saves your quickbar preset to the script-output folder
|
||||
-- @command save-quickbar
|
||||
Commands.new_command('save-quickbar', 'Saves your Quickbar preset items to file')
|
||||
:add_alias('save-toolbar')
|
||||
:register(function(player)
|
||||
local filters = {}
|
||||
Commands.new_command("save-quickbar", "Saves your Quickbar preset items to file")
|
||||
:add_alias("save-toolbar")
|
||||
:register(function(player)
|
||||
local filters = {}
|
||||
|
||||
for i = 1, 100 do
|
||||
local slot = player.get_quick_bar_slot(i)
|
||||
-- Need to filter out blueprint and blueprint books because the slot is a LuaItemPrototype and does not contain a way to export blueprint data
|
||||
if slot ~= nil then
|
||||
local ignored = ignoredItems[slot.name]
|
||||
if ignored ~= true then
|
||||
filters[i] = slot.name
|
||||
for i = 1, 100 do
|
||||
local slot = player.get_quick_bar_slot(i)
|
||||
-- Need to filter out blueprint and blueprint books because the slot is a LuaItemPrototype and does not contain a way to export blueprint data
|
||||
if slot ~= nil then
|
||||
local ignored = ignoredItems[slot.name]
|
||||
if ignored ~= true then
|
||||
filters[i] = slot.name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if next(filters) then
|
||||
PlayerFilters:set(player, filters)
|
||||
else
|
||||
PlayerFilters:remove(player)
|
||||
end
|
||||
if next(filters) then
|
||||
PlayerFilters:set(player, filters)
|
||||
else
|
||||
PlayerFilters:remove(player)
|
||||
end
|
||||
|
||||
return {'quickbar.saved'}
|
||||
end)
|
||||
return { "quickbar.saved" }
|
||||
end)
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
|
||||
local Event = require("modules/exp_legacy/utils/event") ---@dep utils.event
|
||||
local Storage = require("modules/exp_util/storage") ---@dep utils.global
|
||||
local config = require("modules.exp_legacy.config.statistics") ---@dep config.statistics
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local Storage = require("modules/exp_util/storage") --- @dep utils.global
|
||||
local config = require("modules.exp_legacy.config.statistics") --- @dep config.statistics
|
||||
local format_time = _C.format_time
|
||||
local floor = math.floor
|
||||
local afk_required = 5*3600 -- 5 minutes
|
||||
local afk_required = 5 * 3600 -- 5 minutes
|
||||
|
||||
--- Stores players who have been created, required to avoid loss of data
|
||||
local new_players = {}
|
||||
@@ -17,7 +16,7 @@ local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep ex
|
||||
local AllPlayerData = PlayerData.All
|
||||
local Statistics = PlayerData.Statistics
|
||||
Statistics:set_metadata{
|
||||
display_order = config.display_order
|
||||
display_order = config.display_order,
|
||||
}
|
||||
|
||||
--- Update your statistics with any which happened before the data was valid
|
||||
@@ -49,27 +48,27 @@ end)
|
||||
|
||||
--- Used to format time in minute format
|
||||
local function format_minutes(value)
|
||||
return format_time(value*3600, {
|
||||
return format_time(value * 3600, {
|
||||
long = true,
|
||||
hours = true,
|
||||
minutes = true
|
||||
minutes = true,
|
||||
})
|
||||
end
|
||||
|
||||
--- Used to format time into a clock
|
||||
local function format_clock(value)
|
||||
return format_time(value*3600, {
|
||||
hours=true,
|
||||
minutes=true,
|
||||
seconds=false,
|
||||
time=false,
|
||||
string=true
|
||||
return format_time(value * 3600, {
|
||||
hours = true,
|
||||
minutes = true,
|
||||
seconds = false,
|
||||
time = false,
|
||||
string = true,
|
||||
})
|
||||
end
|
||||
|
||||
--- Add MapsPlayed if it is enabled
|
||||
if config.MapsPlayed then
|
||||
Statistics:combine('MapsPlayed')
|
||||
Statistics:combine("MapsPlayed")
|
||||
Event.add(defines.events.on_player_created, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
new_players[player.name] = true
|
||||
@@ -79,8 +78,14 @@ end
|
||||
--- Add Playtime and AfkTime if it is enabled
|
||||
if config.Playtime or config.AfkTime then
|
||||
local playtime, afk_time
|
||||
if config.Playtime then playtime = Statistics:combine('Playtime') playtime:set_metadata{stringify=format_minutes, stringify_short=format_clock} end
|
||||
if config.AfkTime then afk_time = Statistics:combine('AfkTime') afk_time:set_metadata{stringify=format_minutes, stringify_short=format_clock} end
|
||||
if config.Playtime then
|
||||
playtime = Statistics:combine("Playtime")
|
||||
playtime:set_metadata{ stringify = format_minutes, stringify_short = format_clock }
|
||||
end
|
||||
if config.AfkTime then
|
||||
afk_time = Statistics:combine("AfkTime")
|
||||
afk_time:set_metadata{ stringify = format_minutes, stringify_short = format_clock }
|
||||
end
|
||||
Event.on_nth_tick(3600, function()
|
||||
if game.tick == 0 then return end
|
||||
for _, player in pairs(game.connected_players) do
|
||||
@@ -92,8 +97,8 @@ end
|
||||
|
||||
--- Add DistanceTravelled if it is enabled
|
||||
if config.DistanceTravelled then
|
||||
local stat = Statistics:combine('DistanceTravelled')
|
||||
stat:set_metadata{unit=' tiles'}
|
||||
local stat = Statistics:combine("DistanceTravelled")
|
||||
stat:set_metadata{ unit = " tiles" }
|
||||
Event.add(defines.events.on_player_changed_position, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
if not player.valid or not player.connected or player.afk_time > afk_required then return end
|
||||
@@ -104,18 +109,22 @@ end
|
||||
--- Add MachinesRemoved and TreesDestroyed and config.OreMined if it is enabled
|
||||
if config.MachinesRemoved or config.TreesDestroyed or config.OreMined then
|
||||
local machines, trees, ore
|
||||
if config.MachinesRemoved then machines = Statistics:combine('MachinesRemoved') end
|
||||
if config.TreesDestroyed then trees = Statistics:combine('TreesDestroyed') end
|
||||
if config.OreMined then ore = Statistics:combine('OreMined') end
|
||||
if config.MachinesRemoved then machines = Statistics:combine("MachinesRemoved") end
|
||||
if config.TreesDestroyed then trees = Statistics:combine("TreesDestroyed") end
|
||||
if config.OreMined then ore = Statistics:combine("OreMined") end
|
||||
local function on_event(event)
|
||||
if not event.player_index then return end -- Check player is valid
|
||||
if not event.player_index then return end -- Check player is valid
|
||||
local player = game.players[event.player_index]
|
||||
if not player.valid or not player.connected then return end
|
||||
local entity = event.entity -- Check entity is valid
|
||||
if not entity.valid then return end
|
||||
if entity.type == 'resource' then ore:increment(player)
|
||||
elseif entity.type == 'tree' then trees:increment(player)
|
||||
elseif entity.force == player.force then machines:increment(player) end
|
||||
if entity.type == "resource" then
|
||||
ore:increment(player)
|
||||
elseif entity.type == "tree" then
|
||||
trees:increment(player)
|
||||
elseif entity.force == player.force then
|
||||
machines:increment(player)
|
||||
end
|
||||
end
|
||||
Event.add(defines.events.on_marked_for_deconstruction, on_event)
|
||||
Event.add(defines.events.on_player_mined_entity, on_event)
|
||||
@@ -123,35 +132,35 @@ end
|
||||
|
||||
--- Add DamageDealt if it is enabled
|
||||
if config.DamageDealt then
|
||||
local stat = Statistics:combine('DamageDealt')
|
||||
local stat = Statistics:combine("DamageDealt")
|
||||
Event.add(defines.events.on_entity_damaged, function(event)
|
||||
local character = event.cause -- Check character is valid
|
||||
if not character or not character.valid or character.type ~= 'character' then return end
|
||||
if not character or not character.valid or character.type ~= "character" then return end
|
||||
local player = character.player -- Check player is valid
|
||||
if not player.valid or not player.connected then return end
|
||||
local entity = event.entity -- Check entity is valid
|
||||
if not entity.valid or entity.force == player.force or entity.force.name == 'neutral' then return end
|
||||
if not entity.valid or entity.force == player.force or entity.force.name == "neutral" then return end
|
||||
stat:increment(player, floor(event.final_damage_amount))
|
||||
end)
|
||||
end
|
||||
|
||||
--- Add Kills if it is enabled
|
||||
if config.Kills then
|
||||
local stat = Statistics:combine('Kills')
|
||||
local stat = Statistics:combine("Kills")
|
||||
Event.add(defines.events.on_entity_died, function(event)
|
||||
local character = event.cause -- Check character is valid
|
||||
if not character or not character.valid or character.type ~= 'character' then return end
|
||||
if not character or not character.valid or character.type ~= "character" then return end
|
||||
local player = character.player -- Check player is valid
|
||||
if not player or not player.valid or not player.connected then return end
|
||||
local entity = event.entity -- Check entity is valid
|
||||
if not entity.valid or entity.force == player.force or entity.force.name == 'neutral' then return end
|
||||
if not entity.valid or entity.force == player.force or entity.force.name == "neutral" then return end
|
||||
stat:increment(player)
|
||||
end)
|
||||
end
|
||||
|
||||
--- Add RocketsLaunched if it is enabled
|
||||
if config.RocketsLaunched then
|
||||
local stat = Statistics:combine('RocketsLaunched')
|
||||
local stat = Statistics:combine("RocketsLaunched")
|
||||
Event.add(defines.events.on_rocket_launched, function(event)
|
||||
local silo = event.rocket_silo -- Check silo is valid
|
||||
if not silo or not silo.valid then return end
|
||||
@@ -165,9 +174,9 @@ end
|
||||
|
||||
--- Add RocketsLaunched if it is enabled
|
||||
if config.ResearchCompleted then
|
||||
local stat = Statistics:combine('ResearchCompleted')
|
||||
local stat = Statistics:combine("ResearchCompleted")
|
||||
Event.add(defines.events.on_research_finished, function(event)
|
||||
local research = event.research -- Check research is valid
|
||||
local research = event.research -- Check research is valid
|
||||
if event.by_script or not research or not research.valid then return end
|
||||
local force = research.force -- Check force is valid
|
||||
if not force or not force.valid then return end
|
||||
|
||||
@@ -11,22 +11,22 @@ require("modules.exp_legacy.config.expcore.command_color_parse")
|
||||
|
||||
--- Stores the tag for a player
|
||||
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
|
||||
local PlayerTags = PlayerData.Settings:combine('Tag')
|
||||
local PlayerTagColors = PlayerData.Settings:combine('TagColor')
|
||||
local PlayerTags = PlayerData.Settings:combine("Tag")
|
||||
local PlayerTagColors = PlayerData.Settings:combine("TagColor")
|
||||
PlayerTags:set_metadata{
|
||||
permission = 'command/tag'
|
||||
permission = "command/tag",
|
||||
}
|
||||
PlayerTagColors:set_metadata{
|
||||
permission = 'command/tag-color'
|
||||
permission = "command/tag-color",
|
||||
}
|
||||
|
||||
local set_tag = function (player, tag, color)
|
||||
if tag == nil or tag == '' then
|
||||
player.tag = ''
|
||||
local set_tag = function(player, tag, color)
|
||||
if tag == nil or tag == "" then
|
||||
player.tag = ""
|
||||
elseif color then
|
||||
player.tag = '- [color='.. color ..']'..tag..'[/color]'
|
||||
player.tag = "- [color=" .. color .. "]" .. tag .. "[/color]"
|
||||
else
|
||||
player.tag = '- '..tag
|
||||
player.tag = "- " .. tag
|
||||
end
|
||||
end
|
||||
|
||||
@@ -49,40 +49,40 @@ end)
|
||||
--- Sets your player tag.
|
||||
-- @command tag
|
||||
-- @tparam string tag the tag that will be after the name, there is a max length
|
||||
Commands.new_command('tag', 'Sets your player tag.')
|
||||
:add_param('tag', false, 'string-max-length', 20)
|
||||
:enable_auto_concat()
|
||||
:register(function(player, tag)
|
||||
PlayerTags:set(player, tag)
|
||||
end)
|
||||
Commands.new_command("tag", "Sets your player tag.")
|
||||
:add_param("tag", false, "string-max-length", 20)
|
||||
:enable_auto_concat()
|
||||
:register(function(player, tag)
|
||||
PlayerTags:set(player, tag)
|
||||
end)
|
||||
|
||||
--- Sets your player tag color.
|
||||
-- @command tag
|
||||
-- @tparam string color name.
|
||||
Commands.new_command('tag-color', 'Sets your player tag color.')
|
||||
:add_param('color', false, 'color')
|
||||
:enable_auto_concat()
|
||||
:register(function(player, color)
|
||||
PlayerTagColors:set(player, color)
|
||||
end)
|
||||
Commands.new_command("tag-color", "Sets your player tag color.")
|
||||
:add_param("color", false, "color")
|
||||
:enable_auto_concat()
|
||||
:register(function(player, color)
|
||||
PlayerTagColors:set(player, color)
|
||||
end)
|
||||
|
||||
--- Clears your tag. Or another player if you are admin.
|
||||
-- @command tag-clear
|
||||
-- @tparam[opt=self] LuaPlayer player the player to remove the tag from, nil will apply to self
|
||||
Commands.new_command('tag-clear', 'Clears your tag. Or another player if you are admin.')
|
||||
:add_param('player', true, 'player-role')
|
||||
:set_defaults{player=function(player)
|
||||
return player -- default is the user using the command
|
||||
end}
|
||||
:register(function(player, action_player)
|
||||
if action_player.index == player.index then
|
||||
-- no player given so removes your tag
|
||||
PlayerTags:remove(action_player)
|
||||
elseif Roles.player_allowed(player, 'command/clear-tag/always') then
|
||||
-- player given and user is admin so clears that player's tag
|
||||
PlayerTags:remove(action_player)
|
||||
else
|
||||
-- user is not admin and tried to clear another users tag
|
||||
return Commands.error{'expcore-commands.unauthorized'}
|
||||
end
|
||||
end)
|
||||
Commands.new_command("tag-clear", "Clears your tag. Or another player if you are admin.")
|
||||
:add_param("player", true, "player-role")
|
||||
:set_defaults{ player = function(player)
|
||||
return player -- default is the user using the command
|
||||
end }
|
||||
:register(function(player, action_player)
|
||||
if action_player.index == player.index then
|
||||
-- no player given so removes your tag
|
||||
PlayerTags:remove(action_player)
|
||||
elseif Roles.player_allowed(player, "command/clear-tag/always") then
|
||||
-- player given and user is admin so clears that player's tag
|
||||
PlayerTags:remove(action_player)
|
||||
else
|
||||
-- user is not admin and tried to clear another users tag
|
||||
return Commands.error{ "expcore-commands.unauthorized" }
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user