Page 1 of 1
Delay Time of Death
Posted: Wed Jun 13, 2018 8:46 pm
by TheSAguy
Hi,
In my Natural Evolution Enemies mod, I have worms shoot units to the player.
The way it works is that I create a trigger entity that I kill and then spawn the units.
Currently it's instantaneously and I'd like to only like to spawn the newly created units like 5 seconds later. or in other words, kill the trigger entity in 5 seconds after it's created.
Here is the current code:
Code: Select all
script.on_event(defines.events.on_trigger_created_entity, function(event)
local entity = event.entity
--- Unit Cluster created by Worm Launcher Projectile
if entity.valid and global.launch_units[entity.name] then
writeDebug("Cluster Unit Created")
entity.die()
end
end)
Thanks.
Re: Delay Time of Death
Posted: Thu Jun 14, 2018 8:07 am
by bobingabout
Well, the initial event, I'd look at how capsules work, since using a capsule fires a projectile, the same methods can be used to create entities when the projectile explodes.
a 5 second delay... hmmm...
Keep in mind I haven't done this, but...could you create an animation (it can even be invisible, the point is the entity exists) that lasts for 5 seconds, and then creates the new entity when it ends?
Yeah, I like to keep scripts out of it whenever possible.
Re: Delay Time of Death
Posted: Thu Jun 14, 2018 1:03 pm
by TheSAguy
So they way it currently work is the projectile fires and then I create a little unit at the end and kill it.
When it dies, I spawn the other units.
So how would I direct if an animation is done to then do something?
I tried giving the created unit 5 life and give it a negative health gain of -1, so it die after 5 ticks, but that approach does not seem to work.
Thanks.
Re: Delay Time of Death
Posted: Thu Jun 14, 2018 1:37 pm
by Klonan
Maybe creating a 'SmokeWithTrigger' will solve your problem?
It can have a cooldown of 5 seconds, with the action of createEntity
Re: Delay Time of Death
Posted: Fri Jun 15, 2018 8:14 am
by bobingabout
Klonan wrote:Maybe creating a 'SmokeWithTrigger' will solve your problem?
It can have a cooldown of 5 seconds, with the action of createEntity
This is what I was trying to describe.
The best part is that if you do it correctly, you don't have to use scripts at all!
fire weapon
projectile hits target, creates a SmokeWithTrigger entity
SmokeWithTrigger entity expires in 5 seconds, and spawns an enemy unit.
Re: Delay Time of Death
Posted: Fri Jun 15, 2018 1:38 pm
by TheSAguy
Thanks guys, I'll give this a shot.
Re: Delay Time of Death
Posted: Thu Jun 28, 2018 12:58 am
by TheSAguy
Okay, so I'm still not exactly sure how to implement the smoke-with-trigger. since my trigger, is still triggered when the smoke is created and not when the duration ends.
I have my Projectile as: (I removed the sound and animation in below code)
Code: Select all
--- Unit Projectile
{
type = "projectile",
name = "Unit-Projectile",
flags = {"not-on-map"},
acceleration = 0.005,
force = "enemy",
action =
{
type = "direct",
force = "enemy",
action_delivery =
{
type = "instant",
force = "enemy",
target_effects =
{
{
type = "create-entity",
force = "enemy",
entity_name = "ne_unit_launcher_trigger",
},
}
}
},
},
Then I have my trigger entity as:
Code: Select all
--- Unit Launcher Smoke that will cause the Trigger
Unit_Launcher_Trigger = table.deepcopy(data.raw["smoke-with-trigger"]["poison-cloud"])
Unit_Launcher_Trigger.name = "ne_unit_launcher_trigger"
Unit_Launcher_Trigger.duration = 60 * 20
Unit_Launcher_Trigger.fade_away_duration = 0
Unit_Launcher_Trigger.spread_duration = 0
Unit_Launcher_Trigger.force = "enemy"
Unit_Launcher_Trigger.action = {
type = "direct",
force = "enemy",
action_delivery =
{
type = "instant",
force = "enemy",
target_effects =
{
type = "create-entity",
force = "enemy",
entity_name = "blood-explosion-big",
trigger_created_entity = true,
},
}
}
data:extend{Unit_Launcher_Trigger}
In control I have:
Code: Select all
script.on_event(defines.events.on_trigger_created_entity, function(event)
local entity = event.entity
--- Event triggers on the creation and not completion of the smoke.
if entity.valid and entity.name == "blood-explosion-big" then
writeDebug("Unit Triggered")
end
end)
Thanks.