Page 1 of 1

Sprite Sheet Controlled On How Many Items Are In The Entity

Posted: Mon Mar 29, 2021 3:17 pm
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

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

Posted: Mon Mar 29, 2021 4:17 pm
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

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

Posted: Mon Mar 29, 2021 5:04 pm
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:

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

Posted: Mon Mar 29, 2021 11:56 pm
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)

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

Posted: Tue Mar 30, 2021 4:20 am
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. :-)

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

Posted: Tue Mar 30, 2021 7:07 am
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

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

Posted: Tue Mar 30, 2021 3:08 pm
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).