Page 1 of 1
insert items in active armor
Posted: Fri Jan 06, 2017 9:14 am
by mophydeen
Is it possible to insert items into the armor?
Code: Select all
player.insert{name="power-armor", count=1}
-- instead of in the player, imidiately inside the armor
player.insert{name="personal-roboport-equipment", count=2}
player.insert{name="fusion-reactor-equipment", count=1}
Re: insert items in active armor
Posted: Fri Jan 06, 2017 11:25 am
by mophydeen
Code: Select all
local armorname = "power-armor"
if player.get_inventory(defines.inventory.player_armor).can_insert(armorname) then
player.insert(armorname)
local armorSlot = player.get_inventory(defines.inventory.player_armor)
if (not armorSlot.is_empty()) then
for j = 1, #armorSlot do
if armorSlot[j].valid_for_read and armorSlot[j].name == armorname then
local armor = armorSlot[j]
game.print("armor active inventory : " .. armor.get_inventory(defines.inventory.item_active)) -- CRASH HERE : LINE 99
game.print("armor main inventory : " .. armor.get_inventory(defines.inventory.item_main))
local armorinventory = armor.get_inventory(defines.inventory.item_active)
local freactor = {name="fusion-reactor-equipment", count=1}
if armorinventory.can_insert(freactor) then
armorinventory.insert(freactor)
end
local proboport = {name="personal-roboport-equipment", count=2}
if armorinventory.can_insert(proboport) then
armorinventory.insert(proboport)
end
end
end
end
end
Code: Select all
Error while running event on_player_joined_game (ID 43)
Given item is not an ItemWithInventory.
stack traceback:
...l/Downloads/factorio/temp/currently-playing/sl_utils.lua:99: in function 'givePlayerItems'
...l/Downloads/factorio/temp/currently-playing/sl_utils.lua:151: in function 'givePlayerStarterItems'
...l/Downloads/factorio/temp/currently-playing/sl_utils.lua:393: in function 'playerSpawnItems'
...sl/Downloads/factorio/temp/currently-playing/control.lua:195: in function <...sl/Downloads/factorio/temp/currently-playing/control.lua:177
Re: insert items in active armor
Posted: Fri Jan 06, 2017 11:48 am
by Nexela
You need to use LuaGrid and .put
this is making assumptions on validity of slots, but it should point you in the right direction
Code: Select all
local inv = player.get_inventory(defines.inventory.player_armor)
inv.insert("power-armor-mk2")
local armor = inv[1].grid
armor.put{name="fusion-reactor-equipment"}
armor.put{name="personal-roboport-equipment"}
end
Re: insert items in active armor
Posted: Fri Jan 06, 2017 11:49 am
by Adil
Armor has a grid, not inventory.
Code: Select all
if armor.grid then
armor.grid.put({name="fusion-reactor-equipment"})
end
Re: insert items in active armor
Posted: Fri Jan 06, 2017 12:11 pm
by mophydeen
Thank you
Re: insert items in active armor
Posted: Fri Jan 06, 2017 5:04 pm
by cpeosphoros
Adil wrote:Armor has a grid, not inventory.
Code: Select all
if armor.grid then
armor.grid.put({name="fusion-reactor-equipment"})
end
Have a look at
https://mods.factorio.com/mods/arumba/A ... ated_Start code.
Basically, it does armor.grid.put, but has some nice tricks there.