Community Forum

registerFruit.lua not compatible with DLC2

Forum Overview >> Scripting

CategoryScripting
Created26.06.2011 19:56


Mike Gregor (Unknown) 26.06.2011 20:04
I have been using the registerFruit.lua script for adding multiple fruits 31 to be exact. This avoids the need for a fruitMOD in the mods folder and is MP ready. Anyways I am suure you are aware of it :P I have been banging my head against the wall trying to get the DLC3Bga.lua and registerFruit.lua to behave with each other and it's a no go. If I do have the fruit script with DLC2 the game crashes. I remove it, the map will load. If I remove the DLC2 from the game, the map will load. I prefer to have the fruits cause my map is built around them. BUT I would also like the DLC2, since I did pay for it after all.

Here is the fruit script;

[code]
--
--
--


-- Register fruits
function RegisterFruits()
local fruitList = {};

-- Notes:
-- "type" is not accurate. It were an attempt to group the fruits, so they may be easier selected at silos/sell-points.
-- "fruitName" must be the same as in the FoliageSubLayers.
table.insert(fruitList, {type="fruit" ,fruitName="artichoke" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=4 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="fruit" ,fruitName="aubergine" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=4 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="lettuce" ,fruitName="blumkohl" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=4 ,pricePerLiter=0.2 ,literPerQm=5 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="root" ,fruitName="carrot" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=3 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="flower" ,fruitName="cotton" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=4 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="fruit" ,fruitName="erbse" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=3 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="fruit" ,fruitName="gelbbo" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=4 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="grain" ,fruitName="greenwheat" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=4 ,pricePerLiter=0.42 ,literPerQm=1 ,seedUsagePerQm=0.01 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="fruit" ,fruitName="gruenbo" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=4 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="fruit" ,fruitName="melone" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=3 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="flower" ,fruitName="mohn" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=4 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="grain" ,fruitName="oat" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=true ,minHarvestingGrowthState=4 ,pricePerLiter=0.42 ,literPerQm=1 ,seedUsagePerQm=0.01 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="fruit" ,fruitName="pea" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=4 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="root" ,fruitName="potato" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=1 ,pricePerLiter=0.4 ,literPerQm=0.8 ,seedUsagePerQm=0.02 ,seedPricePerLiter=0.1} );
table.insert(fruitList, {type="root" ,fruitName="radieschen" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=4 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="grain" ,fruitName="rice" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=4 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="lettuce" ,fruitName="rotkohl" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=4 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="grain" ,fruitName="rye" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=4 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="fruit" ,fruitName="soybean" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=4 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="lettuce" ,fruitName="spinach" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=3 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="root" ,fruitName="sugarbeet" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=true ,minHarvestingGrowthState=3 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="root" ,fruitName="sugarcane" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=4 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="flower" ,fruitName="sunflower" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=4 ,pricePerLiter=0.42 ,literPerQm=1 ,seedUsagePerQm=0.01 ,seedPricePerLiter=0.1} );
table.insert(fruitList, {type="fruit" ,fruitName="tomato" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=3 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="lettuce" ,fruitName="wirsingkohl" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=4 ,pricePerLiter=0.20 ,literPerQm=5 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="fruit" ,fruitName="honigmelone" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=3 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );
table.insert(fruitList, {type="root" ,fruitName="champingons" ,needsSeeding=true ,allowsSeeding=true ,hasStraw=false ,minHarvestingGrowthState=3 ,pricePerLiter=0.20 ,literPerQm=4 ,seedUsagePerQm=0.50 ,seedPricePerLiter=0.5} );

--
-- Can not seed or harvest! Only for transport!
-- Make sure that 'allowsSeeding' is FALSE. If not, they would also show up in the sowing-machine!
table.insert(fruitList, {type="none" ,fruitName="manure" ,needsSeeding=false ,allowsSeeding=false,hasStraw=false ,minHarvestingGrowthState=99,pricePerLiter=1.00 ,literPerQm=9.9 ,seedUsagePerQm=9.99 ,seedPricePerLiter=9.9} );
table.insert(fruitList, {type="none" ,fruitName="liquidManure" ,needsSeeding=false ,allowsSeeding=false,hasStraw=false ,minHarvestingGrowthState=99,pricePerLiter=1.00 ,literPerQm=9.9 ,seedUsagePerQm=9.99 ,seedPricePerLiter=9.9} );
table.insert(fruitList, {type="none" ,fruitName="fertilizer" ,needsSeeding=false ,allowsSeeding=false,hasStraw=false ,minHarvestingGrowthState=99,pricePerLiter=1.00 ,literPerQm=9.9 ,seedUsagePerQm=9.99 ,seedPricePerLiter=9.9} );
table.insert(fruitList, {type="none" ,fruitName="milk" ,needsSeeding=false ,allowsSeeding=false,hasStraw=false ,minHarvestingGrowthState=99,pricePerLiter=1.00 ,literPerQm=9.9 ,seedUsagePerQm=9.99 ,seedPricePerLiter=9.9} );



--
print(string.format("Registering %d extra fruits...", table.getn(fruitList)));
for i=1, table.getn(fruitList) do
local filename = "images/".. fruitList[i].fruitName .."Hud.png";
local hudFile = Utils.getFilename(filename, g_currentModDirectory);
FruitUtil.registerFruitType(
fruitList[i].fruitName -- string fruitName
,fruitList[i].needsSeeding -- bool needsSeeding (ARGH! I spent 3-4 days trying to find out why the new crop autogrows. Then I noticed an 's' were missing, so 'needSeeding' returned nil.)
,fruitList[i].allowsSeeding -- bool allowsSeeding
,fruitList[i].hasStraw -- bool hasStraw
,fruitList[i].minHarvestingGrowthState -- int minHarvestingGrowthState
,fruitList[i].pricePerLiter -- float pricePerLiter
,fruitList[i].literPerQm -- float literPerQm
,fruitList[i].seedUsagePerQm -- float seedUsagePerQm
,fruitList[i].seedPricePerLiter -- float seedPricePerLiter
,hudFile -- file hudFruitOverlayFilename
);
end;
end;
RegisterFruits();

--
--
--
local origSowingMachineLoad = SowingMachine.load;
SowingMachine.load = function(self, xmlFile)
if origSowingMachineLoad ~= nil then
origSowingMachineLoad(self, xmlFile);
end;

--
local msg = "Info. Added seeds to '".. Utils.getNoNil(self.name, "SowingMachine") .."': ";
self.seeds = {};
for k, fruitType in pairs(FruitUtil.fruitTypes) do
-- Check if FruitType have a FoliageSubLayer-/TerrainId.
local terrainId = 0;
if g_currentMission.fruits[fruitType.index] ~= nil then
terrainId = g_currentMission.fruits[fruitType.index].id;
end;
-- Only add FruitType if its allowed to be seeded, AND have a FoliageSubLayer-/TerrainId.
if fruitType.allowsSeeding and terrainId > 0 then
table.insert(self.seeds, fruitType.index);
msg = msg .. FruitUtil.fruitIndexToDesc[ fruitType.index ].name .." ";
end;
end;
print(msg);
-- Sort the seedable fruits by generic-name.
table.sort(self.seeds, function(l,r) return (FruitUtil.fruitIndexToDesc[l].name < FruitUtil.fruitIndexToDesc[r].name); end);
end;
[/code]

Any help, advice, or a bottle of aspirin would be grateful.

Mike

Mike Gregor (Unknown) 29.06.2011 02:51
nm fixed it :)

