LUADOC - Farming Simulator 17

Printable Version

Script v1.4.4.0

Engine v7.0.0.2

Foundation Reference

BuiltInCutterTrailer

Description
Class for cutters with build in cutter trailers
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 BuiltInCutterTrailer.prerequisitesPresent(specializations)
18 return SpecializationUtil.hasSpecialization(Attachable, specializations) and SpecializationUtil.hasSpecialization(Foldable, specializations);
19end;

load

Description
Called on loading
Definition
load(table savegame)
Arguments
tablesavegamesavegame
Code
24function BuiltInCutterTrailer:load(savegame)
25
26 self.getIsFoldAllowed = Utils.overwrittenFunction(self.getIsFoldAllowed, BuiltInCutterTrailer.getIsFoldAllowed);
27 self.isDetachAllowed = Utils.overwrittenFunction(self.isDetachAllowed, BuiltInCutterTrailer.isDetachAllowed);
28 self.getIsInputAttacherActive = Utils.overwrittenFunction(self.getIsInputAttacherActive, BuiltInCutterTrailer.getIsInputAttacherActive);
29
30 local i=0;
31 while true do
32 local baseName = string.format("vehicle.movingTools.movingTool(%d)", i);
33 if not hasXMLProperty(self.xmlFile, baseName) then
34 break;
35 end;
36
37 local node = Utils.indexToObject(self.components, getXMLString(self.xmlFile, baseName.."#index"));
38 local disableInTrailerMode = Utils.getNoNil(getXMLBool(self.xmlFile, baseName.."#disableInTrailerMode"), false);
39 for _, tool in pairs(self.movingTools) do
40 if tool.node == node then
41 tool.disableInTrailerMode = disableInTrailerMode;
42 break;
43 end;
44 end;
45 i = i + 1;
46 end;
47end;

onAttach

Description
Called if vehicle gets attached
Definition
onAttach(table attacherVehicle, integer jointDescIndex)
Arguments
tableattacherVehicleattacher vehicle
integerjointDescIndexindex of attacher joint it gets attached to
Code
68function BuiltInCutterTrailer:onAttach(attacherVehicle, jointDescIndex)
69 local jointDesc = attacherVehicle.attacherJoints[jointDescIndex];
70 if jointDesc.jointType == AttacherJoints.JOINTTYPE_CUTTER then
71 for _, tool in pairs(self.movingTools) do
72 if tool.disableInTrailerMode then
73 tool.isActive = true;
74 end;
75 end;
76 self.attachedAsTrailer = false;
77 else
78 self:playAnimation("drawbarSetup", -1, nil, true);
79 for _, tool in pairs(self.movingTools) do
80 if tool.disableInTrailerMode then
81 tool.isActive = false;
82 end;
83 end;
84 self.attachedAsTrailer = true;
85 end;
86end;

onDetach

Description
Called if vehicle gets detached
Definition
onDetach()
Code
90function BuiltInCutterTrailer:onDetach()
91 if self.attachedAsTrailer then
92 self:playAnimation("drawbarSetup", 1, nil, true);
93 end;
94end;

getIsInputAttacherActive

Description
Returns true if input attacher is active and can be used to attach
Definition
getIsInputAttacherActive(table inputAttacherJoint)
Arguments
tableinputAttacherJointinput attacher joint
Return Values
booleanisActiveinput attacher is active
Code
100function BuiltInCutterTrailer:getIsInputAttacherActive(superFunc, inputAttacherJoint)
101 if inputAttacherJoint.jointType == AttacherJoints.JOINTTYPE_TRAILERLOW then
102 if self.foldAnimTime ~= nil and self.foldAnimTime == 1 then
103 return false;
104 end;
105 end;
106
107 if superFunc ~= nil then
108 return superFunc(self);
109 end
110 return true;
111end;

isDetachAllowed

Description
Returns true if detach is allowed
Definition
isDetachAllowed()
Return Values
booleandetachAlloweddetach is allowed
Code
116function BuiltInCutterTrailer:isDetachAllowed(superFunc)
117 if self.foldAnimTime ~= nil then
118 if self.foldAnimTime > 0 and self.foldAnimTime < 1 then
119 return false;
120 end;
121 end;
122
123 if superFunc ~= nil then
124 return superFunc(self);
125 end
126 return true;
127end;

getIsFoldAllowed

Description
Returns if fold is allowed
Definition
getIsFoldAllowed(boolean onAiTurnOn)
Arguments
booleanonAiTurnOncalled on ai turn on
Return Values
booleanallowsFoldallows folding
Code
133function BuiltInCutterTrailer:getIsFoldAllowed(superFunc, onAiTurnOn)
134 if self.attacherVehicle ~= nil then
135 local implement = self.attacherVehicle:getImplementByObject(self);
136 local jointDesc = self.attacherVehicle.attacherJoints[implement.jointDescIndex];
137 if jointDesc.jointType ~= AttacherJoints.JOINTTYPE_CUTTER then
138 return false;
139 end;
140 end;
141
142 if superFunc ~= nil then
143 return superFunc(self, onAiTurnOn);
144 end
145 return true;
146end