Krastorio 2


An overhaul mod focusing on end-game technologies and moderately increased complexity.

Overhaul
7 months ago
0.18 - 1.1
338K
Transportation Logistics Trains Combat Armor Mining Fluids Logistic network Manufacturing Power Storage

b Incompatible wirth Water As A Resource

4 years ago

Hello,

Im the author of the Mod Water As A Resource.

Getting an issue, where when an offshore pump is placed, its not raising an event. I use the event to trigger my mod and require the entity, position, direction, force of the built pump.

I tried looking through your mod but cant see a way to pickup on the offshore pump being built. It looks like you've somehow removed the vanilla event for this ???

How can I pickup on a offshore pump being built?

4 years ago
(updated 4 years ago)

Hi TreefrogGreaken,
Probably because u filter only on removing the entity [ offshore_pump ][ offshore_pump ], (vanilla), with K2 u shoud filter also [ assembling-machine ][ kr-electric-offshore-pump ], (only if aai-industry is not present).

4 years ago
(updated 4 years ago)

Hey,

No event filtering.

When your mod is active, I don't see my event triggers at all, as if your mod is somehow absorbing them.

Without your mod, mines works fine, so its got something to do with how your mod handles events.

Heres my event.
script.on_event({defines.events.on_built_entity,defines.events.on_robot_built_entity,defines.script_raised_build}, BuiltOffShore)

And the start of my function, with the prints in for testing
function BuiltOffShore(event) -- Script Event On Built
game.print(event.created_entity.name)
game.print("In Here")
if event.created_entity.valid == true or event.entity.valid == true then
if event.created_entity.name =="offshore-pump" or event.created_entity.name =="kr-electric-offshore-pump" or event.entity ~= nil and event.entity.name =="offshore-pump" then

Whats going on?

4 years ago
(updated 4 years ago)

In this script, on on_built_entity and on_robot_built_entity I change the entity in my one, instead on using a blueprints will be directly used the "kr-electric-offshore-pump" entity type

I think that u don't got the entity because I don't trigger the raise_built in the event so event.created_entity.valid should be false (or maybe the event is not trigged at all). The fact is that if I set raise_built to true, I create other bugs to other mods, because I don't build another entity is the same

4 years ago

Hmm, ok.

Would it be possible then to add in a remote.call into your mod in that place?

I'll add in an remote interface so you can call my function and pass it the entity data, that should then be ok?

I might give this a test at my end first and let you know?

4 years ago

Sure, if u can provide me a command to do in the case ur mod is loaded, I can add it in the next version of the mod. Or u can also modify this script and send me the version for override mine, or give me the code... is equal to me.

4 years ago
(updated 4 years ago)

Hey,

Ok so i've got the remote call working, just need to sort out why its making 2 offshore pumps in the same location and then it'll be sorted.

Once Ive done that, ill let you know the code.

4 years ago

Hello just to let you know I have some code changes that work for me, need to do more work on my mod though first, so I'll let you know once ive finished it off.

4 years ago
(updated 4 years ago)

Hey Linver,

So heres the code to add.

I ammended the Player line, so that it actually grabs the player that built the offshore pump when robots also do it, i need this to work also for my map markers. Then theres just my 3 lines of code in.

local function onBuiltAnEntity(event)
local old_entity = event.created_entity or event.entity
if old_entity.valid and old_entity.name == "offshore-pump" then
local with_damage = old_entity.prototype.max_health - old_entity.health
local network = old_entity.circuit_connection_definitions
local pos = old_entity.position
local force = old_entity.force
local direction = old_entity.direction
local surface = old_entity.surface
local player = old_entity.last_user

    if old_entity and old_entity.valid then
        old_entity.destroy()
    end

    local new_entity = surface.create_entity
    {
        name                      = "kr-electric-offshore-pump",
        position                  = pos,
        direction                 = direction,
        force                     = force,
        player                    = player,
        create_build_effect_smoke = false,
        raise_built               = false
    }

    if game.active_mods["WaterAsAResource"] then
        remote.call("WaaR","build", new_entity, true)
    end

    -- Set in the new entity the health of the destroyed entity
    if with_damage > 0 then
        new_entity.damage(with_damage, game.forces.neutral)
    end
end

end

Would you also put in an optional dependency for (?)WaterAsAResource >= 0.7.8.

Thanks.