Hi
I have a mod idea to add a new dimension to enemies and I might want to learn the modding api for it.
Before diving in to some guides I first wanted to do a general check whether what I wanted to do is possible.
- I want to add a new enemy
- trigger certain events based on how much health the enemy has
- spawn and delete enemies
- completely override the way enemies move
more specifically, add certain paths that enemies will follow, completely ignoring the player
The last one I'm least sure about whether it is possible.
Thanks for any advice.
Questions about enemy api
Re: Questions about enemy api
Many mods do that. Just define a new prototype in data.raw.unit.
To the best of my knowledge, that would work, kind of. You could listen to on_entity_damaged and check event.final_health. That will definitely work for positive damage amounts; I'm not sure if this will also work for negative damage amounts (i.e. healing). Also, the event will not be triggered if other mods decide to change the unit's health.- trigger certain events based on how much health the enemy has
Should work.- spawn and delete enemies
I really didn't deal much with pathfinding yet. There's LuaSurface.request_path, but according to the description this will request a path using the vanilla algorithm for units. About "completely ignoring the player" -- LuaEntity.set_command and LuaEntity.set_distraction_command look useful (using no distraction). But implementing a completely new pathing algorithm where you'd need to check position and motion of every unit you've created would probably be quite expensive in terms of UPS.- completely override the way enemies move
more specifically, add certain paths that enemies will follow, completely ignoring the player
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Re: Questions about enemy api
Thanks for the help. These look like excellent starting point.
It's not so much that I want to do a new pathfinding every frame but rather pass along a predetermined path at the moment of creation.
Probably mostly simple paths like lines, circles, ...
So I think it shouldn't be too much of an extra strain on the UPS with the proposals you have given.
It's not so much that I want to do a new pathfinding every frame but rather pass along a predetermined path at the moment of creation.
Probably mostly simple paths like lines, circles, ...
So I think it shouldn't be too much of an extra strain on the UPS with the proposals you have given.