dynamite does not set off nearby dynamite

Place to get help with not working mods / modding interface.
User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

dynamite does not set off nearby dynamite

Post by FreeER »

:) I can not seem to figure this problem out lol Anyone care to take a look and see what's going on?
I currently have

Code: Select all

        for k,nearbyentity in pairs(game.findentities{{event.entity.position.x-5, event.entity.position.y-5}, {event.entity.position.x+5, event.entity.position.y+5}}) do
            if nearbyentity.name == "dynamite" then for k,v in pairs(glob.dynamite) do if nearbyentity.equals(v.entity) then glob.dynamite[k].tick=glob.dynamite[k].tick-100 end end
            elseif nearbyentity.health then nearbyentity.damage(20, game.player.force)
            end
        end
I would simply let the damage 'kill' the nearby dynamite expect that I get an error (and if I try to use die() instead of reducing the tick it just turns into an infinite error two message).

Also I noticed that the explosion is not what I expected....
blast-mining.zip
(8.88 KiB) Downloaded 161 times
edit: fixed, silly errors lol. had table.remove in two places (moved to only being in onentitydied), the explosions issue (which came from using a landmine type for the dynamite initially) was due to the createentity not being inside of the if name==dynamite block.
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me :)
Or drop into #factorio on irc.esper.net

slpwnd
Factorio Staff
Factorio Staff
Posts: 1835
Joined: Sun Feb 03, 2013 2:51 pm
Contact:

Re: dynamite does not set off nearby dynamite

Post by slpwnd »

I played around a little bit with the mod and changed the code your provided to work in the following way:

Code: Select all

for k,nearbyentity in pairs(game.findentities{{event.entity.position.x-5, event.entity.position.y-5}, {event.entity.position.x+5, event.entity.position.y+5}}) do
    if nearbyentity.isvalid() then
      if nearbyentity.name == "dynamite" then for k,v in pairs(glob.dynamite) do if nearbyentity.equals(v.entity) then v.entity.die() break end end
      elseif nearbyentity.health then nearbyentity.damage(20, game.player.force) end
    end
end
Seems to work fine.

Also there was a small error in the data.lua when icon for dynamite item was taken from the clone mod.

Apart from that really nice mod:) I suppose dynamites would be super useful in the beginning of the game when you can use them to get plenty of resources without mining.

Post Reply

Return to “Modding help”