Hello,
The mod crash when you use an editor mode (like : https://mods.factorio.com/mod/EditorExtensions where you can enter a character-less god-mode) :
The mod Smart Belt Immunity (0.1.1) caused a non-recoverable error.
Please report this error to the mod author.
Error while running event smart-belt-immunity::on_tick (ID 0)
smart-belt-immunity/control.lua:31: attempt to index field 'character' (a nil value)
stack traceback:
smart-belt-immunity/control.lua:31: in function <smart-belt-immunity/control.lua:11>
Also I see you are running the code in an ontick loop every tick on all players, it might be taking lot of performance for not much action, and may even lag out in a big multiplayer game.
You should use the on_nth_tick function https://lua-api.factorio.com/0.16.43/LuaBootstrap.html#LuaBootstrap.on_nth_tick and tune the time to only run it every 1 or 2 second for exemple (60 or 120 ticks) or even less to massively reduce the mod footprint on runtime.
Also as an optimisation you could fill an array (only on game load and on equiping an armor) of players with immunity equipements when an armor is equiped and contains an armor grid that contains a belt immunity equipements and then check if you actually have an array of players before doing any calculation. This way if no belt immunity is installed on an equiped armor, the mod wouldn't do anything at all and you would only loop once all players in the game to index eligible ones and only loop thoses to check if they are on a belt every nth ticks instead of checking all players every single tick.
Here's an exemple of a mod that checks a bunch of mining drill if any is built and registered in a list to check from every 2 seconds only :
- https://github.com/VortiK/vtk-deep-core-mining/blob/master/control.lua#L126
- https://github.com/VortiK/vtk-deep-core-mining/blob/master/lib/feature.lua#L66