diff --git a/.gitignore b/.gitignore index 1ca6a45d..95ba8e14 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .vscode/ .history/ .git/ +maps/biter_battles_v3/ diff --git a/comfy_panel/poll.lua b/comfy_panel/poll.lua index aa10ea5f..ccee37b0 100644 --- a/comfy_panel/poll.lua +++ b/comfy_panel/poll.lua @@ -6,7 +6,6 @@ local Server = require 'utils.server' local Tabs = require 'comfy_panel.main' local session = require 'utils.datastore.session_data' - local Class = {} local insert = table.insert @@ -946,6 +945,10 @@ Gui.on_click( function(event) local data = Gui.get_data(event.element) + if not data then + return + end + insert(data.answers, {text = ''}) redraw_create_poll_content(data) end diff --git a/maps/cave_miner_v2/market.lua b/maps/cave_miner_v2/market.lua index fae17582..3137abb7 100644 --- a/maps/cave_miner_v2/market.lua +++ b/maps/cave_miner_v2/market.lua @@ -88,7 +88,7 @@ function Public.offer_bought(event, cave_miner) local offers = market.get_market_items() local bought_offer = offers[offer_index].offer if bought_offer.type ~= "nothing" then return end - if offer_index == 1 then + if offer_index == 1 and Constants.pickaxe_tiers[cave_miner.pickaxe_tier + 1] then market.force.play_sound({path = 'utility/new_objective', volume_modifier = 0.75}) cave_miner.pickaxe_tier = cave_miner.pickaxe_tier + 1 local speed = Functions.set_mining_speed(cave_miner, player.force) diff --git a/maps/mountain_fortress_v3/entities.lua b/maps/mountain_fortress_v3/entities.lua index 9890a770..0c98c875 100644 --- a/maps/mountain_fortress_v3/entities.lua +++ b/maps/mountain_fortress_v3/entities.lua @@ -240,6 +240,7 @@ local function set_train_final_health(final_damage_amount) locomotive_health = WPT.get('locomotive_health') if locomotive_health <= 0 then + WPT.set('game_lost', true) Public.loco_died() end @@ -1103,6 +1104,11 @@ function Public.unstuck_player(index) end function Public.loco_died() + local game_lost = WPT.get('game_lost') + if not game_lost then + return + end + local active_surface_index = WPT.get('active_surface_index') local locomotive = WPT.get('locomotive') local surface = game.surfaces[active_surface_index] @@ -1169,14 +1175,12 @@ function Public.loco_died() rendering.set_text(this.health_text, 'HP: ' .. this.locomotive_health .. ' / ' .. this.locomotive_max_health) wave_defense_table.game_lost = true wave_defense_table.target = nil - this.game_lost = true local msg = defeated_messages[random(1, #defeated_messages)] local pos = { position = this.locomotive.position } Alert.alert_all_players_location(pos, msg) - Server.to_discord_bold(msg, true) game.forces.enemy.set_friend('player', true) game.forces.player.set_friend('enemy', true) diff --git a/maps/mountain_fortress_v3/functions.lua b/maps/mountain_fortress_v3/functions.lua index 363dd5f1..204c0467 100644 --- a/maps/mountain_fortress_v3/functions.lua +++ b/maps/mountain_fortress_v3/functions.lua @@ -1058,6 +1058,10 @@ function Public.set_spawn_position() if spawn_near_collapse.active then local collapse_position = surface.find_non_colliding_position('small-biter', collapse_pos, 32, 2) local sizeof = locomotive_positions.tbl[total_pos - total_pos + 1] + if not sizeof then + goto continue + end + if check_tile(surface, sizeof, locomotive_positions.tbl, total_pos) then retries = retries + 1 if retries == 2 then diff --git a/maps/mountain_fortress_v3/gui.lua b/maps/mountain_fortress_v3/gui.lua index e5b530a6..6acafa58 100644 --- a/maps/mountain_fortress_v3/gui.lua +++ b/maps/mountain_fortress_v3/gui.lua @@ -11,6 +11,14 @@ local main_button_name = Gui.uid_name() local main_frame_name = Gui.uid_name() local floor = math.floor +local function validate_entity(entity) + if not (entity and entity.valid) then + return false + end + + return true +end + local function validate_player(player) if not player then return false @@ -159,6 +167,10 @@ local function on_gui_click(event) end local locomotive = WPT.get('locomotive') + if not validate_entity(locomotive) then + return + end + if not player or not player.valid then return end diff --git a/maps/mountain_fortress_v3/ic/functions.lua b/maps/mountain_fortress_v3/ic/functions.lua index 49920d24..cde355e6 100644 --- a/maps/mountain_fortress_v3/ic/functions.lua +++ b/maps/mountain_fortress_v3/ic/functions.lua @@ -870,10 +870,12 @@ function Public.use_door_with_entity(ic, player, door) end end - player_data.fallback_surface = car.entity.surface.index - player_data.fallback_position = {car.entity.position.x, car.entity.position.y} + if validate_entity(car.entity) then + player_data.fallback_surface = car.entity.surface.index + player_data.fallback_position = {car.entity.position.x, car.entity.position.y} + end - if car.entity.surface.name == player.surface.name then + if validate_entity(car.entity) and car.entity.surface.name == player.surface.name then local surface = car.surface if validate_entity(car.entity) and car.owner == player.index then IC_Gui.add_toolbar(player) diff --git a/maps/mountain_fortress_v3/ic/main.lua b/maps/mountain_fortress_v3/ic/main.lua index 0a0ce193..c0cf7cf3 100644 --- a/maps/mountain_fortress_v3/ic/main.lua +++ b/maps/mountain_fortress_v3/ic/main.lua @@ -18,7 +18,6 @@ local function on_entity_died(event) local ic = IC.get() if entity.type == 'car' or entity.name == 'spidertron' then - Minimap.kill_minimap(game.players[event.player_index]) Functions.kill_car(ic, entity) end end diff --git a/maps/mountain_fortress_v3/icw/main.lua b/maps/mountain_fortress_v3/icw/main.lua index 419ff40d..06d15e99 100644 --- a/maps/mountain_fortress_v3/icw/main.lua +++ b/maps/mountain_fortress_v3/icw/main.lua @@ -86,6 +86,13 @@ local function on_train_created() Functions.request_reconstruction(icw) end +local function on_built_entity(event) + local icw = ICW.get() + local created_entity = event.created_entity + Functions.create_wagon(icw, created_entity) + Functions.add_wagon_entity_count(icw, created_entity) +end + local function on_gui_click(event) local icw = ICW.get() Functions.toggle_minimap(icw, event) @@ -153,5 +160,6 @@ Event.add(defines.events.on_gui_opened, on_gui_opened) Event.add(defines.events.on_player_built_tile, on_player_or_robot_built_tile) Event.add(defines.events.on_robot_built_tile, on_player_or_robot_built_tile) Event.add(defines.events.on_gui_switch_state_changed, on_gui_switch_state_changed) +Event.add(defines.events.on_built_entity, on_built_entity) return Public diff --git a/modules/check_fullness.lua b/modules/check_fullness.lua index 3101dc02..a90eb1f5 100644 --- a/modules/check_fullness.lua +++ b/modules/check_fullness.lua @@ -35,7 +35,7 @@ local function compute_fullness(player) local warn_player = is_player_warned(player) local free_slots = player.get_main_inventory().count_empty_stacks() if free_slots == 0 or free_slots == 1 then - if player.character then + if player.character and player.character.valid then local damage = ceil((warn_player.count / 2) * warn_player.count) if player.character.health >= damage then player.character.damage(damage, 'player', 'explosion') diff --git a/modules/difficulty_vote_by_amount.lua b/modules/difficulty_vote_by_amount.lua index b660f00a..a3334c71 100644 --- a/modules/difficulty_vote_by_amount.lua +++ b/modules/difficulty_vote_by_amount.lua @@ -178,6 +178,9 @@ end local function set_difficulty() local index = highest_count(this.difficulties) + if not index then + return + end if this.difficulty_vote_index ~= index then local message = table.concat({'>> Map difficulty has changed to ', this.difficulties[index].name, ' difficulty!'}) diff --git a/modules/rpg/main.lua b/modules/rpg/main.lua index 73862343..5f113efd 100644 --- a/modules/rpg/main.lua +++ b/modules/rpg/main.lua @@ -159,6 +159,22 @@ local get_cause_player = { end return players end, + ['spider-vehicle'] = function(cause) + local players = {} + local driver = cause.get_driver() + if driver then + if driver.player then + players[#players + 1] = driver.player + end + end + local passenger = cause.get_passenger() + if passenger then + if passenger.player then + players[#players + 1] = passenger.player + end + end + return players + end, ['locomotive'] = train_type_cause, ['cargo-wagon'] = train_type_cause, ['artillery-wagon'] = train_type_cause, diff --git a/utils/datastore/jail_data.lua b/utils/datastore/jail_data.lua index c4fdb296..9fa4fd35 100644 --- a/utils/datastore/jail_data.lua +++ b/utils/datastore/jail_data.lua @@ -45,6 +45,14 @@ Global.register( local Public = {} +local validate_entity = function(entity) + if not (entity and entity.valid) then + return false + end + + return true +end + local clear_gui = Token.register( function(data) @@ -184,10 +192,7 @@ local teleport_player_to_gulag = function(player, action) local gulag_tp = function(surface) get_player_data(player, true) - player.teleport( - surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 128, 1), - surface.name - ) + player.teleport(surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 128, 1), surface.name) end if action == 'jail' then @@ -244,7 +249,19 @@ local validate_args = function(data) local message = data.message local cmd = data.cmd - if not griefer or not game.players[griefer] then + if not type(griefer) == 'string' then + Utils.print_to(player, 'Invalid name.') + return false + end + + local get_griefer_player = game.get_player(griefer) + + if not validate_entity(get_griefer_player) then + Utils.print_to(player, 'Invalid name.') + return false + end + + if not griefer or not get_griefer_player then Utils.print_to(player, 'Invalid name.') return false end @@ -269,7 +286,7 @@ local validate_args = function(data) return false end - if game.players[griefer].admin and not player.admin then + if get_griefer_player.admin and not player.admin then Utils.print_to(player, 'You canĀ“t select an admin.') return false end @@ -307,10 +324,7 @@ local vote_to_jail = function(player, griefer, msg) votejail[griefer][player.name] = true votejail[griefer].index = votejail[griefer].index + 1 Utils.print_to(player, 'You have voted to jail player ' .. griefer .. '.') - if - votejail[griefer].index >= settings.votejail_count or - (votejail[griefer].index == #game.connected_players - 1 and #game.connected_players > votejail[griefer].index) - then + if votejail[griefer].index >= settings.votejail_count or (votejail[griefer].index == #game.connected_players - 1 and #game.connected_players > votejail[griefer].index) then Public.try_ul_data(griefer, true, votejail[griefer].actor, msg) end else @@ -329,10 +343,7 @@ local vote_to_free = function(player, griefer) votefree[griefer].index = votefree[griefer].index + 1 Utils.print_to(player, 'You have voted to free player ' .. griefer .. '.') - if - votefree[griefer].index >= settings.votejail_count or - (votefree[griefer].index == #game.connected_players - 1 and #game.connected_players > votefree[griefer].index) - then + if votefree[griefer].index >= settings.votejail_count or (votefree[griefer].index == #game.connected_players - 1 and #game.connected_players > votefree[griefer].index) then Public.try_ul_data(griefer, false, votefree[griefer].actor) votejail[griefer] = nil votefree[griefer] = nil @@ -573,10 +584,7 @@ Event.add( if player.admin or playtime >= settings.playtime_for_instant_jail then if cmd == 'jail' then if player.admin then - Utils.warning( - player, - 'Abusing the jail command will lead to revoked permissions. Jailing someone in case of disagreement is not OK!' - ) + Utils.warning(player, 'Abusing the jail command will lead to revoked permissions. Jailing someone in case of disagreement is not OK!') end Public.try_ul_data(griefer, true, player.name, message) return diff --git a/utils/datastore/message_on_join_data.lua b/utils/datastore/message_on_join_data.lua index c39a9416..00b6e817 100644 --- a/utils/datastore/message_on_join_data.lua +++ b/utils/datastore/message_on_join_data.lua @@ -19,7 +19,8 @@ local fetch = return end if type(value) == 'table' then - game.print('>> ' .. player.name .. ' << ' .. value.msg, value.color) + local message = string.gsub(value.msg, "{name}", player.name) + game.print(message, value.color) end end ) @@ -41,7 +42,7 @@ end commands.add_command( 'save-message', - 'Sets your custom join message.', + 'Sets your custom join message. "{name}" will be replaced with your username', function(cmd) local player = game.player if not player or not player.valid then diff --git a/utils/debug/main_view.lua b/utils/debug/main_view.lua index a2b074c4..1ba9f470 100644 --- a/utils/debug/main_view.lua +++ b/utils/debug/main_view.lua @@ -1,6 +1,5 @@ local Gui = require 'utils.gui' local Color = require 'utils.color_presets' -local Event = require 'utils.event' local Public = {} diff --git a/utils/debug/public_global_view.lua b/utils/debug/public_global_view.lua index 26c3f7a4..6a3c5c10 100644 --- a/utils/debug/public_global_view.lua +++ b/utils/debug/public_global_view.lua @@ -40,8 +40,7 @@ function Public.show(container) input_text_box_style.height = 32 input_text_box_style.maximal_width = 1000 - local refresh_button = - right_top_flow.add {type = 'sprite-button', name = refresh_name, sprite = 'utility/reset', tooltip = 'refresh'} + local refresh_button = right_top_flow.add {type = 'sprite-button', name = refresh_name, sprite = 'utility/reset', tooltip = 'refresh'} local refresh_button_style = refresh_button.style refresh_button_style.width = 32 refresh_button_style.height = 32 @@ -75,6 +74,11 @@ Gui.on_click( local left_panel = element.parent.parent local data = Gui.get_data(left_panel) + if not data then + return + end + + local right_panel = data.right_panel local selected_header = data.selected_header local input_text_box = data.input_text_box