I'm working on porting my mod to 0.17, and I was wondering if it might be possible to create some modular equipment (like night vision) that gives resistance / immunity to a certain damage type?
Basically, I want to make a poison mask equipment that gives resistance / immunity to poison. But this could be applied to other damage types as well, like fire, physical, etc.
Nothing in the equipment prototypes seem to fit the bill. Anyone got any creative suggestions?
Modding question - Equipment to add resistances?
Modding question - Equipment to add resistances?
Obuw's Warfare - Combat improvements
Re: Modding question - Equipment to add resistances?
Only thing I can think of is make multiple versions of your equipment and swap the + resistances equipment with the equipment when the equipment inventory is changed.
Re: Modding question - Equipment to add resistances?
I've never seen attributes that can be read/written from for armor. Way I'd do it:
Check the armor when equipment is placed/unplaced (on_player_placed_equipment, on_player_removed_equipment). Have a global player table, made with [player_index][damage-type][flat/percent (two values)].
Before a player places any equipment, the game can handle damage/resistance. on_entity_damaged will trigger and you can look for a character. If they have no entry, you could manually start the table, or wait for equipment being added/removed. Whether you start then or wait for equipment, check the game.item_prototypes[armor] resistance. It looks like the only way to find a character's (the entity) armor, is to check the equipment grid, and then check the name of the prototype:
https://lua-api.factorio.com/latest/Lua ... tGrid.html
https://lua-api.factorio.com/latest/Lua ... otype.html
If that doesn't work, you can hope all armors have individual grids, and then check item_prototypes for items with grids (use pcall if there's nil errors when checking the item_prototypes). Record the name of item and the grid height/width (maybe make a key of height.."x"..width which has the armor name as the value), and then when a player is damaged or equips/unequips armor, check the armor grid. Use that to go back to the item prototype and collect the armor's resistances. Finally we can go over equipment (if not tracking equip/unequip) and calculate armor value. If we were tracking equip/unequip, check the base armor, and calculate flat/percent from that. In the on_entity_damaged event, once the resistances are all determined, then you can modify the final_damage amount based on original_damage_amount. event.final_damage_amount = (original_damage_amount - global.armors[player.player_index][event.damage_type][flat]) * ( 1 - global.armors[player.player_index][event.damage_type][percent]
Something like that should work. You can filter for entity damaged events and such too, but I always go for getting it working before "optimizing".
Technically the character wears armor I think, which is not a player. One can use the entity id or whatever to store armor that way. If a character died, you can nil them in the table and let them get re-added when they have armor.
Edit: wow just found something REALLY IMPORTANT! If you unequip armor, it doesn't trigger the removing equipment event. Only when "on_player_armor_inventory_changed" do you know when someone equipped/removed armor. Was testing my own equipment mod and noticed bonuses didn't stop applying when armor was removed (updating a legacy mod - the original mod only used equip events). The good news is there IS an event to determine when someone changed armors, including armor that is the same kind of item. Unfortunately the event only gives you the player... but it's a start.
Check the armor when equipment is placed/unplaced (on_player_placed_equipment, on_player_removed_equipment). Have a global player table, made with [player_index][damage-type][flat/percent (two values)].
Before a player places any equipment, the game can handle damage/resistance. on_entity_damaged will trigger and you can look for a character. If they have no entry, you could manually start the table, or wait for equipment being added/removed. Whether you start then or wait for equipment, check the game.item_prototypes[armor] resistance. It looks like the only way to find a character's (the entity) armor, is to check the equipment grid, and then check the name of the prototype:
https://lua-api.factorio.com/latest/Lua ... tGrid.html
https://lua-api.factorio.com/latest/Lua ... otype.html
If that doesn't work, you can hope all armors have individual grids, and then check item_prototypes for items with grids (use pcall if there's nil errors when checking the item_prototypes). Record the name of item and the grid height/width (maybe make a key of height.."x"..width which has the armor name as the value), and then when a player is damaged or equips/unequips armor, check the armor grid. Use that to go back to the item prototype and collect the armor's resistances. Finally we can go over equipment (if not tracking equip/unequip) and calculate armor value. If we were tracking equip/unequip, check the base armor, and calculate flat/percent from that. In the on_entity_damaged event, once the resistances are all determined, then you can modify the final_damage amount based on original_damage_amount. event.final_damage_amount = (original_damage_amount - global.armors[player.player_index][event.damage_type][flat]) * ( 1 - global.armors[player.player_index][event.damage_type][percent]
Something like that should work. You can filter for entity damaged events and such too, but I always go for getting it working before "optimizing".
Technically the character wears armor I think, which is not a player. One can use the entity id or whatever to store armor that way. If a character died, you can nil them in the table and let them get re-added when they have armor.
Edit: wow just found something REALLY IMPORTANT! If you unequip armor, it doesn't trigger the removing equipment event. Only when "on_player_armor_inventory_changed" do you know when someone equipped/removed armor. Was testing my own equipment mod and noticed bonuses didn't stop applying when armor was removed (updating a legacy mod - the original mod only used equip events). The good news is there IS an event to determine when someone changed armors, including armor that is the same kind of item. Unfortunately the event only gives you the player... but it's a start.
I have mods! I guess!
Link
Link
Re: Modding question - Equipment to add resistances?
I was look at events else last night, and thought of something:
An event that raises on_entity_damaged may have already done the damage. I'm not sure if damage resolves before the event and you're simply told what happened (read-only), or if the damage is applied after the event is processed, to give something else a chance to act on it. If the first, one has to heal an entity for the difference in damage done vs damage we think should be done.
An event that raises on_entity_damaged may have already done the damage. I'm not sure if damage resolves before the event and you're simply told what happened (read-only), or if the damage is applied after the event is processed, to give something else a chance to act on it. If the first, one has to heal an entity for the difference in damage done vs damage we think should be done.
I have mods! I guess!
Link
Link