-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #229 from oof2win2/feature/nukeprotect
Implement nuke protect, fix move_items
- Loading branch information
Showing
6 changed files
with
128 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
return { | ||
inventories = { | ||
{ | ||
inventory = defines.inventory.character_ammo, | ||
event = defines.events.on_player_ammo_inventory_changed, | ||
items = { | ||
["atomic-bomb"] = true | ||
}, | ||
}, | ||
{ | ||
inventory = defines.inventory.character_armor, | ||
event = defines.events.on_player_armor_inventory_changed, | ||
items = {}, | ||
}, | ||
{ | ||
inventory = defines.inventory.character_guns, | ||
event = defines.events.on_player_gun_inventory_changed, | ||
items = {}, | ||
}, | ||
{ | ||
inventory = defines.inventory.character_main, | ||
event = defines.events.on_player_main_inventory_changed, | ||
items = { | ||
["atomic-bomb"] = true | ||
}, | ||
}, | ||
}, | ||
ignore_permisison = "bypass-nukeprotect", -- @setting ignore_permisison The permission that nukeprotect will ignore | ||
ignore_admins = true, -- @setting ignore_admins Ignore admins, true by default. Allows usage outside of the roles module | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- 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 | ||
|
||
|
||
local function check_items(player, type) | ||
-- 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 | ||
-- if the players | ||
if config.ignore_admins and player.admin then return end | ||
|
||
local inventory = player.get_inventory(type) | ||
for i = 1, #inventory do | ||
local item = inventory[i] | ||
if item.valid and item.valid_for_read and config[tostring(type)][item.name] then | ||
player.print({ "nukeprotect.found", { "item-name." .. item.name } }) | ||
-- insert the items into the table so all items are transferred at once | ||
move_items_stack({ item }) | ||
end | ||
end | ||
end | ||
|
||
for _, inventory in ipairs(config.inventories) do | ||
if #inventory.items > 0 then | ||
Event.add(inventory.event, function(event) | ||
local player = game.get_player(event.player_index) | ||
if player and player.valid then | ||
check_items(player, inventory.inventory) | ||
end | ||
end) | ||
end | ||
end |