mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 12:31:41 +09:00
Fixed Existing Lua Check Errors
This commit is contained in:
@@ -17,31 +17,31 @@ Event.add(defines.events.on_player_created, function(event)
|
||||
player.force.chart(player.surface, {{p.x-r, p.y-r}, {p.x+r, p.y+r}})
|
||||
end
|
||||
-- spawn items
|
||||
for item,callback in pairs(items) do
|
||||
for item, callback in pairs(items) do
|
||||
if type(callback) == 'function' then
|
||||
local stats = player.force.item_production_statistics
|
||||
local made = stats.get_input_count(item)
|
||||
local success,count = pcall(callback,made,stats.get_input_count,player)
|
||||
local success, count = pcall(callback, made, stats.get_input_count, player)
|
||||
count = math.floor(count)
|
||||
if success and count > 0 then
|
||||
player.insert{name=item,count=count}
|
||||
player.insert{name=item, count=count}
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Event.on_init(function()
|
||||
remote.call('freeplay','set_created_items',{})
|
||||
remote.call('freeplay','set_chart_distance',0)
|
||||
remote.call('freeplay','set_skip_intro',config.skip_intro)
|
||||
remote.call('freeplay', 'set_created_items', {})
|
||||
remote.call('freeplay', 'set_chart_distance', 0)
|
||||
remote.call('freeplay', 'set_skip_intro', config.skip_intro)
|
||||
if config.research_queue_from_start then
|
||||
for _,force in pairs(game.forces) do
|
||||
for _, force in pairs(game.forces) do
|
||||
force.research_queue_enabled = true
|
||||
end
|
||||
end
|
||||
if not config.disable_base_game_silo_script then
|
||||
if config.skip_victory then
|
||||
remote.call('silo_script','set_no_victory',true)
|
||||
remote.call('silo_script', 'set_no_victory', true)
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -8,7 +8,7 @@ local config = require 'config.popup_messages' --- @dep config.popup_messages
|
||||
|
||||
local send_text = Game.print_player_floating_text -- (player_index, text, color)
|
||||
|
||||
Event.add(defines.events.on_console_chat,function(event)
|
||||
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)
|
||||
|
||||
@@ -18,7 +18,7 @@ Event.add(defines.events.on_console_chat,function(event)
|
||||
|
||||
-- Sends the message as text above them
|
||||
if config.show_player_messages then
|
||||
send_text(player.index,{'chat-popup.message',player.name,event.message},player.chat_color)
|
||||
send_text(player.index, {'chat-popup.message', player.name, event.message}, player.chat_color)
|
||||
end
|
||||
|
||||
if not config.show_player_mentions then return end
|
||||
@@ -27,10 +27,10 @@ Event.add(defines.events.on_console_chat,function(event)
|
||||
local search_string = event.message:lower():gsub("%s+", "")
|
||||
|
||||
-- Loops over online players to see if they name is included
|
||||
for _,mentioned_player in pairs(game.connected_players) do
|
||||
for _, mentioned_player in pairs(game.connected_players) do
|
||||
if mentioned_player.index ~= player.index then
|
||||
if search_string:match(mentioned_player.name:lower(), 1, true) then
|
||||
send_text(mentioned_player.index,{'chat-popup.ping',player.name},player.chat_color)
|
||||
send_text(mentioned_player.index, {'chat-popup.ping', player.name}, player.chat_color)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,17 +6,17 @@ 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)
|
||||
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 message = event.message:lower():gsub("%s+", "")
|
||||
local allowed = true
|
||||
if config.command_admin_only and not player.admin then allowed = false end
|
||||
if config.command_permission and not Roles.player_allowed(player,config.command_permission) then allowed = false end
|
||||
if config.command_permission and not Roles.player_allowed(player, config.command_permission) then allowed = false end
|
||||
|
||||
local prefix = config.command_prefix
|
||||
for key_word,reply in pairs(config.messages) do
|
||||
for key_word, reply in pairs(config.messages) do
|
||||
if message:find(key_word) then
|
||||
if type(reply) == 'function' then
|
||||
reply = reply(player)
|
||||
@@ -24,29 +24,29 @@ Event.add(defines.events.on_console_chat,function(event)
|
||||
|
||||
if message:find(prefix..key_word) then
|
||||
if allowed then
|
||||
game.print{'chat-bot.reply',reply}
|
||||
game.print{'chat-bot.reply', reply}
|
||||
else
|
||||
player.print{'chat-bot.disallow'}
|
||||
end
|
||||
elseif not allowed then
|
||||
player.print{'chat-bot.reply',reply}
|
||||
player.print{'chat-bot.reply', reply}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not allowed then return end
|
||||
|
||||
for key_word,reply in pairs(config.commands) do
|
||||
for key_word, reply in pairs(config.commands) do
|
||||
if message:find(prefix..key_word) then
|
||||
if type(reply) == 'function' then
|
||||
reply = reply(player)
|
||||
|
||||
if reply then
|
||||
game.print{'chat-bot.reply',reply}
|
||||
game.print{'chat-bot.reply', reply}
|
||||
end
|
||||
|
||||
else
|
||||
game.print{'chat-bot.reply',reply}
|
||||
game.print{'chat-bot.reply', reply}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -18,7 +18,7 @@ local Public = {
|
||||
Global.register({
|
||||
compilatrons = Public.compilatrons,
|
||||
current_messages = Public.current_messages
|
||||
},function(tbl)
|
||||
}, function(tbl)
|
||||
Public.compilatrons = tbl.compilatrons
|
||||
Public.current_messages = tbl.current_messages
|
||||
end)
|
||||
@@ -42,7 +42,7 @@ local callback =
|
||||
local function circle_messages()
|
||||
for name, ent in pairs(Public.compilatrons) do
|
||||
if not ent.valid then
|
||||
Public.spawn_compilatron(game.players[1].surface,name)
|
||||
Public.spawn_compilatron(game.players[1].surface, name)
|
||||
end
|
||||
local current_message = Public.current_messages[name]
|
||||
local msg_number
|
||||
@@ -66,7 +66,7 @@ Event.on_nth_tick(config.message_cycle, circle_messages)
|
||||
|
||||
--- This will add a compilatron to the global and start his message cycle
|
||||
-- @tparam LuaEntity entity the compilatron entity that moves around
|
||||
-- @tparam string name the name of the location that the complitron is at
|
||||
-- @tparam string name the name of the location that the compilatron is at
|
||||
function Public.add_compilatron(entity, name)
|
||||
if not entity and not entity.valid then
|
||||
return
|
||||
@@ -85,19 +85,19 @@ end
|
||||
--- This spawns a new compilatron on a surface with the given location tag (not a position)
|
||||
-- @tparam LuaSurface surface the surface to spawn the compilatron on
|
||||
-- @tparam string location the location tag that is in the config file
|
||||
function Public.spawn_compilatron(surface,location)
|
||||
function Public.spawn_compilatron(surface, location)
|
||||
local position = locations[location]
|
||||
local pos = surface.find_non_colliding_position('compilatron', position, 1.5, 0.5)
|
||||
local compi = surface.create_entity {name='compilatron',position=pos,force=game.forces.neutral}
|
||||
Public.add_compilatron(compi,location)
|
||||
local compi = surface.create_entity {name='compilatron', position=pos, force=game.forces.neutral}
|
||||
Public.add_compilatron(compi, location)
|
||||
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)
|
||||
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)
|
||||
for location,pos in pairs(locations) do
|
||||
Public.spawn_compilatron(player.surface,location)
|
||||
for location in pairs(locations) do
|
||||
Public.spawn_compilatron(player.surface, location)
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
@@ -12,21 +12,21 @@ Event.add(defines.events.on_entity_damaged, function(event)
|
||||
local damage = math.floor(event.original_damage_amount)
|
||||
local health = math.floor(entity.health)
|
||||
local health_percentage = entity.get_health_ratio()
|
||||
local text_colour = {r=1-health_percentage,g=health_percentage,b=0}
|
||||
local text_colour = {r=1-health_percentage, g=health_percentage, b=0}
|
||||
|
||||
-- Gets the location of the text
|
||||
local size = entity.get_radius()
|
||||
if size < 1 then size = 1 end
|
||||
local r = (math.random()-0.5)*size*config.damage_location_variance
|
||||
local p = entity.position
|
||||
local position = {x=p.x+r,y=p.y-size}
|
||||
local position = {x=p.x+r, y=p.y-size}
|
||||
|
||||
-- Sets the message
|
||||
local message
|
||||
if entity.name == 'character' and config.show_player_health then
|
||||
message = {'damage-popup.player-health',health}
|
||||
message = {'damage-popup.player-health', health}
|
||||
elseif entity.name ~= 'character' and cause and cause.name == 'character' and config.show_player_damage then
|
||||
message = {'damage-popup.player-damage',damage}
|
||||
message = {'damage-popup.player-damage', damage}
|
||||
end
|
||||
|
||||
-- Outputs the message as floating text
|
||||
|
||||
@@ -5,13 +5,13 @@ 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
|
||||
local format_time, move_items = _C.format_time, _C.move_items --- @dep expcore.common
|
||||
|
||||
local deaths = {
|
||||
archive={} -- deaths moved here after body is gone
|
||||
--{player_name='Cooldude2606',time_of_death='15H 15M',position={x=0,y=0},corpse=LuaEntity,tag=LuaCustomChartTag}
|
||||
--{player_name='Cooldude2606', time_of_death='15H 15M', position={x=0, y=0}, corpse=LuaEntity, tag=LuaCustomChartTag}
|
||||
}
|
||||
Global.register(deaths,function(tbl)
|
||||
Global.register(deaths, function(tbl)
|
||||
deaths = tbl
|
||||
end)
|
||||
|
||||
@@ -20,10 +20,10 @@ local function create_map_tag(death)
|
||||
local player = Game.get_player_from_any(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})
|
||||
local time = format_time(death.time_of_death, {hours=true, minutes=true, string=true})
|
||||
message = message..' at '..time
|
||||
end
|
||||
death.tag = player.force.add_chart_tag(player.surface,{
|
||||
death.tag = player.force.add_chart_tag(player.surface, {
|
||||
position=death.position,
|
||||
icon=config.map_icon,
|
||||
text=message
|
||||
@@ -33,7 +33,7 @@ end
|
||||
--- Checks that all map tags are present and valid
|
||||
-- adds missing ones, deletes expired ones
|
||||
local function check_map_tags()
|
||||
for index,death in ipairs(deaths) do
|
||||
for index, death in ipairs(deaths) do
|
||||
local map_tag = death.tag
|
||||
local corpse = death.corpse
|
||||
-- Check the corpse is valid
|
||||
@@ -51,19 +51,19 @@ local function check_map_tags()
|
||||
-- Move the death to the archive
|
||||
death.corpse = nil
|
||||
death.tag = nil
|
||||
table.insert(deaths.archive,death)
|
||||
table.remove(deaths,index)
|
||||
table.insert(deaths.archive, death)
|
||||
table.remove(deaths, index)
|
||||
end
|
||||
end
|
||||
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)
|
||||
Event.add(defines.events.on_player_died, function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local corpse = player.surface.find_entity('character-corpse',player.position)
|
||||
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()
|
||||
local chest = move_items(items,corpse.surface,corpse.position)
|
||||
local chest = move_items(items, corpse.surface, corpse.position)
|
||||
chest.destructible = false
|
||||
corpse.destroy()
|
||||
corpse = chest
|
||||
@@ -77,22 +77,22 @@ Event.add(defines.events.on_player_died,function(event)
|
||||
if config.show_map_markers then
|
||||
create_map_tag(death)
|
||||
end
|
||||
table.insert(deaths,death)
|
||||
table.insert(deaths, death)
|
||||
end)
|
||||
|
||||
-- every 5 min all bodies are checked for valid map tags
|
||||
if config.show_map_markers then
|
||||
local check_period = 60*60*5 -- five minutes
|
||||
Event.on_nth_tick(check_period,function(event)
|
||||
Event.on_nth_tick(check_period, function()
|
||||
check_map_tags()
|
||||
end)
|
||||
end
|
||||
|
||||
if config.auto_collect_bodies then
|
||||
Event.add(defines.events.on_character_corpse_expired,function(event)
|
||||
Event.add(defines.events.on_character_corpse_expired, function(event)
|
||||
local corpse = event.corpse
|
||||
local items = corpse.get_inventory(defines.inventory.character_corpse).get_contents()
|
||||
move_items(items,corpse.surface,{x=0,y=0})
|
||||
move_items(items, corpse.surface, {x=0, y=0})
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
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 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)
|
||||
@@ -16,8 +16,8 @@ local function to_hex(color)
|
||||
local hex_digits = '0123456789ABCDEF'
|
||||
local function hex(bit)
|
||||
local major, minor = math.modf(bit/16)
|
||||
major,minor = major+1,minor*16+1
|
||||
return hex_digits:sub(major,major)..hex_digits:sub(minor,minor)
|
||||
major, minor = major+1, minor*16+1
|
||||
return hex_digits:sub(major, major)..hex_digits:sub(minor, minor)
|
||||
end
|
||||
|
||||
return '0x'..hex(color.r)..hex(color.g)..hex(color.b)
|
||||
@@ -33,24 +33,24 @@ local function emit_event(args)
|
||||
end
|
||||
|
||||
local tick = args.tick or 0
|
||||
local tick_formated = format_time(tick,{hours = true,minutes = true,string = true,long = true})
|
||||
local tick_formated = format_time(tick, {hours = true, minutes = true, string = true, long = true})
|
||||
|
||||
local players_online = 0
|
||||
local admins_online = 0
|
||||
for _,player in pairs(game.connected_players) do
|
||||
for _, player in pairs(game.connected_players) do
|
||||
players_online = players_online+1
|
||||
if player.admin then
|
||||
admins_online = admins_online + 1
|
||||
end
|
||||
end
|
||||
|
||||
local done = {title=true,color=true,description=true}
|
||||
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 name: ${serverName} Players: %d Admins: %d Time: %s', players_online, admins_online, tick_formated)
|
||||
}}
|
||||
|
||||
for key,value in pairs(args) do
|
||||
for key, value in pairs(args) do
|
||||
if not done[key] then
|
||||
done[key] = true
|
||||
local field = {
|
||||
@@ -59,17 +59,17 @@ local function emit_event(args)
|
||||
inline=false
|
||||
}
|
||||
|
||||
local new_value, inline = value:gsub('<inline>','',1)
|
||||
local new_value, inline = value:gsub('<inline>', '', 1)
|
||||
if inline then
|
||||
field.value = new_value
|
||||
field.inline = true
|
||||
end
|
||||
|
||||
table.insert(fields,field)
|
||||
table.insert(fields, field)
|
||||
end
|
||||
end
|
||||
|
||||
write_json('log/discord.log',{
|
||||
write_json('log/discord.log', {
|
||||
title=title,
|
||||
description=description,
|
||||
color=color,
|
||||
@@ -80,8 +80,8 @@ end
|
||||
--- Reports added and removed
|
||||
if config.player_reports then
|
||||
local Reports = require 'modules.control.reports' --- @dep modules.control.reports
|
||||
Event.add(Reports.events.on_player_reported,function(event)
|
||||
local player_name,by_player_name = get_player_name(event)
|
||||
Event.add(Reports.events.on_player_reported, function(event)
|
||||
local player_name, by_player_name = get_player_name(event)
|
||||
emit_event{
|
||||
title='Report',
|
||||
description='A player was reported',
|
||||
@@ -91,7 +91,7 @@ if config.player_reports then
|
||||
['Reason:']=event.reason
|
||||
}
|
||||
end)
|
||||
Event.add(Reports.events.on_report_removed,function(event)
|
||||
Event.add(Reports.events.on_report_removed, function(event)
|
||||
local player_name = get_player_name(event)
|
||||
emit_event{
|
||||
title='Report Removed',
|
||||
@@ -106,8 +106,8 @@ end
|
||||
--- Warnings added and removed
|
||||
if config.player_warnings then
|
||||
local Warnings = require 'modules.control.warnings' --- @dep modules.control.warnings
|
||||
Event.add(Warnings.events.on_warning_added,function(event)
|
||||
local player_name,by_player_name = get_player_name(event)
|
||||
Event.add(Warnings.events.on_warning_added, function(event)
|
||||
local player_name, by_player_name = get_player_name(event)
|
||||
emit_event{
|
||||
title='Warning',
|
||||
description='A player has been given a warning',
|
||||
@@ -117,8 +117,8 @@ if config.player_warnings then
|
||||
['Reason:']=event.reason
|
||||
}
|
||||
end)
|
||||
Event.add(Warnings.events.on_warning_removed,function(event)
|
||||
local player_name,by_player_name = get_player_name(event)
|
||||
Event.add(Warnings.events.on_warning_removed, function(event)
|
||||
local player_name, by_player_name = get_player_name(event)
|
||||
emit_event{
|
||||
title='Warning Removed',
|
||||
description='A player has a warning removed',
|
||||
@@ -132,8 +132,8 @@ end
|
||||
--- When a player is jailed or unjailed
|
||||
if config.player_jail then
|
||||
local Jail = require 'modules.control.jail'
|
||||
Event.add(Jail.events.on_player_jailed,function(event)
|
||||
local player_name,by_player_name = get_player_name(event)
|
||||
Event.add(Jail.events.on_player_jailed, function(event)
|
||||
local player_name, by_player_name = get_player_name(event)
|
||||
emit_event{
|
||||
title='Jail',
|
||||
description='A player has been jailed',
|
||||
@@ -143,8 +143,8 @@ if config.player_jail then
|
||||
['Reason:']=event.reason
|
||||
}
|
||||
end)
|
||||
Event.add(Jail.events.on_player_unjailed,function(event)
|
||||
local player_name,by_player_name = get_player_name(event)
|
||||
Event.add(Jail.events.on_player_unjailed, function(event)
|
||||
local player_name, by_player_name = get_player_name(event)
|
||||
emit_event{
|
||||
title='Unjail',
|
||||
description='A player has been unjailed',
|
||||
@@ -158,8 +158,8 @@ end
|
||||
--- When a player is tempbanned
|
||||
if config.player_temp_ban then
|
||||
local Jail = require 'modules.control.jail'
|
||||
Event.add(Jail.events.on_player_temp_banned,function(event)
|
||||
local player_name,by_player_name = get_player_name(event)
|
||||
Event.add(Jail.events.on_player_temp_banned, function(event)
|
||||
local player_name, by_player_name = get_player_name(event)
|
||||
emit_event{
|
||||
title='Temp Ban',
|
||||
description='A player has been temp banned',
|
||||
@@ -169,8 +169,8 @@ if config.player_temp_ban then
|
||||
['Reason:']=event.reason
|
||||
}
|
||||
end)
|
||||
Event.add(Jail.events.on_player_untemp_banned,function(event)
|
||||
local player_name,by_player_name = get_player_name(event)
|
||||
Event.add(Jail.events.on_player_untemp_banned, function(event)
|
||||
local player_name, by_player_name = get_player_name(event)
|
||||
emit_event{
|
||||
title='Temp Ban Removed',
|
||||
description='A player has been untemp banned',
|
||||
@@ -183,7 +183,7 @@ end
|
||||
|
||||
--- Ban and unban
|
||||
if config.player_bans then
|
||||
Event.add(defines.events.on_player_banned,function(event)
|
||||
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)
|
||||
emit_event{
|
||||
@@ -196,7 +196,7 @@ if config.player_bans then
|
||||
}
|
||||
end
|
||||
end)
|
||||
Event.add(defines.events.on_player_unbanned,function(event)
|
||||
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)
|
||||
emit_event{
|
||||
@@ -212,7 +212,7 @@ end
|
||||
|
||||
--- Mute and unmute
|
||||
if config.player_mutes then
|
||||
Event.add(defines.events.on_player_muted,function(event)
|
||||
Event.add(defines.events.on_player_muted, function(event)
|
||||
local player_name = get_player_name(event)
|
||||
emit_event{
|
||||
title='Muted',
|
||||
@@ -221,7 +221,7 @@ if config.player_mutes then
|
||||
['Player:']='<inline>'..player_name
|
||||
}
|
||||
end)
|
||||
Event.add(defines.events.on_player_unmuted,function(event)
|
||||
Event.add(defines.events.on_player_unmuted, function(event)
|
||||
local player_name = get_player_name(event)
|
||||
emit_event{
|
||||
title='Un-Muted',
|
||||
@@ -234,7 +234,7 @@ end
|
||||
|
||||
--- Kick
|
||||
if config.player_kicks then
|
||||
Event.add(defines.events.on_player_kicked,function(event)
|
||||
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)
|
||||
@@ -252,7 +252,7 @@ end
|
||||
|
||||
--- Promote and demote
|
||||
if config.player_promotes then
|
||||
Event.add(defines.events.on_player_promoted,function(event)
|
||||
Event.add(defines.events.on_player_promoted, function(event)
|
||||
local player_name = get_player_name(event)
|
||||
emit_event{
|
||||
title='Promote',
|
||||
@@ -261,7 +261,7 @@ if config.player_promotes then
|
||||
['Player:']='<inline>'..player_name
|
||||
}
|
||||
end)
|
||||
Event.add(defines.events.on_player_demoted,function(event)
|
||||
Event.add(defines.events.on_player_demoted, function(event)
|
||||
local player_name = get_player_name(event)
|
||||
emit_event{
|
||||
title='Demote',
|
||||
@@ -273,12 +273,12 @@ if config.player_promotes then
|
||||
end
|
||||
|
||||
--- Other commands
|
||||
Event.add(defines.events.on_console_command,function(event)
|
||||
Event.add(defines.events.on_console_command, function(event)
|
||||
if event.player_index then
|
||||
local player_name = get_player_name(event)
|
||||
if config[event.command] then
|
||||
emit_event{
|
||||
title=event.command:gsub('^%l',string.upper),
|
||||
title=event.command:gsub('^%l', string.upper),
|
||||
description='/'..event.command..' was used',
|
||||
color=Colors.grey,
|
||||
['By:']='<inline>'..player_name,
|
||||
|
||||
@@ -7,7 +7,7 @@ local config = require 'config.join_messages' --- @dep config.join_messages
|
||||
local Global = require 'utils.global' --- @dep utils.global
|
||||
require 'overrides.table'
|
||||
|
||||
Global.register(config,function(tbl)
|
||||
Global.register(config, function(tbl)
|
||||
config = tbl
|
||||
end)
|
||||
|
||||
@@ -16,9 +16,9 @@ function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local custom_message = config[player.name]
|
||||
if custom_message then
|
||||
game.print(custom_message,player.color)
|
||||
game.print(custom_message, player.color)
|
||||
else
|
||||
player.print{'greetings.greet',{'links.discord'}}
|
||||
player.print{'greetings.greet', {'links.discord'}}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ local Event = require 'utils.event' --- @dep utils.event
|
||||
local config = require 'config.pollution_grading' --- @dep config.pollution_grading
|
||||
|
||||
local delay = config.update_delay * 3600 -- convert from minutes to ticks
|
||||
Event.on_nth_tick(delay,function()
|
||||
Event.on_nth_tick(delay, function()
|
||||
local surface = game.surfaces[1]
|
||||
local true_max = surface.get_pollution(config.reference_point)
|
||||
local max = true_max*config.max_scalar
|
||||
|
||||
@@ -8,22 +8,22 @@ local config = require 'config.preset_player_colours' --- @dep config.preset_pla
|
||||
local Global = require 'utils.global' --- @dep utils.global
|
||||
require 'overrides.table'
|
||||
|
||||
Global.register(config,function(tbl)
|
||||
Global.register(config, function(tbl)
|
||||
config = tbl
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_player_created,function(event)
|
||||
Event.add(defines.events.on_player_created, function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local color = 'white'
|
||||
if config.players[player.name] then
|
||||
color = config.players[player.name]
|
||||
else
|
||||
while config.disallow[color] do
|
||||
color = table.get_random_dictionary_entry(Colours,true)
|
||||
color = table.get_random_dictionary_entry(Colours, true)
|
||||
end
|
||||
color = Colours[color]
|
||||
end
|
||||
color = {r=color.r/255,g=color.g/255,b=color.b/255,a=0.5}
|
||||
color = {r=color.r/255, g=color.g/255, b=color.b/255, a=0.5}
|
||||
player.color = color
|
||||
player.chat_color = color
|
||||
end)
|
||||
@@ -9,7 +9,7 @@ local config = require 'config.scorched_earth' --- @dep config.scorched_earth
|
||||
|
||||
-- Loops over the config and finds the wile which has the highest value for strength
|
||||
local max_strength = 0
|
||||
for _,strength in pairs(config.strengths) do
|
||||
for _, strength in pairs(config.strengths) do
|
||||
if strength > max_strength then
|
||||
max_strength = strength
|
||||
end
|
||||
@@ -22,12 +22,12 @@ Global.register(debug_players, function(tbl)
|
||||
end)
|
||||
|
||||
-- Will degrade a tile down to the next tile when called
|
||||
local function degrade(surface,position)
|
||||
local function degrade(surface, position)
|
||||
local tile = surface.get_tile(position)
|
||||
local tile_name = tile.name
|
||||
local degrade_tile_name = config.degrade_order[tile_name]
|
||||
if not degrade_tile_name then return end
|
||||
surface.set_tiles{{name=degrade_tile_name,position=position}}
|
||||
surface.set_tiles{{name=degrade_tile_name, position=position}}
|
||||
end
|
||||
|
||||
-- Same as degrade but will degrade all tiles that are under an entity
|
||||
@@ -42,12 +42,12 @@ local function degrade_entity(entity)
|
||||
for x = lt.x, rb.x do -- x loop
|
||||
local px = position.x+x
|
||||
for y = lt.y, rb.y do -- y loop
|
||||
local p = {x=px,y=position.y+y}
|
||||
local p = {x=px, y=position.y+y}
|
||||
local tile = surface.get_tile(p)
|
||||
local tile_name = tile.name
|
||||
local degrade_tile_name = config.degrade_order[tile_name]
|
||||
if not degrade_tile_name then return end
|
||||
table.insert(tiles,{name=degrade_tile_name,position=p})
|
||||
table.insert(tiles, {name=degrade_tile_name, position=p})
|
||||
end
|
||||
end
|
||||
surface.set_tiles(tiles)
|
||||
@@ -62,15 +62,15 @@ local function get_probability(strength)
|
||||
end
|
||||
|
||||
-- Gets the mean of the strengths around a tile to give the strength at that position
|
||||
local function get_tile_strength(surface,position)
|
||||
local function get_tile_strength(surface, position)
|
||||
local tile = surface.get_tile(position)
|
||||
local tile_name = tile.name
|
||||
local strength = config.strengths[tile_name]
|
||||
if not strength then return end
|
||||
for x = -1,1 do -- x loop
|
||||
for x = -1, 1 do -- x loop
|
||||
local px = position.x + x
|
||||
for y = -1,1 do -- y loop
|
||||
local check_tile = surface.get_tile{x=px,y=position.y+y}
|
||||
for y = -1, 1 do -- y loop
|
||||
local check_tile = surface.get_tile{x=px, y=position.y+y}
|
||||
local check_tile_name = check_tile.name
|
||||
local check_strength = config.strengths[check_tile_name] or 0
|
||||
strength = strength + check_strength
|
||||
@@ -80,12 +80,12 @@ local function get_tile_strength(surface,position)
|
||||
end
|
||||
|
||||
-- Same as get_tile_strength but returns to a in game text rather than as a value
|
||||
local function debug_get_tile_strength(surface,position)
|
||||
for x = -3,3 do -- x loop
|
||||
local function debug_get_tile_strength(surface, position)
|
||||
for x = -3, 3 do -- x loop
|
||||
local px = position.x+x
|
||||
for y = -3,3 do -- y loop
|
||||
local p = {x=px,y=position.y+y}
|
||||
local strength = get_tile_strength(surface,p) or 0
|
||||
for y = -3, 3 do -- y loop
|
||||
local p = {x=px, y=position.y+y}
|
||||
local strength = get_tile_strength(surface, p) or 0
|
||||
local tile = surface.get_tile(p)
|
||||
print_grid_value(get_probability(strength)*config.weakness_value, surface, tile.position)
|
||||
end
|
||||
@@ -97,13 +97,13 @@ Event.add(defines.events.on_player_changed_position, function(event)
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
local surface = player.surface
|
||||
local position = player.position
|
||||
local strength = get_tile_strength(surface,position)
|
||||
local strength = get_tile_strength(surface, position)
|
||||
if not strength then return end
|
||||
if get_probability(strength) > math.random() then
|
||||
degrade(surface,position)
|
||||
degrade(surface, position)
|
||||
end
|
||||
if debug_players[player.name] then
|
||||
debug_get_tile_strength(surface,position)
|
||||
debug_get_tile_strength(surface, position)
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -112,7 +112,7 @@ Event.add(defines.events.on_built_entity, function(event)
|
||||
local entity = event.created_entity
|
||||
local surface = entity.surface
|
||||
local position = entity.position
|
||||
local strength = get_tile_strength(surface,position)
|
||||
local strength = get_tile_strength(surface, position)
|
||||
if not strength then return end
|
||||
if get_probability(strength)*config.weakness_value > math.random() then
|
||||
degrade_entity(entity)
|
||||
@@ -124,7 +124,7 @@ Event.add(defines.events.on_robot_built_entity, function(event)
|
||||
local entity = event.created_entity
|
||||
local surface = entity.surface
|
||||
local position = entity.position
|
||||
local strength = get_tile_strength(surface,position)
|
||||
local strength = get_tile_strength(surface, position)
|
||||
if not strength then return end
|
||||
if get_probability(strength)*config.weakness_value > math.random() then
|
||||
degrade_entity(entity)
|
||||
@@ -132,7 +132,7 @@ Event.add(defines.events.on_robot_built_entity, function(event)
|
||||
end)
|
||||
|
||||
-- Used as a way to access the global table
|
||||
return function(player_name,state)
|
||||
return function(player_name, state)
|
||||
local player = Game.get_player_from_any(player_name)
|
||||
clear_flying_text(player.surface)
|
||||
debug_players[player_name] = state
|
||||
|
||||
@@ -10,7 +10,7 @@ local entities = config.entities
|
||||
local belts = config.afk_belts.locations
|
||||
local turrets = config.infinite_ammo_turrets.locations
|
||||
|
||||
Global.register(turrets,function(tbl)
|
||||
Global.register(turrets, function(tbl)
|
||||
turrets = tbl
|
||||
end)
|
||||
|
||||
@@ -19,13 +19,13 @@ local function get_spawn_force()
|
||||
local force = game.forces['Spawn']
|
||||
if force and force.valid then return force end
|
||||
force = game.create_force('Spawn')
|
||||
force.set_cease_fire('player',true)
|
||||
game.forces['player'].set_cease_fire('Spawn',true)
|
||||
force.set_cease_fire('player', true)
|
||||
game.forces['player'].set_cease_fire('Spawn', true)
|
||||
return force
|
||||
end
|
||||
|
||||
-- protects and entity so players cant do anything to it
|
||||
local function protect_entity(entity,set_force)
|
||||
local function protect_entity(entity, set_force)
|
||||
if entity and entity.valid then
|
||||
entity.destructible = false
|
||||
entity.minable = false
|
||||
@@ -39,40 +39,40 @@ end
|
||||
-- handles the infinite ammo turrets
|
||||
local function spawn_turrets()
|
||||
if config.infinite_ammo_turrets.enabled then
|
||||
for _,turret_pos in pairs(turrets) do
|
||||
for _, turret_pos in pairs(turrets) do
|
||||
local surface = game.surfaces[turret_pos.surface]
|
||||
local pos = turret_pos.position
|
||||
local turret = surface.find_entity('gun-turret',pos)
|
||||
local turret = surface.find_entity('gun-turret', pos)
|
||||
-- Makes a new turret if it is not found
|
||||
if not turret or not turret.valid then
|
||||
turret = surface.create_entity{name='gun-turret',position=pos,force='Spawn'}
|
||||
protect_entity(turret,true)
|
||||
turret = surface.create_entity{name='gun-turret', position=pos, force='Spawn'}
|
||||
protect_entity(turret, true)
|
||||
end
|
||||
-- adds ammo to the turret
|
||||
local inv = turret.get_inventory(defines.inventory.turret_ammo)
|
||||
if inv.can_insert{name=config.infinite_ammo_turrets.ammo_type,count=10} then
|
||||
inv.insert{name=config.infinite_ammo_turrets.ammo_type,count=10}
|
||||
if inv.can_insert{name=config.infinite_ammo_turrets.ammo_type, count=10} then
|
||||
inv.insert{name=config.infinite_ammo_turrets.ammo_type, count=10}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- makes a 2x2 afk belt where set in config
|
||||
local function spawn_belts(surface,position)
|
||||
local belt_details = {{-0.5,-0.5,2},{0.5,-0.5,4},{-0.5,0.5,0},{0.5,0.5,6}} -- x,y,dir
|
||||
for _,belt_set in pairs(belts) do
|
||||
local function spawn_belts(surface, position)
|
||||
local belt_details = {{-0.5, -0.5, 2}, {0.5, -0.5, 4}, {-0.5, 0.5, 0}, {0.5, 0.5, 6}} -- x, y,dir
|
||||
for _, belt_set in pairs(belts) do
|
||||
local o = position
|
||||
local p = belt_set
|
||||
for _,belt in pairs(belt_details) do
|
||||
local pos = {x=o.x+p.x+belt[1],y=o.y+p.y+belt[2]}
|
||||
local belt_entity = surface.create_entity{name='transport-belt',position=pos,force='neutral',direction=belt[3]}
|
||||
for _, belt in pairs(belt_details) do
|
||||
local pos = {x=o.x+p.x+belt[1], y=o.y+p.y+belt[2]}
|
||||
local belt_entity = surface.create_entity{name='transport-belt', position=pos, force='neutral', direction=belt[3]}
|
||||
protect_entity(belt_entity)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- generates an area with no water and removes entities in the decon area
|
||||
local function spawn_base(surface,position)
|
||||
local function spawn_base(surface, position)
|
||||
local dr = config.corrections.deconstruction_radius
|
||||
local dr2 = dr^2
|
||||
local dtile = config.corrections.deconstruction_tile
|
||||
@@ -86,17 +86,17 @@ local function spawn_base(surface,position)
|
||||
for y = -pr, pr do -- loop over y
|
||||
local y2 = y^2
|
||||
local prod = x2+y2
|
||||
local p = {x=position.x+x,y=position.y+y}
|
||||
local p = {x=position.x+x, y=position.y+y}
|
||||
if prod < dr2 then
|
||||
-- if it is inside the decon radius
|
||||
table.insert(tiles_to_make,{name=dtile,position=p})
|
||||
local entities_to_remove = surface.find_entities_filtered{area={{p.x-1,p.y-1},{p.x,p.y}}}
|
||||
for _,entity in pairs(entities_to_remove) do
|
||||
table.insert(tiles_to_make, {name=dtile, position=p})
|
||||
local entities_to_remove = surface.find_entities_filtered{area={{p.x-1, p.y-1}, {p.x, p.y}}}
|
||||
for _, entity in pairs(entities_to_remove) do
|
||||
if entity.name ~= 'character' then entity.destroy() end
|
||||
end
|
||||
elseif prod < pr2 then
|
||||
-- if it is inside the pattern radius
|
||||
table.insert(tiles_to_make,{name=ptile,position=p})
|
||||
table.insert(tiles_to_make, {name=ptile, position=p})
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -104,30 +104,30 @@ local function spawn_base(surface,position)
|
||||
end
|
||||
|
||||
-- generates the pattern that is in the config
|
||||
local function spawn_pattern(surface,position)
|
||||
local function spawn_pattern(surface, position)
|
||||
local tiles_to_make = {}
|
||||
local ptile = config.corrections.pattern_tile
|
||||
local o = config.corrections.offset
|
||||
local p = {x=position.x+o.x,y=position.y+o.y}
|
||||
for _,tile in pairs(tiles) do
|
||||
table.insert(tiles_to_make,{name=ptile,position={tile[1]+p.x,tile[2]+p.y}})
|
||||
local p = {x=position.x+o.x, y=position.y+o.y}
|
||||
for _, tile in pairs(tiles) do
|
||||
table.insert(tiles_to_make, {name=ptile, position={tile[1]+p.x, tile[2]+p.y}})
|
||||
end
|
||||
surface.set_tiles(tiles_to_make)
|
||||
end
|
||||
|
||||
-- generates the entities that are in the config
|
||||
local function spawn_entities(surface,position)
|
||||
local function spawn_entities(surface, position)
|
||||
local o = config.corrections.offset
|
||||
local p = {x=position.x+o.x,y=position.y+o.y}
|
||||
for _,entity in pairs(entities) do
|
||||
entity = surface.create_entity{name=entity[1],position={entity[2]+p.x,entity[3]+p.y},force='neutral'}
|
||||
local p = {x=position.x+o.x, y=position.y+o.y}
|
||||
for _, entity in pairs(entities) do
|
||||
entity = surface.create_entity{name=entity[1], position={entity[2]+p.x, entity[3]+p.y}, force='neutral'}
|
||||
protect_entity(entity)
|
||||
entity.operable = true
|
||||
end
|
||||
end
|
||||
|
||||
local refill_time = 60*60*5 -- 5 minutes
|
||||
Event.on_nth_tick(refill_time,function()
|
||||
Event.on_nth_tick(refill_time, function()
|
||||
if game.tick < 10 then return end
|
||||
spawn_turrets()
|
||||
end)
|
||||
@@ -135,15 +135,15 @@ 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 p = {x=0,y=0}
|
||||
local p = {x=0, y=0}
|
||||
local s = player.surface
|
||||
spawn_base(s,p)
|
||||
spawn_pattern(s,p)
|
||||
spawn_base(s, p)
|
||||
spawn_pattern(s, p)
|
||||
get_spawn_force()
|
||||
spawn_entities(s,p)
|
||||
spawn_belts(s,p)
|
||||
spawn_entities(s, p)
|
||||
spawn_belts(s, p)
|
||||
spawn_turrets()
|
||||
player.teleport(p,s)
|
||||
player.teleport(p, s)
|
||||
end)
|
||||
|
||||
-- Way to access global table
|
||||
|
||||
@@ -1,54 +1,7 @@
|
||||
---LuaPlayerBuiltEntityEventFilters
|
||||
---Events.set_event_filter(defines.events.on_built_entity, {{filter = "name", name = "fast-inserter"}})
|
||||
local Event = require 'utils.event' --- @dep utils.event
|
||||
local station_name_changer =
|
||||
function(event)
|
||||
local enetety = event.created_entity
|
||||
local name = enetety.name
|
||||
|
||||
if name == "train-stop" then --only do the event if its a trainstop
|
||||
local boundingbox = enetety.bounding_box
|
||||
-- expanded box for recourse search:
|
||||
local bounding2 = { {boundingbox.left_top.x -100 ,boundingbox.left_top.y -100} , {boundingbox.right_bottom.x +100,boundingbox.right_bottom.y +100 } }
|
||||
--gets all resources in bounding_box2:
|
||||
local recoursec = game.surfaces[1].find_entities_filtered{area = bounding2, type = "resource"}
|
||||
|
||||
if #recoursec > 0 then -- save cpu time if their are no recourses in bounding_box2
|
||||
local closest_distance
|
||||
local px,py = boundingbox.left_top.x,boundingbox.left_top.y
|
||||
local recourse_closed
|
||||
|
||||
--Check which recource is closest
|
||||
for i, item in ipairs(recoursec) do
|
||||
local dx, dy = px - item.bounding_box.left_top.x, py - item.bounding_box.left_top.y
|
||||
local distance = (dx*dx)+(dy*dy)
|
||||
if not closest_distance or distance < closest_distance then
|
||||
recourse_closed = item
|
||||
closest_distance = distance
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
local item_name = recourse_closed.name
|
||||
if item_name then -- prevent errors if something went wrong
|
||||
local item_name2 = item_name:gsub("^%l", string.upper):gsub('-',' ') -- removing the - and making first letter capital
|
||||
|
||||
local Item_ore_fluid = "item"
|
||||
if item_name == "crude-oil" then
|
||||
Item_ore_fluid = "fluid"
|
||||
end
|
||||
--Final string:
|
||||
enetety.backer_name = string.format("[L] [img=%s.%s] %s %s (%s)",Item_ore_fluid,item_name,item_name2,enetety.backer_name,Angle( enetety ))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
--add func to robot and player build entities
|
||||
Event.add(defines.events.on_built_entity,station_name_changer)
|
||||
Event.add(defines.events.on_robot_built_entity,station_name_changer)
|
||||
|
||||
|
||||
--Credit to Cooldude2606 for using his lua magic to make this function.
|
||||
local directions = {
|
||||
['W'] = -0.875,
|
||||
@@ -60,12 +13,58 @@ local directions = {
|
||||
['S'] = 0.625,
|
||||
['SW'] = 0.875
|
||||
}
|
||||
function Angle( enetety )
|
||||
local angle = math.atan2(enetety.position.y,enetety.position.x)/math.pi
|
||||
for direction, requiredAngle in pairs(directions) do
|
||||
if angle < requiredAngle then
|
||||
return direction
|
||||
end
|
||||
end
|
||||
|
||||
local function Angle(entity)
|
||||
local angle = math.atan2(entity.position.y, entity.position.x)/math.pi
|
||||
for direction, requiredAngle in pairs(directions) do
|
||||
if angle < requiredAngle then
|
||||
return direction
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function station_name_changer(event)
|
||||
local entity = event.created_entity
|
||||
local name = entity.name
|
||||
|
||||
if name == "train-stop" then --only do the event if its a train stop
|
||||
local boundingBox = entity.bounding_box
|
||||
-- expanded box for recourse search:
|
||||
local bounding2 = { {boundingBox.left_top.x -100 ,boundingBox.left_top.y -100} , {boundingBox.right_bottom.x +100, boundingBox.right_bottom.y +100 } }
|
||||
-- gets all resources in bounding_box2:
|
||||
local recourses = game.surfaces[1].find_entities_filtered{area = bounding2, type = "resource"}
|
||||
|
||||
if #recourses > 0 then -- save cpu time if their are no recourses in bounding_box2
|
||||
local closest_distance
|
||||
local px, py = boundingBox.left_top.x, boundingBox.left_top.y
|
||||
local recourse_closed
|
||||
|
||||
--Check which recourse is closest
|
||||
for i, item in ipairs(recourses) do
|
||||
local dx, dy = px - item.bounding_box.left_top.x, py - item.bounding_box.left_top.y
|
||||
local distance = (dx*dx)+(dy*dy)
|
||||
if not closest_distance or distance < closest_distance then
|
||||
recourse_closed = item
|
||||
closest_distance = distance
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local item_name = recourse_closed.name
|
||||
if item_name then -- prevent errors if something went wrong
|
||||
local item_name2 = item_name:gsub("^%l", string.upper):gsub('-', ' ') -- removing the - and making first letter capital
|
||||
|
||||
local Item_ore_fluid = "item"
|
||||
if item_name == "crude-oil" then
|
||||
Item_ore_fluid = "fluid"
|
||||
end
|
||||
--Final string:
|
||||
entity.backer_name = string.format("[L] [img=%s.%s] %s %s (%s)", Item_ore_fluid, item_name, item_name2, entity.backer_name, Angle( entity ))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Add handler to robot and player build entities
|
||||
Event.add(defines.events.on_built_entity, station_name_changer)
|
||||
Event.add(defines.events.on_robot_built_entity, station_name_changer)
|
||||
|
||||
@@ -57,7 +57,7 @@ Event.add(defines.events.on_tick, function()
|
||||
local max_remove = math.floor(head/100)+1
|
||||
local remove_count = math.random(0, max_remove)
|
||||
while remove_count > 0 and head > 0 do
|
||||
local remove_index = math.random(1,head)
|
||||
local remove_index = math.random(1, head)
|
||||
local entity = tree_queue[remove_index]
|
||||
tree_queue[remove_index] = tree_queue[head]
|
||||
head = head - 1
|
||||
@@ -71,7 +71,7 @@ end)
|
||||
|
||||
-- Clear the chache
|
||||
Event.on_nth_tick(300, function()
|
||||
for key,_ in pairs(chache) do
|
||||
for key, _ in pairs(chache) do
|
||||
chache[key] = nil
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user