Hello. Can I disable brandish for all items in chests? I tried to write self:set_brandish_when_picked(false) in item script:
function item:on_created()
self:set_savegame_variable("bomb")
self:set_assignable(true)
self:set_brandish_when_picked(false)
end
But it works only for pickable treasures, and it doesn't work in chests. Why?
As its name implies, brandish_when_picked affects picked treasures.
You can customize when happens when a chest is open, using the chest:on_opened() event: http://www.solarus-games.org/doc/1.6/lua_api_chest.html#lua_api_chest_on_opened
Yes, I used chest:on_opened() event:
function bomb_chest:on_opened()
hero:start_treasure("bomb")
game:start_dialog("found.bombs", function()
sol.audio.play_sound("bombs")
end)
end
But all treasures in chests are always brandished. What to do?
Hmmm when there is a treasure in a chest, the hero always brandishes it. If you let the chest empty (no treasure), then really nothing happens and your on_opened() event can do what you want (including giving an item without brandishing it).
But when I start suggesting that, I realise that you are not really using any feature of chests anymore. So maybe you should use a custom entity instead.
PS: hero:start_treasure() does brandish the treasure. Use game:get_item("thing"):set_variant/amout() to give an item silently.
And he should also define that function in the metatable, so that he does it only once. In case of more info needed in that function, he can use the custom properties in the editor.
Custom properties are a new feature of 1.6, so not released yet.
Christopho, I tried to do so:
function bomb_chest:on_opened()
game:get_item("bomb"):set_variant(1)
hero:unfreeze()
game:start_dialog("found.bombs", function()
sol.audio.play_sound("bombs")
end)
end
But it doesn't work and game isn't giving bombs to hero. Yes, I see the dialog, I hear my hero says "Bombs!", but slot is empty. I just want to put some things in chests, but without brandish. Tomorrow will try to experiment with custom entities :D
I think you may have a confusion between your bomb item and your bomb counter.
If you replace "bomb" by a simpler item in your code (like "lamp"), I guess it will work.
Bombs like the bow & arrows: in my games, I have
- an item for the bow (which is saved and has a counter),
- another item for arrows (which is not saved but its effect is to increase the bow counter),
- and even a third one for the quiver (which is saved and whose effect is to change the maximum value of the bow counter).
It may seem complicated, but when you think about it, you don't have a lot of other choices.
Bombs work exactly the same in my games:
- an item "bombs_counter" for the bombs counter (which is saved and has a counter),
- another item "bomb" for individual bombs (which is not saved but its effect is to increase the bombs counter),
- and even a third one "bomb_bag" (which is saved and whose effect is to change the maximum value of the bombs counter).
So, once you understand that, it does not make sense to set the variant of item "bomb" to 1, since it is not an item that has a saved possession state (assuming your items are named like mine!). So, I guess you should just change the amount of the bombs counter instead of trying to give a bomb item.
game:get_item("bombs_counter"):add_amount(1)