LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

SemiTrailerFront

Description
Specialization for detachable front part of separable semi trailers
Functions

isDetachAllowed

Description
Returns true if detach is allowed
Definition
isDetachAllowed()
Return Values
booleandetachAlloweddetach is allowed
Code
98function SemiTrailerFront:isDetachAllowed(superFunc)
99 local canBeDatached, warning = superFunc(self)
100 if not canBeDatached then
101 return false, warning
102 end
103
104 local spec = self.spec_semiTrailerFront
105 return spec.attachedSemiTrailerBack ~= nil, nil
106end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
41function SemiTrailerFront:onLoad(savegame)
42 local spec = self.spec_semiTrailerFront
43 spec.inputAttacherCurFade = 1
44 spec.inputAttacherFadeDir = 1
45 spec.inputAttacherFadeDuration = 1000
46
47 spec.joint = self.spec_attachable.inputAttacherJoints[1]
48 spec.joint.lowerRotLimitScaleBackup = {spec.joint.lowerRotLimitScale[1], spec.joint.lowerRotLimitScale[2], spec.joint.lowerRotLimitScale[3]}
49
50 spec.attachedSemiTrailerBack = nil
51 spec.inputAttacherImplement = nil
52 spec.doSemiTrailerLockCheck = true
53end

onPostAttach

Description
Called after vehicle was attached
Definition
onPostAttach(table attacherVehicle, integer inputJointDescIndex, integer jointDescIndex)
Arguments
tableattacherVehicleattacher vehicle
integerinputJointDescIndexindex of input attacher joint
integerjointDescIndexindex of attacher joint it was attached to
Code
140function SemiTrailerFront:onPostAttach(attacherVehicle, inputJointDescIndex, jointDescIndex)
141 local spec = self.spec_semiTrailerFront
142 spec.inputAttacherImplement = attacherVehicle:getImplementByObject(self)
143end

onPostAttachImplement

Description
Called on attaching a implement
Definition
onPostAttachImplement(table implement)
Arguments
tableimplementimplement to attach
Code
111function SemiTrailerFront:onPostAttachImplement(attachable, inputJointDescIndex, jointDescIndex)
112 local spec = self.spec_semiTrailerFront
113 spec.attachedSemiTrailerBack = attachable
114 spec.inputAttacherFadeDir = 1000
115end

onPreDetach

Description
Called if vehicle gets detached
Definition
onPreDetach(table attacherVehicle, table implement)
Arguments
tableattacherVehicleattacher vehicle
tableimplementimplement
Code
130function SemiTrailerFront:onPreDetach(attacherVehicle, implement)
131 local spec = self.spec_semiTrailerFront
132 spec.inputAttacherImplement = nil
133end

onPreDetachImplement

Description
Called on detaching a implement
Definition
onPreDetachImplement(integer implementIndex)
Arguments
integerimplementIndexindex of implement to detach
Code
120function SemiTrailerFront:onPreDetachImplement(implement)
121 local spec = self.spec_semiTrailerFront
122 spec.attachedSemiTrailerBack = nil
123 spec.inputAttacherFadeDir = -1
124end

onUpdate

Description
Called on update
Definition
onUpdate(float dt, boolean isActiveForInput, boolean isSelected)
Arguments
floatdttime since last call in ms
booleanisActiveForInputtrue if vehicle is active for input
booleanisSelectedtrue if vehicle is selected
Code
60function SemiTrailerFront:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
61 local spec = self.spec_semiTrailerFront
62
63 if spec.doSemiTrailerLockCheck then
64 spec.doSemiTrailerLockCheck = false
65 if spec.attachedSemiTrailerBack == nil then
66 spec.inputAttacherFadeDir = -1
67 end
68 end
69
70 if self.isServer and spec.inputAttacherImplement ~= nil and ((spec.inputAttacherCurFade > 0 and spec.inputAttacherFadeDir < 0) or (spec.inputAttacherCurFade < 1 and spec.inputAttacherFadeDir > 0)) then
71 spec.inputAttacherCurFade = MathUtil.clamp(spec.inputAttacherCurFade+(spec.inputAttacherFadeDir*dt)/spec.inputAttacherFadeDuration, 0, 1)
72
73 local lowerRotLimitScale = spec.joint.lowerRotLimitScale
74 local lowerRotLimitScaleBackup = spec.joint.lowerRotLimitScaleBackup
75 lowerRotLimitScale[1] = lowerRotLimitScaleBackup[1]*spec.inputAttacherCurFade
76 lowerRotLimitScale[2] = lowerRotLimitScaleBackup[2]*spec.inputAttacherCurFade
77 lowerRotLimitScale[3] = lowerRotLimitScaleBackup[3]*spec.inputAttacherCurFade
78
79 local attacherVehicle = self:getAttacherVehicle()
80 if attacherVehicle ~= nil then
81 local attacherJoints = attacherVehicle:getAttacherJoints()
82 local jointDesc = attacherJoints[spec.inputAttacherImplement.jointDescIndex]
83 local lowerRotLimit = spec.inputAttacherImplement.lowerRotLimit
84 local x = lowerRotLimit[1]*lowerRotLimitScale[1]
85 local y = lowerRotLimit[2]*lowerRotLimitScale[2]
86 local z = lowerRotLimit[3]*lowerRotLimitScale[3]
87
88 setJointRotationLimit(jointDesc.jointIndex, 0, true, -x, x)
89 setJointRotationLimit(jointDesc.jointIndex, 1, true, -y, y)
90 setJointRotationLimit(jointDesc.jointIndex, 2, true, -z, z)
91 end
92 end
93end

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 SemiTrailerFront.prerequisitesPresent(specializations)
18 return SpecializationUtil.hasSpecialization(AttacherJoints, specializations)
19end

registerEventListeners

Description
Definition
registerEventListeners()
Code
29function SemiTrailerFront.registerEventListeners(vehicleType)
30 SpecializationUtil.registerEventListener(vehicleType, "onLoad", SemiTrailerFront)
31 SpecializationUtil.registerEventListener(vehicleType, "onUpdate", SemiTrailerFront)
32 SpecializationUtil.registerEventListener(vehicleType, "onPostAttachImplement", SemiTrailerFront)
33 SpecializationUtil.registerEventListener(vehicleType, "onPreDetachImplement", SemiTrailerFront)
34 SpecializationUtil.registerEventListener(vehicleType, "onPreDetach", SemiTrailerFront)
35 SpecializationUtil.registerEventListener(vehicleType, "onPostAttach", SemiTrailerFront)
36end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
23function SemiTrailerFront.registerOverwrittenFunctions(vehicleType)
24 SpecializationUtil.registerOverwrittenFunction(vehicleType, "isDetachAllowed", SemiTrailerFront.isDetachAllowed)
25end