Sprite Sheet Controlled On How Many Items Are In The Entity

Place to get help with not working mods / modding interface.
Post Reply
Suf
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Fri Jul 10, 2020 5:07 am
Contact:

Sprite Sheet Controlled On How Many Items Are In The Entity

Post by Suf »

Hi

I've been searching for events https://lua-api.factorio.com/latest/events.html related if the entity has specific number of items and i found the closest event is "on_player_fast_transferred" to what i'm after here,but the problem it's only fast transferred which i'm assuming is when the player puts/takes the items without actually open entity GUI.Also i've checked https://lua-api.factorio.com/latest/LuaEntity.html to make sure there's no extra events that can be in replace of "on_player_fast_transferred"

now here's the code that i haven't tested yet,you can treat it as an example of what i'm trying to do here

Code: Select all

global = global or {}
global.item_count = 0

script.on_event(defines.events.on_player_fast_transferred, function(event) --the problem here is this script Called when a player fast-transfers something to or from an entity,i need this script Only works if the player puts the items into the entity
	global.item_count= global.item_count + 1
	if global.item_count == 200 then
        filename = "__base__/graphics/entity/lab/lab1.png", --i'm assuming this will update the sprite sheet of entity in this case lab to lab 1.png which the modder adds extra detail to the original lab, and i'm not sure if this actually works like that i think it needs an image load code which i haven't searched for yet
	end
end, {
	{filter = "type", type = "tool"},
	{filter = "name", name = "automation-science-pack"},--all of this code should be called if the lab has 200 automation science packs
})
})
And that's it;the question here does this idea work in Factorio or not.and yeah i haven't tested this because i haven't made the entity that will replace the lab yet but the example should be suffice of what my idea here.

Thanks in Advance

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Sprite Sheet Controlled On How Many Items Are In The Entity

Post by eradicator »

What you're trying to do is not supported by the API. There are no events for non-player inventory changes. You can not change the graphic of an entity at runtime. You'd have to use various hacks and workarounds. Not an easy starting point if you're new to modding.

You might want to have a look at the code of https://mods.factorio.com/mod/DiscoScience
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Suf
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Fri Jul 10, 2020 5:07 am
Contact:

Re: Sprite Sheet Controlled On How Many Items Are In The Entity

Post by Suf »

eradicator wrote:
Mon Mar 29, 2021 4:17 pm
What you're trying to do is not supported by the API. There are no events for non-player inventory changes. You can not change the graphic of an entity at runtime. You'd have to use various hacks and workarounds. Not an easy starting point if you're new to modding.

You might want to have a look at the code of https://mods.factorio.com/mod/DiscoScience
It's not supported? then maybe this should be in requesting features section for more modding flexibility; And thanks for the link :mrgreen:

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Sprite Sheet Controlled On How Many Items Are In The Entity

Post by eradicator »

Suf wrote:
Mon Mar 29, 2021 5:04 pm
eradicator wrote:
Mon Mar 29, 2021 4:17 pm
There are no events for non-player inventory changes. You can not change the graphic of an entity at runtime.
It's not supported? then maybe this should be in requesting features section for more modding flexibility
Use the forum search function. Those two are never going to happen. (bad for performance + fundamental engine rewrite)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1648
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Sprite Sheet Controlled On How Many Items Are In The Entity

Post by Pi-C »

While you can't replace the sprite sheet of an entity at runtime, you can define different entities (each with its own sprite sheet) and replace one with the other. To do that, you need to maintain a list of the built entities in the global table (so it will be saved with the game). It's a common technique used in many mods. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Suf
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Fri Jul 10, 2020 5:07 am
Contact:

Re: Sprite Sheet Controlled On How Many Items Are In The Entity

Post by Suf »

Pi-C wrote:
Tue Mar 30, 2021 4:20 am
While you can't replace the sprite sheet of an entity at runtime, you can define different entities (each with its own sprite sheet) and replace one with the other. To do that, you need to maintain a list of the built entities in the global table (so it will be saved with the game). It's a common technique used in many mods. :-)
The idea was here to make a smooth "transformative" change from one sprite sheet to another, but since that isn't supported yet if it will ever be then i can use Krastorio 2 lab's approach and yeah thanks for giving me an alternative approach there :D

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Sprite Sheet Controlled On How Many Items Are In The Entity

Post by eradicator »

LuaRendering.draw_animation has tinting support and thus it can draw (semi-)transparent animations. So blending from one into the next is possible. Should be similar to what disco science does. It's just not straight-forward or cheap (neither is conditional entity replacement).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding help”