Page 1 of 1

Creating Ore with Projectiles

Posted: Sun Jul 31, 2016 5:22 pm
by weareryan
First time post here. Trying to make an asteroid that crashes down as ore, which kinda works. It does create the ore where it hits but ignores the amount field. It only creates a 50 quantity spot. I've been modding for all of 1 day so my mod fu is terribly weak.

Code: Select all

data:extend{
  {
    type = "projectile",
    name = "asteroid",
    flags = {"not-on-map"},
    acceleration = 0.01,
    action =
    {
      {
        type = "direct",
        action_delivery =
        {
          type = "instant",
          target_effects =
          {
            {
              type = "create-entity",
              entity_name = "iron-ore",
              amount = 2000,
            },
            {
              type = "create-entity",
              entity_name = "massive-explosion"
            },
            --[[{
              type = "create-entity",
              entity_name = "small-scorchmark",
              check_buildability = true
            }]]
          }
        }
      },
      {
        type = "area",
        perimeter = 8,
        action_delivery =
        {
          type = "instant",
          target_effects =
          {
            {
            type = "damage",
            damage = {amount = 80, type = "explosion"}
            },
           --[[ {
            type = "create-entity",
            entity_name = "explosion"
            }]]
          }
        }
      }
    },
    light = {intensity = 0.5, size = 4},
    animation =
    {
      filename = "__asteroids__/graphics/asteroid_01.png",
      line_length = 8,
      width = 128,
      height = 128,
      frame_count = 32,
      priority = "high"
    },
  },

Re: Creating Ore with Projectiles

Posted: Sun Jul 31, 2016 5:33 pm
by aubergine18
Bah, I'd just started writing an asteroid plugin, but it looks like you're already much further on than me so I'll stop. Regarding ore amount, I have no idea how to solve that issue. Although... What if the asteroid exploded in to several smaller asteroids which themselves deposit iron?

Are you able to get some fire moving with the asteroid itself, and maybe smoke generator that follows the asteroid? Would make it look awesome as it's heading towards the ground...

Re: Creating Ore with Projectiles

Posted: Sun Jul 31, 2016 6:42 pm
by Adil
The devs might have not even thought someone would try to do that. It is possible to alter the amount of ore in script.
The rewrite would be as follows:
weareryan wrote:

Code: Select all

{
type = "create-entity",
entity_name = "iron-ore",
amount = 2000,

trigger_createdentity="true",

},
And code handler would be:

Code: Select all

script.on_event(defines.events.on_trigger_created_entity, function(event)
    if event.entity.name='iron-ore' then event.entity.amount=100 end
end)
Better yet, you could define your own ore "meteorite-iron-ore" for example or use an intermediate entity to trigger event and spawn ore during the event handler. This way, if there's another mod, which also uses `on_trigger_created_entity` and `iron-ore`, its handler won't clash with events related to your mod.

Re: Creating Ore with Projectiles

Posted: Mon Aug 01, 2016 6:12 am
by weareryan
aubergine18 wrote:Bah, I'd just started writing an asteroid plugin, but it looks like you're already much further on than me so I'll stop. Regarding ore amount, I have no idea how to solve that issue. Although... What if the asteroid exploded in to several smaller asteroids which themselves deposit iron?

Are you able to get some fire moving with the asteroid itself, and maybe smoke generator that follows the asteroid? Would make it look awesome as it's heading towards the ground...
I'm not terribly far along yet. Right now I've got a modified radar building that sends down an asteroid when it completes a scan cycle. With no way to target it, and wanting to watch for testing purposes, I have it target the player - who gets blown up if he's not running. The smoke and flame idea is pretty awesome though - maybe if I could stream the flamethrower graphic off the back...I'll let you know if I get it going. And now I realize I need to give it a shadow as well.
Adil wrote:The devs might have not even thought someone would try to do that. It is possible to alter the amount of ore in script.
The rewrite would be as follows:
weareryan wrote:

Code: Select all

{
type = "create-entity",
entity_name = "iron-ore",
amount = 2000,

trigger_createdentity="true",

},
And code handler would be:

Code: Select all

script.on_event(defines.events.on_trigger_created_entity, function(event)
    if event.entity.name='iron-ore' then event.entity.amount=100 end
end)
Better yet, you could define your own ore "meteorite-iron-ore" for example or use an intermediate entity to trigger event and spawn ore during the event handler. This way, if there's another mod, which also uses `on_trigger_created_entity` and `iron-ore`, its handler won't clash with events related to your mod.
Thanks this is the solution I've settled on. I want to elegantly link the 'custom' ore to the normal ore's stats in case those get changed by another mod or the dev. It's not intended to make it's own special ores right now, just regular stuff. I've got enough headache building it without unnecessary exotic ores - had enough of that in minecraft.