Animated Lamp

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

Animated Lamp

Post by Suf »

Hi

I've made a lamp model with full animation for lamp entity,but seems lamp prototypes don't support animation https://wiki.factorio.com/Prototype/Lamp
and assembling machine prototype does support them https://wiki.factorio.com/Prototype/AssemblingMachine

so the question here is there a middle ground where i can make the entity benefits from the animation aspect in assembling machine, but at the same time acts like lamp?

Thanks in advance.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3361
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Animated Lamp

Post by DaveMcW »

In data.lua make an animation prototype.

In control.lua use rendering.draw_animation{} to add the animation to whatever entity you want. You will need additional scripting if you want to change the animation in certain cases (circuit condition, no power, day, etc.).

If it just looks like a lamp but you don't need lamp functionality, you can use simple-entity-with-owner.

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

Re: Animated Lamp

Post by Suf »

DaveMcW wrote:
Wed Apr 07, 2021 8:15 am
In data.lua make an animation prototype.

In control.lua use rendering.draw_animation{} to add the animation to whatever entity you want. You will need additional scripting if you want to change the animation in certain cases (circuit condition, no power, day, etc.).

If it just looks like a lamp but you don't need lamp functionality, you can use simple-entity-with-owner.
interesting information; as for entity it acts like vanilla's lamp aside from animations and color codes.

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

Re: Animated Lamp

Post by Suf »

i've made the animation in data.lua,i got this error (animation): Value must be a list or dictionary in property tree at ROOT.animation.

which i'm guessing because i wanted that to load the sprite sheet instead of array of pictures?

Do you have a mod/example that shows how this process works ?
mods usually using predefined commands doesn't help me that much,so if there's an example or mod that uses nothing but codes and not predefined commands that would be nice.

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

Re: Animated Lamp

Post by Suf »

So i fixed the error,but even with that the entity still static.
again if there's an example of how this works i could achieve what i'm after.

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

Re: Animated Lamp

Post by Suf »

I've tried to use a workaround by making it assembling machine as type,but that didn't work because i still needed a way to void a recipe result and make it begins the animation as how it supposed to be for lamp regardless when the player choose the recipe and as for light i believe working_visualisations could act like "lamp's light".

So is that possible or not even as workaround?

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2354
Joined: Fri Nov 06, 2015 7:41 pm

Re: Animated Lamp

Post by Deadlock989 »

Suf wrote:
Wed Apr 14, 2021 7:45 am
I've tried to use a workaround by making it assembling machine as type,but that didn't work because i still needed a way to void a recipe result and make it begins the animation as how it supposed to be for lamp regardless when the player choose the recipe and as for light i believe working_visualisations could act like "lamp's light".

So is that possible or not even as workaround?
See the copper burner lamp in this small mod or the aetheric lamps in this large mod.

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

Re: Animated Lamp

Post by Suf »

Deadlock989 wrote:
Wed Apr 14, 2021 8:34 am
Suf wrote:
Wed Apr 14, 2021 7:45 am
I've tried to use a workaround by making it assembling machine as type,but that didn't work because i still needed a way to void a recipe result and make it begins the animation as how it supposed to be for lamp regardless when the player choose the recipe and as for light i believe working_visualisations could act like "lamp's light".

So is that possible or not even as workaround?
See the copper burner lamp in this small mod or the aetheric lamps in this large mod.
Yeah i've seen them; one always have the light on and working_visualisations begins how lamp works,and other needs fuels to act as lamp.
but my lamp idea is somewhat different it has full animation and everything including the light,it doesn't support color codes like industrial revolution lamps
but instead the player choose the color(as recipe) they wanted and that triggers glow and entity color change according to that,also the working animation should be stopped like how lamps works until evening or night.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2354
Joined: Fri Nov 06, 2015 7:41 pm

Re: Animated Lamp

Post by Deadlock989 »

