How to convert a mower into a mulcher?

Your forum for all discussions around Modding.
Hardrada
Posts: 4
Joined: Tue Aug 13, 2024 12:44 am

How to convert a mower into a mulcher?

Post by Hardrada »

Hello good folks,

I'm a total rookie when it comes to xml editing, but i'm trying to make a mower function as a mulcher with no sucess. I have changed everything related to "mower" in the vehicle.xml into "mulcher" (typedesc, workArea: type&functionName, effecttype etc) with no effect. I tried to just replace the <mower> section and replacing it with a <mulcher> section by copying from a mulcher xml, just kept the same linknode and workAreaindex and i also tried to add a <mulcher> in addition to the mower section by looking at another mod with option for both functions. But i simply cant make it mulch ingame.

What am i missing here? Do i need to edit something in the i3d. file aswell? I'm happy to provide more information if needed and greatly appriciate it if someone is willing to help me out here and point me in the right direction.
User avatar
LS-Lara
Posts: 525
Joined: Sun Aug 04, 2019 4:57 pm

Re: How to convert a mower into a mulcher?

Post by LS-Lara »

Hmm, in principle it sounds about right, but it is hard to tell if you forgot some little detail somewhere.
You won't need to change anything but the XML, as long as you only want to adapt the function of the device.

For a quick test, I've just modded a Sepp Knüsel F240 mower into a mulcher with only very few lines of code within minutes - it is indeed not very complicated.

Maybe you want to share your XML here (use forum file upload) so some more eyes can have a look for potential issues?
Der Sinn des Lebens ist:
29.61%

Mein Traktor:
Base:
HP Pavilion 690-03xx
Core i7-8700 @ 3.2GHz
NVIDIA GeForce GTX 1060 6GB
2x Benq GL2450H
Windows 10 Home 64bit
Custom:
2 x 16GB Corsair Vengeance LPX DDR4 C16 XMP 2.0
Samsung NVMe M.2 970 EVO Plus 500GB
Samsung SSD 860 EVO 1TB
Logitech G203 Prodigy
Logitech Wireless F710
Hardrada
Posts: 4
Joined: Tue Aug 13, 2024 12:44 am

Re: How to convert a mower into a mulcher?

Post by Hardrada »

Firstly, thank you for the reply Lara and offer to help. I figured out the issue today why it won't mulch and that was because of the modDesc.xml. I added specialization "mulcher" and now it will mulch, but by doing that i created another wierd issue. Now the vehicle (a selfpropelled mower from the micro tractor pack) only works if i turn the mower/mulcher on.

By only enter the vehicle and turn on the engine nothing happens and i can't even exit the vehicle, even the dashboard display/HUB don't show up, but by turning on the mower everything works. So i have to mulch the entire time do get it to drive.

It doesn't work uploading the modDesc.xml because this forum detects it as a possible attack vector so i try add it here. I changed the stumpCutter to "mulcher" :

Code: Select all

    <vehicleTypes>

            <type name="tobata" parent="baseDrivable" className="Vehicle" filename="$dataS/scripts/vehicles/Vehicle.lua">
            <specialization name="fillVolume"/>
            <specialization name="dischargeable"/>
            <specialization name="trailer"/>
            <specialization name="tensionBelts"/>
            <specialization name="foldable"/>
            <specialization name="cover"/>
        </type>


        <type name="tobatasolo" parent="baseDrivable" filename="$dataS/scripts/vehicles/Vehicle.lua">
            <specialization name="fillVolume" />
            <specialization name="dischargeable" />
            <specialization name="turnOnVehicle" />
            <specialization name="foldable" />
            <specialization name="cylinderedFoldable" />
            <specialization name="bunkerSiloInteractor" />
            <specialization name="shovel" />
            <specialization name="groundReference" />
            <specialization name="workArea" />
            <specialization name="workParticles" />
            <specialization name="testAreas" />
            <specialization name="mower" />
            <specialization name="powerConsumer" />
            <specialization name="workMode" />
            <specialization name="pushHandTool" />
        </type>
        <type name="rocadeira" parent="selfPropelledMower" className="Vehicle" filename="$dataS/scripts/vehicles/Vehicle.lua">
            <specialization name="stumpCutter" />
        </type>


    </vehicleTypes>
Attachments
rocadeira.xml
The xml i edited
(32.23 KiB) Downloaded 87 times
rocadeiraoriginal.xml
Origninal xml
(33.69 KiB) Downloaded 80 times
User avatar
LS-Lara
Posts: 525
Joined: Sun Aug 04, 2019 4:57 pm

Re: How to convert a mower into a mulcher?

Post by LS-Lara »

