Page 1 of 1

Need help with damage over time script (i.e. poison)

Posted: Sun Feb 25, 2018 7:47 am
by Bikklo
Hello all,
This is my first foray into the world of modding factorio, and so far everything is going smoothly. I have however encountered a small stumbling block.

What I want to do is create a new type of bullet magazine that, when fired, will inflict poison damage to the target over a short duration of time (for example, 4 damage every half second for 3 seconds). The solution that first comes to mind is to use a script to check when entities are damaged, and if the cause of damage is an entity or player using the "poison" bullets, cause "n" amount of damage to the target entity every "x" ticks. I have been able to make a script to check the cause of damage to entities and if the attacker has my "poison" bullets in their inventory easily enough, but what I'm having trouble with is detecting if the attacker used my poison bullets to attack and applying damage to the target entity.

Any help with this problem is greatly appreciated! :)

I can, upon request, upload my mod as a .zip file for those that wish to look at my code.

Re: Need help with damage over time script (i.e. poison)

Posted: Sun Feb 25, 2018 4:08 pm
by Nexela
This can be done without scripts. You will just add some of the trigger logic from poison capsules to your bullets. I don't have anything in front of me to go into it deeper at this time though

Re: Need help with damage over time script (i.e. poison)

Posted: Mon Feb 26, 2018 4:27 am
by Bikklo
Nexela wrote:This can be done without scripts. You will just add some of the trigger logic from poison capsules to your bullets. I don't have anything in front of me to go into it deeper at this time though
I figured it could be, but my attempts to do so were not successful. Any tips are appreciated :)

Re: Need help with damage over time script (i.e. poison)

Posted: Mon Feb 26, 2018 10:42 am
by Aeternus
Explore the code of the vanilla Flame Thrower weapons. They have a static DOT effect (fire) and should be a fair example.

Re: Need help with damage over time script (i.e. poison)

Posted: Mon Feb 26, 2018 11:17 am
by Deadly-Bagel
Looks like you need to create a "sticker", check out "fire-sticker" in the fire.lua file, should be straightforward from there. Unfortunately I can't find any info on it in the Factorio LUA documentation.

Re: Need help with damage over time script (i.e. poison)

Posted: Tue Feb 27, 2018 4:55 am
by Bikklo
Deadly-Bagel wrote:Looks like you need to create a "sticker", check out "fire-sticker" in the fire.lua file, should be straightforward from there. Unfortunately I can't find any info on it in the Factorio LUA documentation.
This is exactly what I needed, thank you! Got it working now. I noticed lots of things in the vanilla code are missing documentation on the API web page, which is unfortunate for us modders. I would also like to make the toxic rounds affect biter bases, as it doesn't seem to by default. Is there a key to enable this in the sticker, or perhaps in the ammo? Thanks for the help!

Now all I need is someone to do textures for me :lol:

Re: Need help with damage over time script (i.e. poison)

Posted: Tue Feb 27, 2018 9:39 am
by Deadly-Bagel
Hmm. I don't see any way to affect structures, the fire-flame-on-tree entity appears to be a hardcoded category.

Not sure if it would work with a bullet weapon but I would try adding a Flag to all Spawners:

Code: Select all

for i, spawner in pairs(data.raw["unit-spawner"]) do
    table.insert(spawner.flags, "building")
end
(not sure if that actually works but you get the idea)

Then create a smoke-with-trigger entity, refer to poison-cloud but strip out the graphics and set the entity_flags of the damage to "building".

I'm not sure if you could selectively spawn this when the target is a building but be wary of performance, if you have a large number of Gun Turrets this could potentially be spawning thousands of these invisible clouds so you'd need to test it, and I recommend keeping their lifespan short.