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

Place to get help with not working mods / modding interface.
Post Reply
Bikklo
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sun Feb 25, 2018 7:22 am
Contact:

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

Post 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.

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

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

Post 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

Bikklo
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sun Feb 25, 2018 7:22 am
Contact:

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

Post 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 :)
Last edited by Bikklo on Tue Feb 27, 2018 4:57 am, edited 1 time in total.

Aeternus
Filter Inserter
Filter Inserter
Posts: 835
Joined: Wed Mar 29, 2017 2:10 am
Contact:

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

Post by Aeternus »

Explore the code of the vanilla Flame Thrower weapons. They have a static DOT effect (fire) and should be a fair example.

User avatar
Deadly-Bagel
Smart Inserter
Smart Inserter
Posts: 1498
Joined: Wed Jul 13, 2016 10:12 am
Contact:

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

Post 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.
Money might be the root of all evil, but ignorance is the heart.

Bikklo
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sun Feb 25, 2018 7:22 am
Contact:

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

Post 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:

User avatar
Deadly-Bagel
Smart Inserter
Smart Inserter
Posts: 1498
Joined: Wed Jul 13, 2016 10:12 am
Contact:

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

Post 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.
Money might be the root of all evil, but ignorance is the heart.

Post Reply

Return to “Modding help”