Arbritrary External Mod Prototype Script

Place to get help with not working mods / modding interface.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2171
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Arbritrary External Mod Prototype Script

Post by Ranakastrasz »

In my mod, I have increased the energy values of all modular armor equipment by 50x so it can interact with fuel and the energy network in a sane manner. I want to be able to allow full compatability with all other mods that add new modules. Other mods don't have this multiplier however, meaning I would have to write some kind of interface script for each and every mod that is added. Is it possible/how can I write a script that runs after all mods load their prototypes, and then loop through and alter them as needed?
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Arbritrary External Mod Prototype Script

Post by Choumiko »

Put the code that multiplies the value in data-final-fixes.lua This file is run after all data.lua and data-updates are done for every mod. Running it in data-updates could be enough (Not sure if there's a best practice yet)
ajranney
Inserter
Inserter
Posts: 30
Joined: Mon May 25, 2015 4:44 am
Contact:

Re: Arbritrary External Mod Prototype Script

Post by ajranney »

Like Choumiko said a data-updates or data-final-fixes can search by prototype and replace/alter properties of all items added by all mods. I suggest you look at the following prototypes:
"energy-shield-equipment","battery-equipment","solar-panel-equipment","generator-equipment","active-defense-equipment" and possibly "night-vision-equipment", and "movement-bonus-equipment"
the code would search for all items with type = ""(as above) and replace energy_... with whatever values or multipliers you wished.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2171
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Arbritrary External Mod Prototype Script

Post by Ranakastrasz »

This is the code I attempted. I didn't finish it yet due to compilation error. I am trying to get it to loop through all prototypes at the same time. This seems to not be cooperating.

Code: Select all

function modValue(str) -- Multiply power values by powerCoef
    --str = "101kw"
    pos = string.find(str,"%a")-1
    --io.write(pos.."\n")
    subPre = string.sub(str,1,pos)
    subSuf = string.sub(str,(pos)-string.len(str))
    --io.write(string.len(str).."\n")
    val = tonumber(subPre)
    val = val*50
    subPre = tostring(val)
    str = subPre..subSuf
    --io.write(subPre.."\n")
    --io.write(subSuf.."\n")
    --io.write(str.."\n")
    return str
end

for i, equipment in pairs (data.raw) do
    if string.find(equipment[1].type, "equipment") then
        
    end
end
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Arbritrary External Mod Prototype Script

Post by Adil »

Data.raw subtables are indexed by names not by numbers. Have a look at this page.
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.
Post Reply

Return to “Modding help”