Community Forum


Forum Overview >> Scripting

Created27.09.2019 22:56

John Deere (JDeere2012) 27.09.2019 22:56
Hello, I am trying to enhance the wheelDestruction. Sadly the "destroyFruitArea" is not further explained in the Docs. Therefore I tried to use the FS17 mod from Giants but the "Utils.getXZWidthAndHeight" gave me the same problem... I cannot research what is about bc there is no mentioning in the Docs, they are just using it.

Now I am wondering what is it about those methods that Giants is using, but are not explained in the Docs. Are there some hidden Docs and am I just dumb or are those docs restricted.


Gtx | Andy (GtX_Andy) 28.09.2019 01:04
More than half of the lua docs are not shared by Giants and many of the ones shared are missing many functions. Unfortunately this is the new normal and has gotten much worse since I started to mod and script in 13. :-(

I am not really understanding what part you are exactly having an issue with but I can explain the 'getXZWidthAndHeight' function.
Important: This function is no longer part of the 'Utils'. It is now found as part of 'MathUtil'

You need to provide 6 variables to this function.These will be the area X and Z values for Start, Width and Height nodes if this is what your calculating. Basically this function is just trimming the given values (Normal X and Z world translation of each) to give the correct Width and Height values.

The function would look something like this ;-)

function getXZWidthAndHeight(startX, startZ, widthX, widthZ, heightX, heightZ)
return startX, startZ, widthX - startX, widthZ - startZ, heightX - startX, heightZ - startZ;

This is just and example and you are still best using built in function
'MathUtil.getXZWidthAndHeight(startX, startZ, widthX, widthZ, heightX, heightZ)

Cheers, GtX

John Deere (JDeere2012) 28.09.2019 02:08
Dude, you don't know how thankful I am right now about your answer ;D

I've been driving crazy bc I haven't found anything and it is very sad that Giants is going down this route. Maybe they just didn't have enough people and this will get better in the future.

Regarding the coding, I took the following:

function RealCropDestruction:destroyFruitArea(self, x0, z0, x1,z1, x2, z2)

local x, z, widthX, widthZ, heightX, heightZ = MathUtils.getXZWidthAndHeight(nil, x0, z0, x1, z1, x2, z2 );

for index, entry in pairs(g_currentMission.fruits) do

local desc = FruitUtil.fruitIndexToDesc[index];
if desc.allowsSeeding then
local detailId = g_currentMission.terrainDetailId;

if desc.preparingOutputName ~= nil and entry.preparingOutputId ~= nil then
setDensityCompareParams(entry.preparingOutputId, "equal", 0);
setDensityMaskParams(entry.preparingOutputId, "between", 2, desc.maxPreparingGrowthState+1);
setDensityMaskedParallelogram(entry.preparingOutputId, x,z, widthX,widthZ, heightX,heightZ, 0, 1,, 0, g_currentMission.numFruitStateChannels, 1);
setDensityCompareParams(entry.preparingOutputId, "greater", -1);
setDensityMaskParams(entry.preparingOutputId, "greater", 0);

setDensityCompareParams(, "between", 2, desc.maxPreparingGrowthState+1);
setDensityParallelogram(, x,z, widthX,widthZ, heightX,heightZ, 0, g_currentMission.numFruitStateChannels, desc.cutState+1);
setDensityCompareParams(, "greater", -1);
--elseif desc.cutState < desc.minHarvestingGrowthState then
elseif index == FruitUtil.FRUITTYPE_GRASS then
-- grass
setDensityCompareParams(, "between", desc.minHarvestingGrowthState+1, desc.maxHarvestingGrowthState+1);
setDensityParallelogram(, x,z, widthX,widthZ, heightX,heightZ, 0, g_currentMission.numFruitStateChannels, desc.cutState+2);
setDensityCompareParams(, "greater", -1);
--elseif desc.minHarvestingGrowthState == desc.maxHarvestingGrowthState then
elseif index == FruitUtil.FRUITTYPE_OILSEEDRADISH then
-- oilseed, no destruction
-- all other/normal fruits
setDensityCompareParams(, "greater", 2);
setDensityMaskedParallelogram(, x,z, widthX,widthZ, heightX,heightZ, 0, g_currentMission.numFruitDensityMapChannels, detailId, g_currentMission.terrainDetailTypeFirstChannel, g_currentMission.terrainDetailTypeNumChannels, desc.cutState+1);
setDensityCompareParams(, "greater", -1);

From the FS17 CropDestruction Mod bc somehow the area where the fruit gets destroyed is always to big and too far west.
Here a pic:
(already added destruction to CareWheels)

Lastly, I want to ask you if there is any big Forum regarding such topics or modding in general? Bc somehow you must have known that the function got moved into MathUtil :P

Greedings, Taka

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