Can I trigger an attack action from a script event?

Place to get help with not working mods / modding interface.
Post Reply
Solinya
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Sun Mar 17, 2019 10:39 pm
Contact:

Can I trigger an attack action from a script event?

Post by Solinya »

I'm trying to have the equivalent of a discharge defense/land-mine attack go off on a script-defined trigger (say, when a character drops below a certain hp %). When looking around, I've found plenty of threads on how to define new attack types in the data stage, but I'm not sure how to trigger those attacks or actions in the control stage.

I don't want my attack to be usable outside of the script-defined events, and it looks like LuaEntity.set_command() can only be used on units, not characters. I may be able to create a temporary entity to "attack" once and remove itself for me, but wondering if there's a simpler way to handle this (especially since entities aren't always placeable on all locations).

My ultimate goal is to damage, stun, and knockback enemies around the character in a specific event handler. I have the script conditions figured out, I just don't know how to trigger the appropriate action(s).

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5201
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Can I trigger an attack action from a script event?

Post by eradicator »

You can use LuaSurface.create_entity() to spawn in "projectile" and "beam" type prototypes.
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.

Solinya
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Sun Mar 17, 2019 10:39 pm
Contact:

Re: Can I trigger an attack action from a script event?

Post by Solinya »

I'm not that familiar with projectiles and beams. Per your advice I was looking into create_entity and the first obstacle I encountered is targeting. The discharge defense is able to target all enemies within a radius of 8 around the player, but it's also not quite implemented as a projectile. Would I need to use LuaSurface.find_entities_filtered() to generate a projectile targeting each enemy, and if so, are my projectiles guaranteed to hit the enemies in the back of a clump of biters, or will the biters in front absorb all the shots?

The second obstacle is that an animation is mandatory for projectiles. I'd be okay with reusing the discharge defense animation, but that appears to be a beam (electric-beam-no-sound) and I'm unsure how to hook up the animation.

If I opt for the beam approach, I need to have a non-zero damage interval, even if I just want a one-time effect. But I also don't see how to specify the lifetime of the beam?

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5201
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Can I trigger an attack action from a script event?

Post by eradicator »

I have only very limited experience with projectile spawning myself, but i would expect that you spawn a projectile with area of effect damage at the players position. If you want a slowly expanding circular effect you might want to look at the atomic-rocket and atomic-bomb-wave projectiles.

If any prototype requires an animation and you don't want one you can just specify data\core\graphics\empty.png to make it invisible.
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.

Post Reply

Return to “Modding help”