[Solved]How to add an "opening" animation for chests?

Started by froggy77, May 07, 2017, 08:06:50 PM

Previous topic - Next topic
You will need to do something similar for NPCs, and many other types of interactions with other entities (switches, carried entities, etc). That is a lot of work.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

The switch I have already basically done, but only for stepping on. I do not plan to make all the entities except for when it is simple or when I need it for animation purposes. I probably will not have a second player feature because it is not something I want with my games, but in some cases simple second player features can be useful.  For example, when you want an entity to step on a switch or to move a block that can only be pushed from their side.

Thanks for the time spent. I just needed advice, not a brainstorming.  ;)
I would like to use the editor to create the chest normally; maybe it could be disabled and replaced by an entity during the opening and at the end enabled to appear when completely opened. I will try to write a script even I lost my poor level in lua.

I did posted the solution on page 1, it does replace the default chest by a custom entity, you might do some tweaks to make it properly work to your needs though

June 18, 2017, 01:10:07 PM #19 Last Edit: June 20, 2017, 12:26:15 AM by froggy77
Thank you MetalZelda, I did not understand where to put those scripts and I did not realize that there was no need to create an entity from the editor.
Even if I managed to make it work, I found some problems.


       
  • If there is no treasure_savegame_variable, then there are these error messages:
Error: In on_created: [string "entities/chest/chest.lua"]:23: bad argument #1 to is_open (string expected, got nil))
Error: In on_interaction: [string "entities/chest/chest.lua"]:44: bad argument #1 to is_open (string expected, got nil))


       
  • If there is a treasure_savegame_variable but no treasure, then there is the following error message
Error: In sprite callback: [string "entities/chest/chest.lua"]:52: bad argument #1 to start_treasure (string expected, got nil))
This one is not a problem.


       
  • If there is no delay for "opening" animation in "delay between frames", then nothing happens: no error message, no treasure, "hero:unfreeze()" does not start.
In order to correct this, I added a value for "delay between frames", for example: 200 ms.


       
  • hero:freeze() and hero:unfreeze() seem not to be necessary.

To make this work you need to create a chest entity, not a custom entity, the script do the rest (delete the chest and create the custom entity).

You need to define the sprite, treasure and savegame variable from there, like this



But, it is very basic atm, the entity name could be used to store frame delays or other stuffs