Is It Possible to Change the Player Starting Equipment?
-
- Inserter
- Posts: 23
- Joined: Thu Jan 22, 2015 8:22 pm
- Contact:
Is It Possible to Change the Player Starting Equipment?
Can I change the starting equipment of the player somehow?
Re: Is It Possible to Change the Player Starting Equipment?
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)
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
I also update mods, some of them even work.
Recently I did a mod tutorial.
-
- Inserter
- Posts: 23
- Joined: Thu Jan 22, 2015 8:22 pm
- Contact:
Re: Is It Possible to Change the Player Starting Equipment?
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)
Re: Is It Possible to Change the Player Starting Equipment?
There will be probably some simply solution, i think DyTech override starting items so you could check it. I never done it but 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.
Re: Is It Possible to Change the Player Starting Equipment?
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)
-
- Filter Inserter
- Posts: 358
- Joined: Fri Jul 25, 2014 2:53 pm
- Contact:
Re: Is It Possible to Change the Player Starting Equipment?
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)
Check out my mods
Re: Is It Possible to Change the Player Starting Equipment?
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)
For MP you have to loop through all players.
Btw is game.player.character really required? Shouldn't it work with game.player only?
Because in sandbox there is no character attached to the player, so it will also throw an error.
Re: Is It Possible to Change the Player Starting Equipment?
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?
Re: Is It Possible to Change the Player Starting Equipment?
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.
But yes, I was too fast. Obviously if onPlayerCreated returns the playerIndex it isn't needed to iterate through all players. You can get the explicit player from the array directly.
Re: Is It Possible to Change the Player Starting Equipment?
Here's a list of events with playerindex (as of 11.11)drs9999 wrote:...
playerindex events