LUADOC - Farming Simulator 17

Printable Version

Script v1.4.4.0

Engine v7.0.0.2

Foundation Reference

SemiTrailerFront

Description
This is the specialization for semi trailer fronts
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 SemiTrailerFront.prerequisitesPresent(specializations)
18 return SpecializationUtil.hasSpecialization(AttacherJoints, specializations);
19end

preLoad

Description
Called before loading
Definition
preLoad(table savegame)
Arguments
tablesavegamesavegame
Code
24function SemiTrailerFront:preLoad(savegame)
25 self.isDetachAllowed = Utils.overwrittenFunction(self.isDetachAllowed, SemiTrailerFront.isDetachAllowed);
26end

load

Description
Called on loading
Definition
load(table savegame)
Arguments
tablesavegamesavegame
Code
31function SemiTrailerFront:load(savegame)
32 self.inputAttacherCurFade = 1;
33 self.inputAttacherFadeDir = 1;
34 self.inputAttacherFadeDuration = 1000;
35
36 local joint = self.inputAttacherJoints[1]
37 joint.lowerRotLimitScaleBackup = {joint.lowerRotLimitScale[1], joint.lowerRotLimitScale[2], joint.lowerRotLimitScale[3]}
38
39 self.attachedSemiTrailerBack = nil;
40 self.doSemiTrailerLockCheck = true
41end

update

Description
Called on update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Code
55function SemiTrailerFront:update(dt)
56 if self.doSemiTrailerLockCheck then
57 self.doSemiTrailerLockCheck = false
58 if self.attachedSemiTrailerBack == nil then
59 self.inputAttacherFadeDir = -1;
60 end
61 end
62
63 if self.isServer and self.inputAttacherImplement ~= nil and ((self.inputAttacherCurFade > 0 and self.inputAttacherFadeDir < 0) or (self.inputAttacherCurFade < 1 and self.inputAttacherFadeDir > 0)) then
64 self.inputAttacherCurFade = Utils.clamp(self.inputAttacherCurFade+(self.inputAttacherFadeDir*dt)/self.inputAttacherFadeDuration, 0, 1)
65 self.inputAttacherJoints[1].lowerRotLimitScale[1] = self.inputAttacherJoints[1].lowerRotLimitScaleBackup[1]*self.inputAttacherCurFade
66 self.inputAttacherJoints[1].lowerRotLimitScale[2] = self.inputAttacherJoints[1].lowerRotLimitScaleBackup[2]*self.inputAttacherCurFade
67 self.inputAttacherJoints[1].lowerRotLimitScale[3] = self.inputAttacherJoints[1].lowerRotLimitScaleBackup[3]*self.inputAttacherCurFade
68
69 local jointDesc = self.attacherVehicle.attacherJoints[self.inputAttacherImplement.jointDescIndex]
70 local x = self.inputAttacherImplement.lowerRotLimit[1]*self.inputAttacherJoints[1].lowerRotLimitScale[1];
71 local y = self.inputAttacherImplement.lowerRotLimit[2]*self.inputAttacherJoints[1].lowerRotLimitScale[2];
72 local z = self.inputAttacherImplement.lowerRotLimit[3]*self.inputAttacherJoints[1].lowerRotLimitScale[3];
73
74 setJointRotationLimit(jointDesc.jointIndex, 0, true, -x, x);
75 setJointRotationLimit(jointDesc.jointIndex, 1, true, -y, y);
76 setJointRotationLimit(jointDesc.jointIndex, 2, true, -z, z);
77 end
78end

onAttachImplement

Description
Called on attaching a implement
Definition
onAttachImplement(table implement)
Arguments
tableimplementimplement to attach
Code
86function SemiTrailerFront:onAttachImplement(implement)
87 self.attachedSemiTrailerBack = implement.object;
88 self.inputAttacherFadeDir = 1000;
89end

onDetachImplement

Description
Called on detaching a implement
Definition
onDetachImplement(integer implementIndex)
Arguments
integerimplementIndexindex of implement to detach
Code
94function SemiTrailerFront:onDetachImplement(implementIndex)
95 self.attachedSemiTrailerBack = nil;
96 self.inputAttacherFadeDir = -1;
97end

onDetach

Description
Called if vehicle gets detached
Definition
onDetach(table attacherVehicle, integer jointDescIndex)
Arguments
tableattacherVehicleattacher vehicle
integerjointDescIndexindex of attacher joint it was attached to
Code
103function SemiTrailerFront:onDetach(attacherVehicle, jointDescIndex)
104 self.inputAttacherImplement = nil;
105end

onAttached

Description
Called after vehicle was attached
Definition
onAttached(table attacherVehicle, integer jointDescIndex)
Arguments
tableattacherVehicleattacher vehicle
integerjointDescIndexindex of attacher joint it was attached to
Code
111function SemiTrailerFront:onAttached(attacherVehicle, implement)
112 self.inputAttacherImplement = attacherVehicle:getImplementByObject(self);
113end

isDetachAllowed

Description
Returns true if detach is allowed
Definition
isDetachAllowed()
Return Values
booleandetachAlloweddetach is allowed
Code
118function SemiTrailerFront:isDetachAllowed(superFunc)
119 if superFunc ~= nil then
120 if not superFunc(self) then
121 return false;
122 end
123 end
124 return self.attachedSemiTrailerBack ~= nil;
125end