Solarus-Games English Forum

Solarus => Development => Topic started by: Dokk on August 20, 2018, 12:19:11 PM

Title: Disable brandish for all items in chests
Post by: Dokk on August 20, 2018, 12:19:11 PM
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?
Title: Re: Disable brandish for all items in chests
Post by: Christopho on August 20, 2018, 12:27:12 PM
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
Title: Re: Disable brandish for all items in chests
Post by: Dokk on August 20, 2018, 04:10:11 PM
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?
Title: Re: Disable brandish for all items in chests
Post by: Christopho on August 20, 2018, 04:30:43 PM
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.
Title: Re: Disable brandish for all items in chests
Post by: Diarandor on August 20, 2018, 05:13:14 PM
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.
Title: Re: Disable brandish for all items in chests
Post by: Christopho on August 20, 2018, 05:34:36 PM
Custom properties are a new feature of 1.6, so not released yet.
Title: Re: Disable brandish for all items in chests
Post by: Dokk on August 20, 2018, 08:45:25 PM


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
Title: Re: Disable brandish for all items in chests
Post by: Christopho on August 20, 2018, 09:30:39 PM
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.

Code (lua) Select

game:get_item("bombs_counter"):add_amount(1)