Lua Command - Add item to named player inventory

Place to get help with not working mods / modding interface.
DocHoss333
Burner Inserter
Burner Inserter
Posts: 6
Joined: Thu Jan 23, 2025 4:25 pm
Contact:

Lua Command - Add item to named player inventory

Post by DocHoss333 »

I'm just dipping my toes into scripting in Factorio and I can't seem to find an answer to this question directly...I want to add an item into a player's inventory in a multiplayer game. Say the character's name is "jim123"...what console command can I run to give "jim123" a stack of iron plate, for instance? All the examples I can find manipulate the inventory of the player who is playing, but I'm wanting to do this from an admin session (specifically an RCON connection, but I don't think that's really important here...right?).
robot256
Smart Inserter
Smart Inserter
Posts: 1163
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Lua Command - Add item to named player inventory

Post by robot256 »

Replace `game.player` with `game.players["player-name"]`
DocHoss333
Burner Inserter
Burner Inserter
Posts: 6
Joined: Thu Jan 23, 2025 4:25 pm
Contact:

Re: Lua Command - Add item to named player inventory

Post by DocHoss333 »

Nailed it. Thanks!
DocHoss333
Burner Inserter
Burner Inserter
Posts: 6
Joined: Thu Jan 23, 2025 4:25 pm
Contact:

Re: Lua Command - Add item to named player inventory

Post by DocHoss333 »

A follow up question...how do you add items at different quality levels? Say I want to add rare iron plates...is that a property of the item insert command or is it treated as a separate item?

Example:
This inserts items into the named player's inventory. How would I modify this command to make the iron plates rare?

/c game.players["player"].insert{name = "iron-plate", count = 100}

EDIT: think I answered my own question by looking more carefully at the modding docs. Should be this...

/c game.players["player"].insert{name = "iron-plate", count = 100, quality = "rare"}
Post Reply

Return to “Modding help”