How to add safe mode to Plough/Cultivator

Game Version: FS15 and later
GE Version: 6.x and later


Modding Index | Misc. Modding Tutorials


This tutorial explains how to add safe mod to Plough/Cultivator's

Definition of “Safe Mode”: Plough or Cultivator only works(plough/cultivate) inside the field boundaries.

Now, in this tutorial I will show you two different modifications: easy one and advanced one.

It is really simple!

1. Unzip plough/cultivator file of desire.

2. Find (plough/cultivator's name).lua file, and open it with any text editor.

3. Search for

Utils.updateCultivatorArea (x, z, x1, z1, x2, z2);
or
Utils.updatePloughrArea (x, z, x1, z1, x2, z2);

4. Change to:

Utils.updateCultivatorArea (x, z, x1, z1, x2, z2, false);
or
Utils.updatePloughrArea (x, z, x1, z1, x2, z2, false);

5. Save file and close it, then zip it back.

6. Done!

This will add a Safe Mode Switch, which will allow you to turn it on and off.

1. Unzip plough/cultivator file of desire.

2. Find (plough/cultivator's name).lua file, and open it with any text editor.

3. Declare a switch for your plough/cultivator by adding the following code under: function (plough/cultivator's name):load(xmlFile)

 self.safeMode = true;  ---- default is turn safe mode on

4. Search for

if self: getIsActiveForInput() then

if not, then we create a new one under: function (plough/cultivator's name):update(dt) Then, insert few lines of code and look like this:

if self: getIsActiveForInput() then
    if InputBinding.hasEvent(InputBinding.MySafeMode) then  ---- detect whether the safe mode button pressed
        self.safeMode = not self.safeMode;
    end;
    ...
    ...
    (whatever code it has, leave it.)
    ...
    ...
    ...
end;

Keep an eye on MySafeMode, we need it later on.

5. Search for

Utils.updateCultivatorArea (x, z, x1, z1, x2, z2);
or
Utils.updatePloughrArea (x, z, x1, z1, x2, z2);

And change to

Utils.updateCultivatorArea (x, z, x1, z1, x2, z2, not self.safeMode);
or
Utils.updatePloughrArea (x, z, x1, z1, x2, z2, not self.safeMode);

6. Add few lines of code under: function (plough/cultivator's name):draw()

 if self.safeMode then
        g_currentMission: addHelpButtonText("Switch to normal mode", InputBinding.MySafeMode);
    else
        g_currentMission: addHelpButtonText("Switch to safe mode", InputBinding.MySafeMode);
    end;
    

7. Save and close it. We've done with .lua file. Now, open modDesc.xml with text editor.

8. Search for <l10n></l10n> (This step is optional, it's for input binding text) If not, we need to add it manually. I usually add it at the end of file and before </modDesc>. now, the code look like this:

<l10n>
        <text name="MySafeMode">
            <en>(plough/cultivator's name) Safe mode switch</en>
            <de>(Pflug/Landwirt Namen)sicheren modus schalten</de>
        </text>
    </l10n>

9. Search for <inputBindings></inputBindings> (This is addressing which key for safe mode switch) If not, we need to add it manually. I usually add it at the end of file and before </modDesc>. now, the code look like this:

    <inputBindings>
        <input name="MySafeMode" category="VEHICLE" key1="KEY_x" key2="" button="" device="0" mouse="" />
    </inputBindings>
    

ps. KEY_x is for key X; if you want to use different key or keypad, please search “input binding”(or whatever it is) in the forum.

10. Save and close it. Then zip them back.

11. Done.


Original Author: Frank_tw | Date: April 05, 2012

Modding Index | Misc. Modding Tutorials