From 854753e4afe1002f659e41b4c64826d5024c1f89 Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Mon, 14 Apr 2025 19:55:57 +0200 Subject: Clears inventory if player picks up item --- von-newmann-2/control.lua | 49 +++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/von-newmann-2/control.lua b/von-newmann-2/control.lua index e1b5004..0bd741d 100644 --- a/von-newmann-2/control.lua +++ b/von-newmann-2/control.lua @@ -224,7 +224,7 @@ local function create_roboport(center, surface, player) end end -local function update_inventory() +local function clear_inventory() if not mod_enabled then return end @@ -243,29 +243,23 @@ local function on_player_created(event) local player = game.get_player(event.player_index) local character = player.character - - local group = player.permission_group or game.permissions.create_group("NO_INVENTORY") - group.set_allows_action(defines.input_action.craft,false) - --group.set_allows_action(defines.input_action.destroy_item,false) - --group.set_allows_action(defines.input_action.destroy_opened_item,false) - group.set_allows_action(defines.input_action.drop_item,false) - group.set_allows_action(defines.input_action.inventory_transfer,false) - group.set_allows_action(defines.input_action.inventory_split,false) - group.set_allows_action(defines.input_action.cursor_transfer,false) - group.set_allows_action(defines.input_action.cursor_split,false) - group.set_allows_action(defines.input_action.fast_entity_split,false) - group.set_allows_action(defines.input_action.fast_entity_transfer,false) - group.set_allows_action(defines.input_action.stack_split,false) - group.set_allows_action(defines.input_action.stack_transfer,false) - --group.set_allows_action(defines.input_action.use_item,false) - group.set_allows_action(defines.input_action.begin_mining,false) - group.set_allows_action(defines.input_action.begin_mining_terrain,false) - --group.set_allows_action(defines.input_action.smart_pipette,false) - group.name = "NO_INVENTORY" + local group_name = "NO_INVENTORY" + + local group = player.permission_group or game.permissions.create_group(group_name) + group.set_allows_action(defines.input_action.begin_mining, false) + group.set_allows_action(defines.input_action.begin_mining_terrain, false) + group.set_allows_action(defines.input_action.craft, false) + group.set_allows_action(defines.input_action.cursor_split, false) + group.set_allows_action(defines.input_action.cursor_transfer, false) + group.set_allows_action(defines.input_action.drop_item, false) + group.set_allows_action(defines.input_action.fast_entity_split, false) + group.set_allows_action(defines.input_action.fast_entity_transfer, false) + group.set_allows_action(defines.input_action.inventory_split, false) + group.set_allows_action(defines.input_action.inventory_transfer, false) + group.set_allows_action(defines.input_action.stack_split, false) + group.set_allows_action(defines.input_action.stack_transfer, false) + group.name = group_name group.add_player(player) - --player.print(player.permission_group.allows_action(defines.input_action.inventory_transfer)) - - --player.get_main_inventory().resize(0) local center = player.character.position player.character = nil @@ -286,7 +280,7 @@ local function on_player_created(event) util.remove_safe(player, crashed_debris_items) -- player.get_main_inventory().sort_and_merge() - update_inventory() + clear_inventory() local area = {{center.x + 10, center.y + 15}, {center.x - 10, center.y - 15}} clear_area(area, surface) create_roboport(center, surface, player) @@ -364,5 +358,10 @@ script.on_init(function () script.on_event(defines.events.on_player_created, on_player_created) script.on_event(defines.events.on_player_changed_position, on_player_changed_position) - script.on_configuration_changed(update_inventory) + -- I can't prevent a player with a 'nil' character to pick up items from belts or the ground. + -- The following just empties the inventory in case an item is picked. + -- It's highly recommended to disable the 'F' shorcut in 'Settings -> Controls' when playing with this mod. + -- Hopefully in the future I'll find a better way to do this. + script.on_event(defines.events.on_picked_up_item, function(event) clear_inventory() end) + script.on_configuration_changed(clear_inventory) end) -- cgit v1.2.1