prototype for starting inventory
Posted: Fri Oct 26, 2018 10:59 am
Hello,
Currently, I believe the only way to change the starting player's inventory is to handle the on_player_created event, and then use methods such as clear_items_inside() and insert() to modify it.
At a basic level this works, but it appears the game or at least the UI will act upon the new equipment before the event fires. The player experiences this by seeing the inventory stacks flash, as if items have been added, even when they are made empty by a mod.
There are other bug possibilities with this approach. If one mod sees the player inventory before a further mod changes it, then it might act upon the inventory in a way that causes problems for the other mod. Given that the event handler ordering is (as far as I know) still alphabetical rather than dependency ordered, it is difficult for mods to coordinate their starting inventory changes to prevent these issues. A good example would be a mod that forcibly remove all things from the player so they have to gather and craft everything. It would not be able to ensure it does its job if any other mod adds starting items. It'd be much cleaner if we could modify the starting items before they are added and act in mod dependency order.
My thinking is, that having a prototype for the starting inventory would solve all these problems. I mean I wouldn't be surprised if it already exists but I couldn't find it? A further benefit, I imagine many modders are more comfortable with data.lua than control.lua, it can be used by designers as well as programmers. The current approach would still be available for mods that really need a programmatic way to manipulate inventory, e.g. different players get different items.
Regards
H8UL
Currently, I believe the only way to change the starting player's inventory is to handle the on_player_created event, and then use methods such as clear_items_inside() and insert() to modify it.
At a basic level this works, but it appears the game or at least the UI will act upon the new equipment before the event fires. The player experiences this by seeing the inventory stacks flash, as if items have been added, even when they are made empty by a mod.
There are other bug possibilities with this approach. If one mod sees the player inventory before a further mod changes it, then it might act upon the inventory in a way that causes problems for the other mod. Given that the event handler ordering is (as far as I know) still alphabetical rather than dependency ordered, it is difficult for mods to coordinate their starting inventory changes to prevent these issues. A good example would be a mod that forcibly remove all things from the player so they have to gather and craft everything. It would not be able to ensure it does its job if any other mod adds starting items. It'd be much cleaner if we could modify the starting items before they are added and act in mod dependency order.
My thinking is, that having a prototype for the starting inventory would solve all these problems. I mean I wouldn't be surprised if it already exists but I couldn't find it? A further benefit, I imagine many modders are more comfortable with data.lua than control.lua, it can be used by designers as well as programmers. The current approach would still be available for mods that really need a programmatic way to manipulate inventory, e.g. different players get different items.
Regards
H8UL