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.
Need help with damage over time script (i.e. poison)
Re: Need help with damage over time script (i.e. poison)
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)
I figured it could be, but my attempts to do so were not successful. Any tips are appreciatedNexela 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
Last edited by Bikklo on Tue Feb 27, 2018 4:57 am, edited 1 time in total.
Re: Need help with damage over time script (i.e. poison)
Explore the code of the vanilla Flame Thrower weapons. They have a static DOT effect (fire) and should be a fair example.
- Deadly-Bagel
- Smart Inserter
- Posts: 1498
- Joined: Wed Jul 13, 2016 10:12 am
- Contact:
Re: Need help with damage over time script (i.e. poison)
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.
Re: Need help with damage over time script (i.e. poison)
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!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.
Now all I need is someone to do textures for me
- Deadly-Bagel
- Smart Inserter
- Posts: 1498
- Joined: Wed Jul 13, 2016 10:12 am
- Contact:
Re: Need help with damage over time script (i.e. poison)
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:
(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.
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
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.