Use the registerFruit script

Game Version: FS11 and later
GE Version: ? and later


Modding Index | Map Making Tutorials


This is a simple guide on using Giants new fruit registration system. Why? this makes it possible to install fruits on your map and make it possible to play MP with those fruits. As it also eliminates the need for a Map_fruits.zip mod, or the individual type such as the potatoMOD.zip.

There are 2 things needed;

1) The script itself, which is registerFruits.lua, The example I am providing was done by Decker_MMV extra fruits added by me. I started harassing Giants about fruit registers a few months back and this pops up. I have been on GDN since FS2009 came out. So maybe they just needed a push from it's users. :)

Make a folder called scripts>in that folder create a new text file, name it registerFruits.lua>in this file put the following;

– –Example By Decker_MMIV and Sniper214 –

– 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;

2) You will need some hud images, which are widely available everywhere.  Make a folder and call it images, insert your hud files in here. Make sure the name matches that of what's in the fruitRegister.lua and it must have hud at end of name. such as;

potatoHud.png

DO NOTE: You must have the fruits themselves correctly inserted in the map01.i3d before this will work. AND remove all other fruit mods, such as ;

Map_fruits.zip mod, or the individual type such as the potatoMOD.zip.

Also as pointed out by sandgroper, cause well I am forgetful at times; you need to make an entry into your moddesc.xml to start the script when map loads.

After the </l1on> and before the <maps> insert this line;

<extraSourceFiles>      <sourceFile filename=“scripts/registerFruits.lua” />   </extraSourceFiles>

Again, thanks sandgroper :)

Ok as some of you may wonder why I called it fruitRegister in the topic and then registerFruit in the tutorial, this is unimportant. As long as the script file name is the same as in the moddesc.xml you'll be fine. To avoid confusion in the future I will rename the topic.

Thanks to x3mperformance for pointing this out.

Hope this will be useful to all of you multicrops type. :)


Original Author: Sniper214 | Date: June 08, 2011

Modding Index | Map Making Tutorials