Page 1 of 1

Arbritrary External Mod Prototype Script

Posted: Sat Aug 29, 2015 9:28 pm
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?

Re: Arbritrary External Mod Prototype Script

Posted: Sat Aug 29, 2015 9:34 pm
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)

Re: Arbritrary External Mod Prototype Script

Posted: Sat Aug 29, 2015 11:05 pm
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.

Re: Arbritrary External Mod Prototype Script

Posted: Sat Aug 29, 2015 11:15 pm
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

Re: Arbritrary External Mod Prototype Script

Posted: Tue Sep 01, 2015 3:25 am
by Adil
Data.raw subtables are indexed by names not by numbers. Have a look at this page.