I took a look at this, because some script-mods worked fine, where others did not - so I imagined that it could be due to the very different methods, that the script-modding community have created throughout the years, for registering/injecting their custom specializations into existing vehicle-types in Farming Simulator.
What I discovered, was that the script-mods that fails loading in patch 1.4.0.0, mostly uses old register.lua script code, including expecting that the self.spec_... member-variable is automatically created.
After a bit of trial-and-error, I managed to privately modify some of other mod-authors' script-mods that I use in my game-sessions, and got them working again. - Though there may still be other problems I have yet to discover.
DO NOT ATTEMPT THE FOLLOWING, IF YOU HAVE NO EXPERIENCE WITH MODIFYING LUA SCRIPTS!
Instead just be patient and wait for the mod-authors to fix their script-mods.
As there may be other script-modders out there, who are currently struggling with updating their mods to work again for patch 1.4.0.0, I have below explained the steps I did, for what to change and modify, to get script-mods back into a hopefully working state again - unless GIANTS Software quickly provides a hot-fix that restores the old method, of letting script-mods inject their specializations into existing vehicle-types.
Could be that some script-modders may find this information and knowledge useful.
For the below examples, I have used loki_79's Realistic Cab View mod - though it could be any other script-mod that uses an older method of registering/injecting its specializations.
1.
Remove the registration of your specialization from your Lua script, and instead put it into the modDesc.XML file
Code: Select all
// OLD - in Lua script (maybe called `register.lua`)
g_specializationManager:addSpecialization('cabView', 'CabView', Utils.getFilename('CabView.lua', g_currentModDirectory), true);
Code: Select all
// NEW - in `modDesc.xml`
<specializations>
<specialization name="cabView" className="CabView" filename="CabView.lua" />
</specializations>
2.
Change the Lua code that "register"/inject your specialization into existing vehicle-types.
There might be a "better, proper and cleaner method" for doing this (GIANTS developers, please share if possible), but for now this seems to be how it is known and done by the modding community
Code: Select all
// OLD - in Lua script (maybe called `register.lua`)
for vehicleName, vehicleType in pairs(g_vehicleTypeManager.types) do
if SpecializationUtil.hasSpecialization(Drivable, vehicleType.specializations) and
SpecializationUtil.hasSpecialization(Motorized, vehicleType.specializations) and
SpecializationUtil.hasSpecialization(Enterable, vehicleType.specializations) and
SpecializationUtil.hasSpecialization(Dashboard, vehicleType.specializations)
then
g_vehicleTypeManager:addSpecialization(vehicleName, "cabView")
print("INSTALLED: "..vehicleName)
end
end
- Adding a script-scoped variable called modName, that is assigned the value of g_currentModName.
- Moving the for-loop into a function (if not already), which I here have named injectSpecialization.
- Create local variable modNameSpecName and assign it a string-value concatinated to contain "<modName>.<specialization-name>".
- Change the #2 argument in call to g_vehicleTypeManager:addSpecialization to use the modNameSpecName variable.
- Adding new statements for appending an anonymous-function to TypeManager.validateTypes - which will check that it is type-manager for "vehicle" before calling our injectSpecialization function.
Code: Select all
// NEW - in Lua script (maybe called `register.lua`)
local modName = g_currentModName;
function injectSpecialization()
local modNameSpecName = modName .. "." .. "cabView"
for vehicleName, vehicleType in pairs(g_vehicleTypeManager.types) do
if SpecializationUtil.hasSpecialization(Drivable, vehicleType.specializations) and
SpecializationUtil.hasSpecialization(Motorized, vehicleType.specializations) and
SpecializationUtil.hasSpecialization(Enterable, vehicleType.specializations) and
SpecializationUtil.hasSpecialization(Dashboard, vehicleType.specializations)
then
g_vehicleTypeManager:addSpecialization(vehicleName, modNameSpecName)
print("INSTALLED: "..vehicleName)
end
end
end
TypeManager.validateTypes = Utils.appendedFunction(TypeManager.validateTypes, function(self)
if self.typeName == "vehicle" then
injectSpecialization()
end
end)
3.
Recreate the possibly missing self.spec_... member-variable.
For an example of how GIANTS Software does this, take a look at FS19's Precision Farming DLC mod, the SoilSampler.lua script.
Code: Select all
// OLD - in your Lua specialization script
function CabView:onLoad(savegame)
spec = self.spec_cabView
...
- First add a script-scoped variable called modName, that is assigned the value of g_currentModName.
- Then in the "first function of this specialization that gets called when a vehicle is spawned", add a new statement, that creates the wanted self.spec_... member-variable and assign it the value of the not-easily-accessible self.spec_<modName>.<specialization-name> member-variable.
Code: Select all
// NEW - in your Lua specialization script
local modName = g_currentModName
function CabView:onLoad(savegame)
self.spec_cabView = self["spec_" .. modName .. "." .. "cabView"]
local spec = self.spec_cabView
...