LUADOC - Farming Simulator 17

Printable Version

Script v1.4.4.0

Engine v7.0.0.2

Foundation Reference

FrontloaderAttacher

Description
Class for vehicles with attachable frontloaders
Functions

prerequisitesPresent

Description
Checks if all prerequisite specializations are loaded
Definition
prerequisitesPresent(table specializations)
Arguments
tablespecializationsspecializations
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
17function FrontloaderAttacher.prerequisitesPresent(specializations)
18 return SpecializationUtil.hasSpecialization(AttacherJoints, specializations);
19end

load

Description
Called on loading
Definition
load(table savegame)
Arguments
tablesavegamesavegame
Code
24function FrontloaderAttacher:load(savegame)
25 if self.configurations["frontloader"] ~= nil then
26 self.frontloaderAttacher = {};
27 self.frontloaderAttacher.attacherJoint = {};
28 local key = string.format("vehicle.frontloaderConfigurations.frontloaderConfiguration(%d)", self.configurations["frontloader"]-1);
29 if self:loadAttacherJointFromXML(self.frontloaderAttacher.attacherJoint, self.xmlFile, key..".attacherJoint") then
30 table.insert(self.attacherJoints, self.frontloaderAttacher.attacherJoint);
31
32 local frontAxisLimitJoint = Utils.getNoNil(getXMLBool(self.xmlFile, key..".attacherJoint#frontAxisLimitJoint"), true)
33 if frontAxisLimitJoint then
34 local frontAxisJoint = Utils.getNoNil(getXMLInt(self.xmlFile, key..".attacherJoint#frontAxisJoint"), 0)
35 if self.componentJoints[frontAxisJoint+1] ~= nil then
36 self.frontloaderAttacher.frontAxisJoint = frontAxisJoint+1
37 else
38 print("Warning: Invalid front-axis joint '"..tostring(frontAxisJoint).."' in '"..self.configFileName.."'")
39 end
40 end
41
42 ObjectChangeUtil.updateObjectChanges(self.xmlFile, "vehicle.frontloaderConfigurations.frontloaderConfiguration", self.configurations["frontloader"], self.components, self);
43 else
44 -- first config is "no-frontloader"-option
45 ObjectChangeUtil.updateObjectChanges(self.xmlFile, "vehicle.frontloaderConfigurations.frontloaderConfiguration", 1, self.components, self);
46 self.frontloaderAttacher = nil;
47 end
48 end
49end

onDetachImplement

Description
Called on detaching a implement
Definition
onDetachImplement(integer implementIndex)
Arguments
integerimplementIndexindex of implement to detach
Code
69function FrontloaderAttacher:onDetachImplement(implementIndex)
70 local implement = self.attachedImplements[implementIndex];
71 local attacherJoint = self.attacherJoints[implement.jointDescIndex]
72 if attacherJoint.jointType == AttacherJoints.JOINTTYPE_ATTACHABLEFRONTLOADER and self.isServer then
73 if self.frontloaderAttacher.frontAxisJoint ~= nil then
74 for i=1, 3 do
75 self:setComponentJointRotLimit(self.componentJoints[self.frontloaderAttacher.frontAxisJoint], i, -self.frontloaderAttacher.rotLimit[i], self.frontloaderAttacher.rotLimit[i])
76 end
77 end
78 end
79end

onAttachImplement

Description
Called on attaching a implement
Definition
onAttachImplement(table implement)
Arguments
tableimplementimplement to attach
Code
84function FrontloaderAttacher:onAttachImplement(implement)
85 local attacherJoint = self.attacherJoints[implement.jointDescIndex]
86 if attacherJoint.jointType == AttacherJoints.JOINTTYPE_ATTACHABLEFRONTLOADER and self.isServer then
87 if self.frontloaderAttacher.frontAxisJoint ~= nil then
88 -- copy rotlimit
89 self.frontloaderAttacher.rotLimit = {unpack(self.componentJoints[self.frontloaderAttacher.frontAxisJoint].rotLimit)}
90 for i=1, 3 do
91 self:setComponentJointRotLimit(self.componentJoints[self.frontloaderAttacher.frontAxisJoint], i, 0, 0)
92 end
93 end
94 end
95end