diff --git a/config/_file_loader.lua b/config/_file_loader.lua index 186014e0..fcfd3392 100644 --- a/config/_file_loader.lua +++ b/config/_file_loader.lua @@ -51,6 +51,7 @@ return { 'modules.addons.report-jail', 'modules.addons.protection-jail', 'modules.addons.deconlog', + 'modules.addons.nukeprotect', --- Data 'modules.data.statistics', diff --git a/config/expcore/roles.lua b/config/expcore/roles.lua index 4ed31454..d1209fc6 100644 --- a/config/expcore/roles.lua +++ b/config/expcore/roles.lua @@ -223,7 +223,8 @@ Roles.new_role('Regular','Reg') 'command/go-to-spawn', 'command/me', 'standard-decon', - 'bypass-entity-protection' + 'bypass-entity-protection', + 'bypass-nukeprotect' } :set_auto_assign_condition(function(player) if player.online_time >= hours3 then diff --git a/config/nukeprotect.lua b/config/nukeprotect.lua new file mode 100644 index 00000000..42c9b9ad --- /dev/null +++ b/config/nukeprotect.lua @@ -0,0 +1,11 @@ +return { + ammo = { + ["atomic-bomb"] = true + }, -- @setting ammo The items to not allow in the player's ammo inventory + armor = {}, -- @setting armor The items to not allow in the player's armor inventory + gun = {}, -- @setting gun The items to not allow in the player's gun inventory + main = { + ["atomic-bomb"] = true + }, -- @setting main The items to not allow in the player's main inventory + ignore_permisison = "bypass-nukeprotect" -- @setting ignore_permisison The permission that nukeprotect will ignore +} diff --git a/locale/en/addons.cfg b/locale/en/addons.cfg index 1cac74dc..b034c052 100644 --- a/locale/en/addons.cfg +++ b/locale/en/addons.cfg @@ -83,3 +83,9 @@ jail=__1__ was jailed because they were reported too many times. Please wait for [protection-jail] jail=__1__ was jailed because they removed too many protected entities. Please wait for a moderator. + +[nukeprotect] +ammo=You cannot have __1__ in your ammo inventory, so it was placed into the chests at spawn. +armor=You cannot have __1__ in your armor inventory, so it was placed into the chests at spawn. +gun=You cannot have __1__ in your gun inventory, so it was placed into the chests at spawn. +main=You cannot have __1__ in your main inventory, so it was placed into the chests at spawn. \ No newline at end of file diff --git a/modules/addons/nukeprotect.lua b/modules/addons/nukeprotect.lua new file mode 100644 index 00000000..7037ecfd --- /dev/null +++ b/modules/addons/nukeprotect.lua @@ -0,0 +1,75 @@ +--- Disable new players from having certain items in their inventory, most commonly nukes +-- @addon Nukeprotect + +local Event = require 'utils.event' --- @dep utils.event +local Roles = require 'expcore.roles' --- @dep expcore.roles +local config = require 'config.nukeprotect' --- @dep config.nukeprotect +local move_items_stack = _C.move_items_stack --- @dep expcore.common + +Event.add(defines.events.on_player_ammo_inventory_changed, function(event) + local player = game.get_player(event.player_index) + + -- if the player has perms to be ignored, then they should be + if config.ignore_permisison and Roles.player_allowed(player, config.ignore_permisison) then return end + + local inv = player.get_inventory(defines.inventory.character_ammo) + + for i = 1, #inv do + local item = inv[i] + if item.valid and item.valid_for_read and config.ammo[item.name] then + player.print({ "nukeprotect.ammo", { "item-name." .. item.name } }) + move_items_stack({ item }) + end + end +end) + +Event.add(defines.events.on_player_armor_inventory_changed, function(event) + local player = game.get_player(event.player_index) + + -- if the player has perms to be ignored, then they should be + if config.ignore_permisison and Roles.player_allowed(player, config.ignore_permisison) then return end + + local inv = player.get_inventory(defines.inventory.character_armor) + + for i = 1, #inv do + local item = inv[i] + if item.valid and item.valid_for_read and config.armor[item.name] then + player.print({ "nukeprotect.armor", { "item-name." .. item.name } }) + move_items_stack({ item }) + end + end +end) + +Event.add(defines.events.on_player_gun_inventory_changed, function(event) + local player = game.get_player(event.player_index) + + -- if the player has perms to be ignored, then they should be + if config.ignore_permisison and Roles.player_allowed(player, config.ignore_permisison) then return end + + local inv = player.get_inventory(defines.inventory.character_guns) + + for i = 1, #inv do + local item = inv[i] + if item.valid and item.valid_for_read and config.gun[item.name] then + player.print({ "nukeprotect.gun", { "item-name." .. item.name } }) + move_items_stack({ item }) + end + end +end) + +Event.add(defines.events.on_player_main_inventory_changed, function(event) + local player = game.get_player(event.player_index) + + -- if the player has perms to be ignored, then they should be + if config.ignore_permisison and Roles.player_allowed(player, config.ignore_permisison) then return end + + local inv = player.get_inventory(defines.inventory.character_main) + + for i = 1, #inv do + local item = inv[i] + if item.valid and item.valid_for_read and config.main[item.name] then + player.print({ "nukeprotect.main", { "item-name." .. item.name } }) + move_items_stack({ item }) + end + end +end)