Unfortunately this is a have-cake-or-eat-it but not both situation (IMO). If you want the automatic electric on/off behaviour of electric lamps, it has to be a lamp - lamps are heavily optimised for the electric network which is why you can't have any other kind of energy source for them. But lamps simply don't support animations. The earlier suggestion to use rendering to draw an animation on them would require you to do heavy scripting to change every lamp at dawn and dusk (if the lamp's glow is the thing that's animated). I think that would be a real UPS killer and wouldn't touch it with a bargepole myself - you may as well use some other entity since you'd be simulating the optimised behaviour in Lua anyway. Otherwise, you can have animated glows as part of a working_visualisation on a crafting machine entity as you figured out for yourself, but then you can't have the automatic on/off behaviour.

The only other example I've seen that comes close to your idea is the Dectorio glowing lamps which have a preselected colour. In Dectorio (if I remember correctly) you have to separately craft and place every colour of lamp, but you could instead have one generic craftable lamp item that places one variant of the lamp and then make a scripted hotkey replacement of the entity with the other coloured entities, a bit like how the IR2 steam lamps have a scripted hotkey to cycle the recipe. Then you could have arbitrarily coloured lamps with no signal - but still not animated.

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

Re: Animated Lamp

Post by eradicator »

Deadlock989 wrote:
Wed Apr 14, 2021 9:15 am
But lamps simply don't support animations. The earlier suggestion to use rendering to draw an animation on them would require you to do heavy scripting to change every lamp at dawn and dusk (if the lamp's glow is the thing that's animated). I think that would be a real UPS killer and wouldn't touch it with a bargepole myself
Assuming a few things:
1) @OP wants a "lamp" that either shows a fixed animation or is completely off.
2) @OP wants the staggered on/off at dusk dawn.

Then I think using an assembling machine with a void->void recipe that continuously runs the animation should work. The animation can be disabled via active=false. Not sure how long vanilla staggers, but even 10 seconds give you a whooping 600 ticks to handle that.

I don't know how hard you people spam lamps, but if active=false is as cheap as it sounds, then I doubt you'd see a notable UPS impact even with several thousand "lamps".
Author of: 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.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2354
Joined: Fri Nov 06, 2015 7:41 pm

Re: Animated Lamp

Post by Deadlock989 »

eradicator wrote:
Wed Apr 14, 2021 9:32 am
I don't know how hard you people spam lamps, but if active=false is as cheap as it sounds, then I doubt you'd see a notable UPS impact even with several thousand "lamps".
I was spamming them enough to make creating a lamp mod that has triple the illumination radius (and the attendant burden on light search radius) worthwhile.

I'd be interested to see the numbers. It seems like a song and dance (tracking all the entities on every surface, staggering them across ticks) just to have a lamp that flickers a bit.

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

Re: Animated Lamp

Post by Suf »

I've checked Dectorio and the lamp works like vanilla's lamp exactly and as for colors they're signals as wellImage
by this point i might just do a crafting tab for lamps specifically and just put every variant there as lamp type until lamp prototype supports animations without all of workaround. Anyway thanks guys.
Last edited by Suf on Wed Apr 14, 2021 10:18 am, edited 1 time in total.

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

Re: Animated Lamp

Post by eradicator »

Deadlock989 wrote:
Wed Apr 14, 2021 9:49 am
I'd be interested to see the numbers. It seems like a song and dance (tracking all the entities on every surface, staggering them across ticks) just to have a lamp that flickers a bit.
Doesn't seem too much of a hazzle to me. Number-wise the closest thing I've made is Eradicator's Visible Stockpile which is pretty fast. And then there's ofc Bottleneck which defaults to 40machines/tick.

Edit:

So just test. Grab a bunch of assemblers from the map and toggle active at 40/tick. Costs ~0.070ms on my system. Ofcs this all assumes that the active=false trick really is enough for @Op.

Code: Select all

/c

local asm = game.player.surface.find_entities_filtered {
  type = 'assembling-machine',
  limit = 100
  }
  
script.on_event(defines.events.on_tick, function()
  for i=1,40 do
    asm[i].active = not asm[i].active
    end
  end)
Last edited by eradicator on Wed Apr 14, 2021 10:30 am, edited 1 time in total.
Author of: 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.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2354
Joined: Fri Nov 06, 2015 7:41 pm

Re: Animated Lamp

Post by Deadlock989 »

I guess we all have mileage that varies. I'd never run Bottleneck, especially since 90% of what it does could have been replaced with native game engine features made available in 1.0.

Post Reply

Return to “Modding help”