Is It Possible to Change the Player Starting Equipment?
Posted: Sat Jan 24, 2015 7:42 am
Can I change the starting equipment of the player somehow?
www.factorio.com
https://forums.factorio.com/
Code: Select all
game.onevent(defines.events.onplayercreated, function(event)
local player = game.getplayer(event.playerindex)
player.insert{name="iron-plate", count=8}
player.insert{name="pistol", count=1}
player.insert{name="basic-bullet-magazine", count=10}
player.insert{name="burner-mining-drill", count = 1}
player.insert{name="stone-furnace", count = 1}
if (#game.players <= 1) then
game.showmessagedialog{text = {"msg-intro"}}
end
end)
How do I use a mod to clear items from the inventory or prevent them from being added?Adil wrote:Example from factorio/data/base/scenarios/freeplay/control.lua :Either tweak those, or make your own mod folder in type analogous code there.Code: Select all
game.onevent(defines.events.onplayercreated, function(event) local player = game.getplayer(event.playerindex) player.insert{name="iron-plate", count=8} player.insert{name="pistol", count=1} player.insert{name="basic-bullet-magazine", count=10} player.insert{name="burner-mining-drill", count = 1} player.insert{name="stone-furnace", count = 1} if (#game.players <= 1) then game.showmessagedialog{text = {"msg-intro"}} end end)
From what I've seen this is the case, you can useKexík wrote:i think starting items from base factorio should be in inventory when your mod defines.events.onplayercreated is called, so you could check player inventory and delete them if they are there.
Code: Select all
require "defines"
game.onevent(defines.events.onplayercreated, function(event)
-- "hard" way shown, easy way would be getting the player and use player.removeitem with the name and a high count
local inventory = game.players[event.playerindex].getinventory(defines.inventory.playermain)
-- at this point you could call "inventory.clear()" if you wanted to delete everything in the main inventory
-- other inventories are also defined in the defines.lua file (data/core/lualib/defines.lua)
local contents = inventory.getcontents()
for name, count in pairs(contents) do
if name == "name of item to remove" or name == "name of another item to remove" then
inventory.remove({name=name, count=count})
end
end
-- can insert with inventory.insert({name="item-name", count=some_count})
end)
Code: Select all
game.onevent(defines.events.onplayercreated, function(event)
local character = game.player.character
character.clearitemsinside()
character.insert{name="stone-axe", count=1}
end)
But only in SPcartmen180 wrote:this clears anything the character is given when starting a new game and adds what you want, in this case a stone axe.Code: Select all
game.onevent(defines.events.onplayercreated, function(event) local character = game.player.character character.clearitemsinside() character.insert{name="stone-axe", count=1} end)
Slight issue here, it will only work in single player. MP would need to use game.player[event.playerindex] instead (btw, I'd forgotten about the clearitemsinside method, and the wiki shows it on the player but testing shows it works on the character too, hm wiki version history has "LuaEntity::clearitemsinside and getitemcount works on all entities (hopefully)" on 5.0 so I should have looked harder lol).cartmen180 wrote:game.player.character
??? what, why? Especially during onplayercreated that doesn't make sense to me.drs9999 wrote:For MP you have to loop through all players.
yes, it does. Which is nice for compatibility with sandboxdrs9999 wrote:Shouldn't it work with game.player only?
game.player doesn't exist in mp-games it is game.players then , where players is an array that contains all player.FreeER wrote:??? what, why? Especially during onplayercreated that doesn't make sense to me.
Here's a list of events with playerindex (as of 11.11)drs9999 wrote:...