OK, with your mod being some self-propelled mower instead of an implement makes this rather tricky, but not impossibe.

With your setup, you should have two items in your log:

Problem 1

Code: Select all

Warning: Missing fruit type converter in 'C:/Users/.../rocadeiraMulcher.xml'
This is some "classical" issue.
The vehicleType "selfPropelledMower" includes the "mower" specialization and that requires a fruitTypeConverter as mandatory.
Now, you could either define your own vehicleType with only those specializations needed for your model, or you simply put this into your XML:

Code: Select all

<mower fruitTypeConverter="MOWER" />
It won't impact any functionality, it simply satisfies the formal aspects to avoids the warning.

Problem 2

Code: Select all

Error: Running LUA method 'update'.
dataS/scripts/vehicles/specializations/Mulcher.lua(312) : attempt to call method 'getIsImplementChainLowered' (a nil value)
Now this is actually the main issue.
Like many other specializations, the mulcher-specialization has a function "doCheckSpeedLimit" which tests under which conditions the vehicle speed shall be limited (in this case to 15km/h).
For mulchers, the developers apparently assumed that they will always be some implement and not a self-propelled vehicle.
So, the function will check whether or not the implement and any implements it may be attached to is actually lowered, using the function "getIsImplementChainLowered".
Unfortunately, this one is included in the attachable-specialization, which is not active in your vehicle (and it would make no sense to have it).
As a result, the engine unsuccessfully tries to load something it cannot find ... again and again and again ... causing the game to go crazy.

I tried some simple workarounds, but those would cause other issues, mainly with the helper.
So, my solution is a simple script that will alter the way of decision making for the "doCheckSpeedLimit" function.

Important: you need a consistent name for your vehicleType in all files, I have chosen "rocadeiraMulcher".

So, modDesc.xml will have this:

Code: Select all

<type name="rocadeiraMulcher" parent="selfPropelledMower" className="Vehicle" filename="$dataS/scripts/vehicles/Vehicle.lua">
    <specialization name="mulcher" />
</type>
and your vehicle XML this:

Code: Select all

<vehicle type="rocadeiraMulcher"
In your modDesc.xml you also add this:

Code: Select all

<extraSourceFiles>
    <sourceFile filename="DrivenMulcher.lua" />
</extraSourceFiles>
and create a file named "DrivenMulcher.lua" in your mod with this content:

Code: Select all

--[[
https://forum.giants-software.com/viewtopic.php?t=207905
Source of the original code: Mulcher.lua by Giants Software
]]
print("---> LOADING SCRIPT: DrivenMulcher.lua")
DrivenMulcher = {}
function DrivenMulcher:doCheckSpeedLimit(superFunc)
    local vehicleTypeName = self.typeName
    local moddedTypeName = "rocadeiraMulcher"
    if string.find(vehicleTypeName, moddedTypeName) then
        return self:getIsTurnedOn()
    else
        return self:getIsImplementChainLowered()
    end
end
Mulcher.doCheckSpeedLimit = Utils.overwrittenFunction(Mulcher.doCheckSpeedLimit, DrivenMulcher.doCheckSpeedLimit)
What actually happens here is, that the script will check whether the vehicle is actually one with your special vehicleType.
In that case, the speed check will be done by whether the mulcher is switched on or not.
In all other cases, i.e. with any normal attached mulcher, the speed test will be done as originally intended.

Have a try and check out whether everything works as intended.
Der Sinn des Lebens ist:
29.61%

Mein Traktor:
Base:
HP Pavilion 690-03xx
Core i7-8700 @ 3.2GHz
NVIDIA GeForce GTX 1060 6GB
2x Benq GL2450H
Windows 10 Home 64bit
Custom:
2 x 16GB Corsair Vengeance LPX DDR4 C16 XMP 2.0
Samsung NVMe M.2 970 EVO Plus 500GB
Samsung SSD 860 EVO 1TB
Logitech G203 Prodigy
Logitech Wireless F710
Hardrada
Posts: 4
Joined: Tue Aug 13, 2024 12:44 am

Re: How to convert a mower into a mulcher?

Post by Hardrada »

Holy molly. You actually went the extra a mile and fixed it and even made a custom script for me and explained everything along the way. I am truly grateful! This was way more complicated than i tought and i would never had managed this or even identified the real problem with my extremly limited knowledge. I will test this as soon as i get a moment of spare time. Just wanted to say thank you very much in advance!!
Hardrada
Posts: 4
Joined: Tue Aug 13, 2024 12:44 am

Re: How to convert a mower into a mulcher?

Post by Hardrada »

Aaaand it works flawlessly! Can't thank you enough for the help Lara !
Post Reply