Page 1 of 1

Can I trigger an attack action from a script event?

Posted: Sun Feb 02, 2020 12:06 am
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).

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

Posted: Sun Feb 09, 2020 4:28 pm
by eradicator
You can use LuaSurface.create_entity() to spawn in "projectile" and "beam" type prototypes.

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

Posted: Mon Feb 17, 2020 2:10 am
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?

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

Posted: Mon Feb 17, 2020 3:50 pm
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.