mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 19:45:22 +09:00
Added ExpGamingAdmin
This commit is contained in:
58
modules/ExpGamingAdmin/ClearInventory/control.lua
Normal file
58
modules/ExpGamingAdmin/ClearInventory/control.lua
Normal file
@@ -0,0 +1,58 @@
|
||||
--- Desction <get from json>
|
||||
-- @module ExpGamingAdmin.ClearInventory@4.0.0
|
||||
-- @author <get from json>
|
||||
-- @license <get from json>
|
||||
-- @alais ThisModule
|
||||
|
||||
-- Module Require
|
||||
local Admin = require('ExpGamingAdmin.AdminLib@^4.0.0')
|
||||
local Game = require('FactorioStdLib.Game@^0.8.0')
|
||||
|
||||
-- Module Define
|
||||
local module_verbose = false
|
||||
local ThisModule = {}
|
||||
|
||||
-- Function Define
|
||||
local inventorys = {
|
||||
defines.inventory.player_main,
|
||||
defines.inventory.player_quickbar,
|
||||
defines.inventory.player_trash,
|
||||
defines.inventory.player_guns,
|
||||
defines.inventory.player_ammo,
|
||||
defines.inventory.player_armor
|
||||
}
|
||||
|
||||
function Admin.move_item_to_spawn(item,surface,chests)
|
||||
local chests = chests or surface.find_entities_filtered{area={{-10,-10},{10,10}},name='iron-chest'} or {}
|
||||
local chest = nil
|
||||
while not chest or not chest.get_inventory(defines.inventory.chest).can_insert(item) do
|
||||
chest = table.remove(chests,1)
|
||||
if not chest then chest = surface.create_entity{
|
||||
name='iron-chest',
|
||||
position=surface.find_non_colliding_position('iron-chest',{0,0},32,1)
|
||||
} end
|
||||
end
|
||||
chest.get_inventory(defines.inventory.chest).insert(item)
|
||||
table.insert(chests,chest)
|
||||
return chests
|
||||
end
|
||||
|
||||
function Admin.move_inventory(player)
|
||||
local player = Game.get_player(player)
|
||||
if not player then return end
|
||||
local chests = player.surface.find_entities_filtered{area={{-10,-10},{10,10}},name='iron-chest'} or {}
|
||||
for _,_inventory in pairs(inventorys) do
|
||||
local inventory = player.get_inventory(_inventory)
|
||||
if inventory then
|
||||
for item,count in pairs(inventory.get_contents()) do
|
||||
local item = {name=item,count=count}
|
||||
chests = Admin.move_item_to_spawn(item,player.surface,chests)
|
||||
end
|
||||
inventory.clear()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Admin.add_action('Clear Inventory',Admin.move_inventory)
|
||||
-- Module Return
|
||||
return ThisModule
|
||||
Reference in New Issue
Block a user