FS22 Modding - Trying to make a script for balers

Your forum for all discussions around Modding.
Paxol
Posts: 2
Joined: Mon Jan 16, 2023 11:52 am

FS22 Modding - Trying to make a script for balers

Post by Paxol »

Hi, I'm new to FS22 modding/scripting. I want to do a script that stops the cruise control when the baler is 99% full.

I started modifing the "Fill level warning" mod, first I add the specialization to vehicles that has the Baler specialization

Code: Select all

local modName = g_currentModName;
function injectSpecialization()
  local modNameSpecName = modName .. "." .. "fillLevelWarning"

  for vehicleTypeName, vehicleType in pairs(g_vehicleTypeManager.types) do
    if SpecializationUtil.hasSpecialization(Baler, vehicleType.specializations) then
      print("DEBUG: registred specialization")
      g_vehicleTypeManager:addSpecialization(vehicleTypeName, modNameSpecName)
    end
  end
end

TypeManager.validateTypes = Utils.appendedFunction(TypeManager.validateTypes, function(self)
  if self.typeName == "vehicle" then
    injectSpecialization()
  end
end)
In the specialization script I can successfully detect when the bale is at 99%

Code: Select all

function fillLevelWarning:onUpdate(dt)
  local fillLevel = self:getFillUnitFillLevelPercentage(1)

  if fillLevel ~= nil then
    if fillLevel >= 0.99 then
      if not self.notified then
        print("DEBUG: fill level 99%")
        self.notified = true
      end
    else
      self.notified = false
    end
  end
end
but I don't find any (easy) way to toggle the cruise control

Thanks to anyone trying to help me.

Edit don_apple: topic moved from "General Discussion" to "Modding", since it is about creating/changing a mod and not about the game itself.
Paxol
Posts: 2
Joined: Mon Jan 16, 2023 11:52 am

Re: FS22 Modding - Trying to make a script for balers

Post by Paxol »

I managed to archive the desired behaviour with this code (requiring the attachable specialization):

Code: Select all

print("DEBUG: fill level 92%")

local rootVehicle = self.spec_attachable.attacherVehicle

if rootVehicle ~= nil and rootVehicle.setCruiseControlState ~= nil then
  rootVehicle:setCruiseControlState(Drivable.CRUISECONTROL_STATE_OFF, false)
end

self.notified = true
If anyone has a better solution please post a reply :)
Post Reply