Detecting when a player replaces an entity
Detecting when a player replaces an entity
Right now, it seems that it throws entity built and mined event.
Is there a way to determine when a player manually replaces/upgrades an entity, like a transport-belt?
Is there a way to determine when a player manually replaces/upgrades an entity, like a transport-belt?
Re: Detecting when a player replaces an entity
You get two events simultaneously, just check them.
https://mods.factorio.com/mod/FillingBeltsUpdater
https://mods.factorio.com/mod/FillingBeltsUpdater
Re: Detecting when a player replaces an entity
don't understand how that would help
Re: Detecting when a player replaces an entity
What feature are you trying to build by detecting this event?
Re: Detecting when a player replaces an entity
it is about xp gain from placing entities, but if you fast replace it goes bonkers, so it needs to ignore replacing of entities
Re: Detecting when a player replaces an entity
I would subtract xp for each entity mined. Keep a xp buffer that is only given to the player once per tick, so fast replace ends up with zero net xp. Also you can add a check to ensure actual xp never goes down.
Re: Detecting when a player replaces an entity
That does not do what i would like it to do.
Re: Detecting when a player replaces an entity
Code: Select all
local tick = 0
local last_entity = nil
...
function mything(event)
if last_entity ~= nil then
-- probably need last_entity.valid because something doesn't exist after being mined
if tick == event.tick and last_entity.valid and (event.entity.position[1] == last_entity.position[1] and event.entity.position[2] == last_entity.position[2]) then
return
end
end
...do normal stuff...
tick = event.tick
last_entity = event.entity
end
I have mods! I guess!
Link
Link
Re: Detecting when a player replaces an entity
having a hashtable that saves every entity built that can be replaced, is extremely bloated way to do such a small thing
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Detecting when a player replaces an entity
Store all deconstructions in a tick-aware cache, if a build event has the same position and fast_replaceable_group as an entity in the cache you know it's a replacement action. If the cache tick index is not the current tick at the start of any event delete the cache. I.e. you only ever need to store a single tick worth of deconstruction events.
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.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Detecting when a player replaces an entity
it may be enough to save only the position of the last placed entity + tick and compare it with the entity position that is mined next
not sure if this will give the correct result always, got to try
not sure if this will give the correct result always, got to try
Re: Detecting when a player replaces an entity
there is no way to do this properly, it seems, only found a way to keep track of some entities that were placed in the last x amount of ticks and compare them to the ones mined, but that is quite wonky