Page 1 of 1

[Solved] How to apply animated graphics to chest?

Posted: Sun Jan 20, 2019 5:46 pm
by Schallfalke
Hi all,

I want to apply animation to a chest (something like assembling machine, radar, turret, etc). I am using entity type "container" and "logistic-container" for it.
But I found out it supports only the property "picture", where I cannot use sub-properties like "frame_count" to apply animated graphics. (I know a lot on how to do animations on turrets though.)

1) Is there any way to apply animated graphics? Or how to get around the restriction?
2) Are there are any entity type that has the inventory/storage slots? I can change the entity type from "container" if it is needed.

Re: How to apply animated graphics to chest?

Posted: Sun Jan 20, 2019 5:54 pm
by DaveMcW
You have to use two entities, one for the chest and one for the animation.

And then a bunch of control.lua code to make sure both entities are placed and removed together.

Re: How to apply animated graphics to chest?

Posted: Sun Jan 20, 2019 6:02 pm
by Schallfalke
Does it mean I have to use some script to place an additional "animated entity" (like radar type) when item is placed, and remove the additional when it is mined?

I am not sure if it is tricky or not to place an entity on top of another. Can you show me some code on how to do that?

Re: How to apply animated graphics to chest?

Posted: Sun Jan 20, 2019 7:03 pm
by darkfrei
prototype.pictures[1].priority = "extra-high"

It must be here https://wiki.factorio.com/Prototype/Entity but it does not. Same is here https://wiki.factorio.com/Types/RotatedSprite#priority

Re: How to apply animated graphics to chest?

Posted: Sun Jan 20, 2019 7:30 pm
by Bilka
darkfrei wrote:
Sun Jan 20, 2019 7:03 pm
prototype.pictures[1].priority = "extra-high"
That has nothing to do with sprite drawing. It determines into what sprite atlas the sprite is put.

Re: How to apply animated graphics to chest?

Posted: Sun Jan 20, 2019 10:51 pm
by Schallfalke
DaveMcW wrote:
Sun Jan 20, 2019 5:54 pm
You have to use two entities, one for the chest and one for the animation.

And then a bunch of control.lua code to make sure both entities are placed and removed together.
I have just tried that and it works, thanks for the suggestion.
I am now using a chest entity as "main" part. And a radar entity as animation part, which only creates when on_built_entity or on_robot_built_entity is called. (Similar for removal.)

But then a new problem arise. When holding the item in hand, the "green tint hover" (I don't know what it is called) only shows the chest entity sprite, without the radar entity sprite. It is the same problem, when ghosts are being placed, and in blueprints.
Is there a way to solve this too?

Re: How to apply animated graphics to chest?

Posted: Sun Jan 20, 2019 10:59 pm
by DaveMcW
You could use a third entity that is a combination of both graphics, then destroy/replace it in on_built.

The nice thing is you can set main_entity.minable.result = "third_entity" so it goes back to the combined version when mined.

The only tricky part is blueprints, you will have to search/replace "main_entity" to "third_entity" in on_player_configured_blueprint.

Re: How to apply animated graphics to chest?

Posted: Mon Jan 21, 2019 9:50 am
by Schallfalke
Wow! You are so talented, thinking outside the box. :idea:

I have never tried modifying blueprint. This is a totally new area to me, it will take some time for me to look into that.

Have a new problem though. I want to set the radar-part entity to be invulnerable or "hide" from biters. Tried a few solutions but none of them works (biters still found and destroyed the radar entity), which include:
  • Setting prototype health to nil. (Setting zero reports error at game loading stage; setting to nil actually sets 10 health.)
  • Setting prototype collision box to {{0, 0}, {0, 0}}.
  • Setting property at surface.create_entity with destructible = false.
Is there any way to set entity invulnerability?

Re: How to apply animated graphics to chest?

Posted: Wed Jan 30, 2019 6:08 pm
by Schallfalke
I have successfully set invulnerability by setting after surface.create_entity line, instead of within function.

Thanks for all the help!