J Puddester (Unknown) 27.08.2013 09:38
So how did you fix it Mike? I'm trying to add a second crop... first I added millet (modelled after rape) no problem... can sow, harvest and store it, no problem... but when I added sunflower (modelled after maize) I get an error in the editor (actually a full list, like this):

Error: TerrainDetail distance texture 'C:/Documents and Settings/Desktop/TEST/map/textures/foliage/foliage_sunflower_distance5_diffuse.png' incorrect format. Must be 8bit RGB format.

I've checked and rechecked the format of all png's... I believe the problem is with what is trying to read them, but the editor doesn't tell me what -that- is... it only displays the symptom, not the cause of the error...

Here are a few details of what I've set up in map01.i3d:

Millet is
densityMapTypeIndex="9"
densityMapChannelOffset="4"
numDensityMapChannels="4"
Sunflower is
densityMapTypeIndex="10"
densityMapChannelOffset="4"
numDensityMapChannels="4"

FoliageMultiLayer numChannels=12 and
numTypeIndexChannels=4

Sunflower does appear in the editor drop list just fine, and I can paint with the sunflower foliage... but why does the editor scripting window create the RGB format error when loading the map?

If you have a working zip to share that includes your lua, map edits, and even the textures and huds I would appreciate it... I wouldn't have to bang my head anymore either :-) Thanks Mike.


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