Page 1 of 1

Make production statistics graph editable

Posted: Thu Sep 30, 2021 9:01 pm
by MrJakobLaich
I'm trying a different approach, maybe I can fix this problem without requesting anything.
I'll leave this here, maybe it's easy enough to implement and someone might need it in the future

I have the following problem:
I have a capsule that has a low cooldown, I can't change the cooldown because of other reasons that aren't important.
When the capsule gets used the player gets a buff.
When a buff is active the capsule is used without giving a buff and the player gets the same capsule put into their inventory.
This is to simulate the capsule not being used as long as there is a buff active.

This causes the following problem:
The production consumption statistic automatically counts up every time a capsule is used.
I want to subtract one from the last time a value was added up to the current point in time.
This is probably only one tick, because I have a script effect for the capsule.

set_output_count only edits the total count.
https://lua-api.factorio.com/latest/Lua ... tput_count

Re: Make production statistics graph editable

Posted: Thu Sep 30, 2021 9:11 pm
by Klonan
MrJakobLaich wrote: Thu Sep 30, 2021 9:01 pm When a buff is active the capsule is used without giving a buff and the player gets the same capsule put into their inventory.
This is to simulate the capsule not being used as long as there is a buff active.
You could set the capsule to not be consumed when used:
https://wiki.factorio.com/Types/UseOnSe ... uses_stack

And then if the capsule does activate the buff, consume from the stack using script yourself, and add it to the production GUI

Re: Make production statistics graph editable

Posted: Fri Oct 01, 2021 9:57 am
by MrJakobLaich
Klonan wrote: Thu Sep 30, 2021 9:11 pm
MrJakobLaich wrote: Thu Sep 30, 2021 9:01 pm When a buff is active the capsule is used without giving a buff and the player gets the same capsule put into their inventory.
This is to simulate the capsule not being used as long as there is a buff active.
You could set the capsule to not be consumed when used:
https://wiki.factorio.com/Types/UseOnSe ... uses_stack

And then if the capsule does activate the buff, consume from the stack using script yourself, and add it to the production GUI
Thanks :D
Funnily enough that's exactly what we came up with after a lot of thinking and debating about possible solutions (I got some help from the discord ;) )
Still do appreciate that you replied so fast 8-)

Trying to implement that right now. ;)

EDIT:
Works 100% as intended, thanks :D

If anyone comes across this:
Is set

Code: Select all

capsule_action["uses_stack"] = false
as a value of the item.
Then in the control.lua I do

Code: Select all

player.remove_item{name=<item_name>, count=<remove_amount>}
when the item should be consumed.
Then I do

Code: Select all

game["forces"]["player"]["item_production_statistics"].on_flow(<item_name>, -1)
to increase the production statistic by one.
(-1 for the right consumption side of the prod stat)