Author Topic: Disable brandish for all items in chests  (Read 130 times)

Dokk

  • Newbie
  • *
  • Posts: 7
  • Game developer & musician
    • View Profile
Disable brandish for all items in chests
« 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:

Code: [Select]
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?
I'm making first russian quest on SE

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1130
    • View Profile
Re: Disable brandish for all items in chests
« Reply #1 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
« Last Edit: August 20, 2018, 04:31:11 pm by Christopho »

Dokk

  • Newbie
  • *
  • Posts: 7
  • Game developer & musician
    • View Profile
Re: Disable brandish for all items in chests
« Reply #2 on: August 20, 2018, 04:10:11 pm »
Yes, I used chest:on_opened() event:

Code: [Select]

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?
I'm making first russian quest on SE

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1130
    • View Profile
Re: Disable brandish for all items in chests
« Reply #3 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.
« Last Edit: August 20, 2018, 04:32:43 pm by Christopho »

Diarandor

  • Hero Member
  • *****
  • Posts: 1008
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Disable brandish for all items in chests
« Reply #4 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.
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1130
    • View Profile
Re: Disable brandish for all items in chests
« Reply #5 on: August 20, 2018, 05:34:36 pm »
Custom properties are a new feature of 1.6, so not released yet.

Dokk

  • Newbie
  • *
  • Posts: 7
  • Game developer & musician
    • View Profile
Re: Disable brandish for all items in chests
« Reply #6 on: August 20, 2018, 08:45:25 pm »


Christopho, I tried to do so:

Code: [Select]

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'm making first russian quest on SE

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1130
    • View Profile
Re: Disable brandish for all items in chests
« Reply #7 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
  1. game:get_item("bombs_counter"):add_amount(1)
« Last Edit: August 20, 2018, 09:32:47 pm by Christopho »