COMMUNITY FORUM

Edit foliage state with LUA

Forum Overview >> Scripting

CategoryScripting
Created11.12.2024 05:16


Nekzuris (Nekzuris) 11.12.2024 05:16
Hi, I recently found this mod that adds Stubble Destruction:
https://www.kingmods.net/en/fs25/mods/57778/stubble-destruction

I think it looks awesome, but it works by replacing the original foliage game files, and I’d like to recreate it as a normal script mod.
If I understand correctly, it simply adds another crop state with the same texture but squished.

I was able to add another crop state by editing the relevant values in g_fruitTypeManager, and it technically works: stubble is destroyed under the wheels, but there’s no texture.

Here’s what my code looks like:
StubbleDestruction = {}

function StubbleDestruction:loadFruitTypes(xmlFileHandle, missionInfo, baseDirectory, isBaseType)
local barely = g_fruitTypeManager.indexToFruitType[FruitType.BARLEY]
if barely.nameToGrowthState["TIRETRACKS"] == nil then
local numFoliageStates = barely.numFoliageStates -- 10
barely.nameToGrowthState["TIRETRACKS"] = numFoliageStates + 1 -- 11
barely.growthStateToName[numFoliageStates + 1] = "tireTracks"
barely.maxWheelDestructionState = barely.maxWheelDestructionState + 1 -- 10
barely.numFoliageStates = barely.numFoliageStates + 1 -- 11
barely.maxDisasterDestructionState = barely.maxDisasterDestructionState + 1 -- 11
barely.wheelDestructionState = barely.wheelDestructionState + 1 -- 11
for _, period in ipairs(barely.growthDataSeasonal.periods) do
period.growthMapping[numFoliageStates + 1] = numFoliageStates + 1 --11
end
end
return true
end
FruitTypeManager.loadFruitTypes = Utils.appendedFunction(FruitTypeManager.loadFruitTypes, StubbleDestruction.loadFruitTypes)

Do you know how I could edit the texture for this new state? I don’t need a completely new texture, just a copy of the previous state but render it flat.

I was also looking into how the XML is loaded to see if it might be possible to override this function and patch the XML that way, if this is even possible.
The function is FruitTypeDesc.loadFromFoliageXMLFile, but I couldn’t find its code, and any attempt to prepend or override it caused the game to stop loading.


Note: Log in to post. Create a new account here.