Page 1 of 1

[SOLVED] Edit starting inventory

Posted: Sun May 26, 2024 4:42 pm
by DannyDavidDJ
Help, I've been trying to edit starting inventory.
Remove starter items on Freeplay and add new ones.

I tried pasting code from other discussions but nothing helped
Could anyone help me with code for Control.lua and any other necessary with code and files i need?

(also, if you could explain how it works, that would be great)

Thanks in advance :)

Re: Edit starting inventory

Posted: Sun May 26, 2024 6:20 pm
by mmmPI
Maybe you'd have more chance taking example on a mod that does something similar to what you want to achieve, one whose license allows taking example :)

As of now there is very little information you are giving that could help diagnose the problems

Re: Edit starting inventory

Posted: Sun May 26, 2024 7:20 pm
by DannyDavidDJ
I want to change players starting inventory when starting a new game.

I tried that.
script.on_event(defines.events.on_player_created, function(event)
local player = game.players[event.player_index]
player.insert({name="iron-plate", count=800})
end)
No errors or anything, but it doesn't work.

There's something i'm doing wrong? Maybe i missed something?

Re: Edit starting inventory

Posted: Sun May 26, 2024 7:38 pm
by mmmPI
I can't say for sure, but it seem you are not inserting item in the inventory as it's done in this mod :
https://github.com/brevven/CarStart/blo ... ontrol.lua

Re: Edit starting inventory

Posted: Sun May 26, 2024 7:53 pm
by DannyDavidDJ
It works! I've been trying for hours haha :D

Thank you so much!

One more thing, do you also know how to delete starting items? Factorio gives some stuff and i would like to get rid of them

Re: Edit starting inventory

Posted: Sun May 26, 2024 8:22 pm
by mmmPI

Re: Edit starting inventory

Posted: Sun May 26, 2024 8:52 pm
by DannyDavidDJ
Thank you so much!

although now, the script that delete items won't let me spawn with other items i want ^^;

Re: Edit starting inventory

Posted: Mon May 27, 2024 7:41 am
by DannyDavidDJ
SOLVED

If anyone need help with this, here's the code

it was that simple...
-- Clear the player inventory
local function clear_inv(e)
local player = game.players[e.player_index]
player.clear_items_inside()
player.insert{name = "car", count = 1}
end

-- Disable the crash site and skip cutscene
local function disable_crash()
-- If we're in freeplay, disable the crash site

if remote.interfaces["freeplay"] then
remote.call("freeplay", "set_disable_crashsite", true)
end
end

script.on_event(defines.events.on_player_created, clear_inv) -- on player created
script.on_init(disable_crash) -- on mod init


Thanks everyone for help! :D

Re: [SOLVED] Edit starting inventory

Posted: Wed May 29, 2024 11:11 pm
by Gweneph
There's also a freeplay interface for setting the starting items if you want to use that.

You can check in base/scenarios/freeplay/freeplay.lua for how to call it.

Re: [SOLVED] Edit starting inventory

Posted: Thu May 30, 2024 2:24 pm
by Pi-C
Gweneph wrote:
Wed May 29, 2024 11:11 pm
There's also a freeplay interface for setting the starting items if you want to use that.
But this interface will only be available if the "Freeplay" scenario is used. You can get the active scenario by reading script.level.

Re: [SOLVED] Edit starting inventory

Posted: Thu May 30, 2024 5:49 pm
by DannyDavidDJ
It's fine, It's solved. But thanks for everything :D

Re: [SOLVED] Edit starting inventory

Posted: Fri Jun 07, 2024 3:15 am
by codyfactorio