-- Local compatibility adapter. Original Workshop files remain dependencies. KFTFerret = KFTFerret or {} local F = KFTFerret F.scriptName = "Base.62daimlerFerretMk2" F.weaponPart = "KFT_FerretMG" F.ammoType = "Base.762x63mm" F.version = 1 function F.isFerret(vehicle) return vehicle ~= nil and vehicle:getScriptName() == F.scriptName end function F.isGunner(vehicle, character) return F.isFerret(vehicle) and character ~= nil and character:getVehicle() == vehicle and vehicle:getSeat(character) == 1 end function F.AmmoAccess(vehicle, part, character) return F.isGunner(vehicle, character) end function F.InitTurret(vehicle, part) local data = part:getModData() local vehicleData = vehicle:getModData() local pose = data.kftPose or vehicleData.turretAnimID or "002" vehicleData.turretAnimID = pose part:setModelVisible("Default", true) vehicle:playPartAnim(part, pose) local gloveBox = vehicle:getPartById("GloveBox") if gloveBox then gloveBox:setModelVisible("interiorTop", false) end end function F.InitGloveBox(vehicle, part) part:setModelVisible("interiorTop", false) end function F.InitWeapon(vehicle, part) local data = part:getModData() if not data.kftInitialized then -- Called once for a newly added part, including an existing-save migration. -- A removed or destroyed gun is never recreated on subsequent loads. if not part:getInventoryItem() then VehicleUtils.createPartInventoryItem(part) part:setCondition(100) end data.kftInitialized = F.version end end function F.weaponReady(vehicle) if not F.isFerret(vehicle) then return false end local part = vehicle:getPartById(F.weaponPart) return part ~= nil and part:getInventoryItem() ~= nil and part:getCondition() > 0 end function F.poseForAngle(relativeAngle) local pose = math.floor(math.floor((relativeAngle % 360) + 0.5) / 2) * 2 + 2 if pose > 360 then pose = 2 end return string.format("%03d", pose) end function F.savePose(vehicle, pose) local turret = vehicle:getPartById("Turrent") if not turret then return end vehicle:getModData().turretAnimID = pose local data = turret:getModData() if data.kftPose ~= pose then data.kftPose = pose if isServer() then vehicle:transmitPartModData(turret) end end end function F.patchScript() local script = getScriptManager():getVehicle(F.scriptName) if not script then print("[KI5FerretTurret] Ferret Mk2 script unavailable; adapter not applied.") return false end if script:getPartById(F.weaponPart) then return true end if not script:getPartById("GloveBox") or not script:getPartById("FER62HatchTurret") then print("[KI5FerretTurret] Unexpected Ferret layout; adapter not applied.") return false end -- Load merges only the named parts. Do NOT call Loaded(): in B42.21 it -- multiplies chassis dimensions and suspension by modelScale a second time. script:Load("62daimlerFerretMk2", require "KFT_FerretPatch") print("[KI5FerretTurret] Ferret Mk2 turret parts applied (v0.1.1).") return true end Events.OnGameBoot.Add(F.patchScript) Events.OnInitGlobalModData.Add(F.patchScript)