Another Resistance Question

Place to get help with not working mods / modding interface.
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1455
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Another Resistance Question

Post by TheSAguy »

I was thinking of adding a damage type - Venom, but wanted to make all buildings immune to it.
Is there a way to mass update all entities? Like cycle thought them and update?

I know that some buildings already have the 75% fire resistance.
Maybe something like "If Resistance = {} or Resistance = Fire 75%, then Resistance = Fire 75% and Venom 100%"
(Not actual code)

Thanks.
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Another Resistance Question

Post by Adil »

Well, I don't see this much different from usual entity alteration by mod.
You iterate over in your data.lua, data-upgrades.lua (or the third one) or whatever file that is required by those, you iterate over data.raw selecting the categories you need, and selecting desired entities from those categories and update those.

Code: Select all

new_resist={type = "venom", decrease = 15, percent = 50};
exclude={"player"=true, "behemoth-biter"=true, "behemoth-spitter"=true};--you got the idea of how this list should be filled
for category_name, category in pairs(data.raw) do
    if category_name~='projectile' then --first filter, purely demonstrational
        for prot_name, prot in pairs(category) do
            if prot.resistances and not exclude[prot_name] then --second filter
                 table.insert(prot.resistances,new_resist); 
            end
        end
    end
end 
In the example I've went with explicit list of vulnerable unit names and not with the listing of vulnerable categories because some mods might put there entities which shouldn't be vulnerable. For example mocombat adds mechanic units for which poison damage would be just silly.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1455
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Another Resistance Question

Post by TheSAguy »

Thanks Adil,

So I have just started with the code and have a few follow-up questions so I better understand things.

This is the current code.

Code: Select all

local new_resist = {type = "Venom", decrease = 50, percent = 100}
local exclude = {["player"]=true, ["behemoth-biter"]=true, ["behemoth-spitter"]=true}--you got the idea of how this list should be filled

for category_name, category in pairs(data.raw) do
    if category_name~='projectile' then --first filter, purely demonstrational
        for prot_name, prot in pairs(category) do
            if prot.resistances and not exclude[prot_name] then --second filter
                 table.insert(prot.resistances,new_resist)
            end
        end
    end
end
Is there a way to use wild cards for the biters? Like "*-biter" and "*-spitter"
Is there an easy way to get all "Categories"?
Am I correct in saying that currently it will only add the new resist to items that already have some sort of resistance? (If it meets the filter criteria)
- So the current code, all categories not Projectile and not in the exclusion list, that has a resistance, will get the Venom added.

Lastly, I'm new to Lua, is there a good tutorial, especially on the whole "in pairs" thing....
Thanks.
daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: Another Resistance Question

Post by daniel34 »

TheSAguy wrote:Lastly, I'm new to Lua, is there a good tutorial, especially on the whole "in pairs" thing...
There's a really good book available online on the lua.org page: Programming in Lua (first edition)
For pairs, look at http://www.lua.org/pil/4.3.5.html
quick links: log file | graphical issues | wiki
Post Reply

Return to “Modding help”