Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
SemiTrailerFront
DescriptionSpecialization for detachable front part of separable semi trailersFunctions
- isDetachAllowed
- onLoad
- onPostAttach
- onPostAttachImplement
- onPreDetach
- onPreDetachImplement
- onUpdate
- prerequisitesPresent
- registerEventListeners
- registerOverwrittenFunctions
isDetachAllowed
DescriptionReturns true if detach is allowedDefinition
isDetachAllowed()Return Values
boolean | detachAllowed | detach is allowed |
98 | function 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 |
106 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
41 | function 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 |
53 | end |
onPostAttach
DescriptionCalled after vehicle was attachedDefinition
onPostAttach(table attacherVehicle, integer inputJointDescIndex, integer jointDescIndex)Arguments
table | attacherVehicle | attacher vehicle |
integer | inputJointDescIndex | index of input attacher joint |
integer | jointDescIndex | index of attacher joint it was attached to |
140 | function SemiTrailerFront:onPostAttach(attacherVehicle, inputJointDescIndex, jointDescIndex) |
141 | local spec = self.spec_semiTrailerFront |
142 | spec.inputAttacherImplement = attacherVehicle:getImplementByObject(self) |
143 | end |
onPostAttachImplement
DescriptionCalled on attaching a implementDefinition
onPostAttachImplement(table implement)Arguments
table | implement | implement to attach |
111 | function SemiTrailerFront:onPostAttachImplement(attachable, inputJointDescIndex, jointDescIndex) |
112 | local spec = self.spec_semiTrailerFront |
113 | spec.attachedSemiTrailerBack = attachable |
114 | spec.inputAttacherFadeDir = 1000 |
115 | end |
onPreDetach
DescriptionCalled if vehicle gets detachedDefinition
onPreDetach(table attacherVehicle, table implement)Arguments
table | attacherVehicle | attacher vehicle |
table | implement | implement |
130 | function SemiTrailerFront:onPreDetach(attacherVehicle, implement) |
131 | local spec = self.spec_semiTrailerFront |
132 | spec.inputAttacherImplement = nil |
133 | end |
onPreDetachImplement
DescriptionCalled on detaching a implementDefinition
onPreDetachImplement(integer implementIndex)Arguments
integer | implementIndex | index of implement to detach |
120 | function SemiTrailerFront:onPreDetachImplement(implement) |
121 | local spec = self.spec_semiTrailerFront |
122 | spec.attachedSemiTrailerBack = nil |
123 | spec.inputAttacherFadeDir = -1 |
124 | end |
onUpdate
DescriptionCalled on updateDefinition
onUpdate(float dt, boolean isActiveForInput, boolean isSelected)Arguments
float | dt | time since last call in ms |
boolean | isActiveForInput | true if vehicle is active for input |
boolean | isSelected | true if vehicle is selected |
60 | function 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 |
93 | end |
prerequisitesPresent
DescriptionChecks if all prerequisite specializations are loadedDefinition
prerequisitesPresent(table specializations)Arguments
table | specializations | specializations |
boolean | hasPrerequisite | true if all prerequisite specializations are loaded |
17 | function SemiTrailerFront.prerequisitesPresent(specializations) |
18 | return SpecializationUtil.hasSpecialization(AttacherJoints, specializations) |
19 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
29 | function 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) |
36 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
23 | function SemiTrailerFront.registerOverwrittenFunctions(vehicleType) |
24 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "isDetachAllowed", SemiTrailerFront.isDetachAllowed) |
25 | end |