Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- AIConveyorBelt
- AIImplement
- AIVehicle
- AnimatedVehicle
- ArticulatedAxis
- Attachable
- AttacherJointControl
- AttacherJoints
- BaleGrab
- BaleLoader
- Baler
- BaleWrapper
- BaseMaterial
- BunkerSiloCompacter
- BunkerSiloInteractor
- BuyableBale
- CCTDrivable
- Combine
- ConnectionHoses
- ConveyorBelt
- Cover
- CrabSteering
- Crawlers
- Cultivator
- Cutter
- Cylindered
- CylinderedFoldable
- Dashboard
- Dischargeable
- Drivable
- DynamicallyLoadedParts
- DynamicMountAttacher
- Enterable
- FertilizingCultivator
- FertilizingSowingMachine
- FillTriggerVehicle
- FillUnit
- FillVolume
- Foldable
- FoliageBending
- ForageWagon
- FrontloaderAttacher
- FruitPreparer
- GroundAdjustedNodes
- GroundReference
- Honk
- HookLiftContainer
- HookLiftTrailer
- IKChains
- JigglingParts
- Leveler
- Lights
- LivestockTrailer
- Locomotive
- LogGrab
- ManureBarrel
- MixerWagon
- Motorized
- Mountable
- Mower
- Pickup
- Pipe
- Plow
- PowerConsumer
- PowerTakeOffs
- RandomlyMovingParts
- ReceivingHopper
- ReverseDriving
- Rideable
- RidgeMarker
- Roller
- Ropes
- SemiTrailerFront
- Shovel
- SlopeCompensation
- SmartAttach
- SowingMachine
- SpeedRotatingParts
- SplineVehicle
- Sprayer
- StrawBlower
- StumpCutter
- Suspensions
- Tedder
- TensionBeltObject
- TensionBelts
- TipOccluder
- Trailer
- TreePlanter
- TreeSaw
- TurnOnVehicle
- Washable
- WaterTrailer
- Wearable
- Weeder
- Wheels
- Windrower
- Wipers
- WoodCrusher
- WoodHarvester
- WorkArea
- WorkMode
- WorkParticles
- 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
HookLiftTrailer
DescriptionSpecialization for hooklift trailers providing separate load-up and tipping animationsFunctions
- getCanDetachContainer
- getDoConsumePtoPower
- getIsFoldAllowed
- getIsTippingAllowed
- getPtoRpm
- isDetachAllowed
- onLoad
- onPostAttachImplement
- onPostLoad
- onPreDetachImplement
- onUpdateTick
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- startTipping
- stopTipping
getCanDetachContainer
DescriptionDefinitiongetCanDetachContainer()Code
188 | function HookLiftTrailer:getCanDetachContainer() |
189 | local spec = self.spec_hookLiftTrailer |
190 | return self:getAnimationTime(spec.refAnimation) == 1 |
191 | end |
getDoConsumePtoPower
DescriptionReturns if should consume pto powerDefinition
getDoConsumePtoPower()Return Values
boolean | consume | consumePtoPower |
219 | function HookLiftTrailer:getDoConsumePtoPower(superFunc) |
220 | local spec = self.spec_hookLiftTrailer |
221 | local doConsume = superFunc(self) |
222 | |
223 | return doConsume or self:getIsAnimationPlaying(spec.refAnimation) or self:getIsAnimationPlaying(spec.unloadingAnimation) |
224 | end |
getIsFoldAllowed
DescriptionReturns if fold is allowedDefinition
getIsFoldAllowed()Return Values
boolean | allowsFold | allows folding |
196 | function HookLiftTrailer:getIsFoldAllowed(superFunc, direction, onAiTurnOn) |
197 | local spec = self.spec_hookLiftTrailer |
198 | if self:getAnimationTime(spec.unloadingAnimation) > 0 then |
199 | return false |
200 | end |
201 | |
202 | return superFunc(self, direction, onAiTurnOn) |
203 | end |
getIsTippingAllowed
DescriptionReturns if tipping is allowedDefinition
getIsTippingAllowed()Return Values
boolean | tippingAllowed | tipping is allowed |
181 | function HookLiftTrailer:getIsTippingAllowed() |
182 | local spec = self.spec_hookLiftTrailer |
183 | return self:getAnimationTime(spec.refAnimation) == 0 |
184 | end |
getPtoRpm
DescriptionReturns rpm of ptoDefinition
getPtoRpm()Return Values
float | rpm | rpm of pto |
229 | function HookLiftTrailer:getPtoRpm(superFunc) |
230 | local spec = self.spec_hookLiftTrailer |
231 | local rpm = superFunc(self) |
232 | |
233 | if self:getIsAnimationPlaying(spec.refAnimation) or self:getIsAnimationPlaying(spec.unloadingAnimation) then |
234 | return self.spec_powerConsumer.ptoRpm |
235 | else |
236 | return rpm |
237 | end |
238 | end |
isDetachAllowed
DescriptionReturns true if detach is allowedDefinition
isDetachAllowed()Return Values
boolean | detachAllowed | detach is allowed |
208 | function HookLiftTrailer:isDetachAllowed(superFunc) |
209 | if self:getAnimationTime(self.spec_hookLiftTrailer.unloadingAnimation) == 0 then |
210 | return superFunc(self) |
211 | else |
212 | return false, nil |
213 | end |
214 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
52 | function HookLiftTrailer:onLoad(savegame) |
53 | local spec = self.spec_hookLiftTrailer |
54 | |
55 | spec.jointLimits = AnimCurve:new(linearInterpolatorN) |
56 | local i = 0 |
57 | while true do |
58 | local key = string.format("vehicle.hookLiftTrailer.jointLimits.key(%d)", i) |
59 | if not hasXMLProperty(self.xmlFile, key) then |
60 | if i == 0 then |
61 | spec.jointLimits = nil |
62 | end |
63 | break |
64 | end |
65 | local t = getXMLFloat(self.xmlFile, key.."#time") |
66 | local rx,ry,rz = StringUtil.getVectorFromString(getXMLString(self.xmlFile, key.."#rotLimit")) |
67 | local tx,ty,tz = StringUtil.getVectorFromString(getXMLString(self.xmlFile, key.."#transLimit")) |
68 | rx = math.rad(Utils.getNoNil(rx, 0)) |
69 | ry = math.rad(Utils.getNoNil(ry, 0)) |
70 | rz = math.rad(Utils.getNoNil(rz, 0)) |
71 | tx = Utils.getNoNil(tx, 0) |
72 | ty = Utils.getNoNil(ty, 0) |
73 | tz = Utils.getNoNil(tz, 0) |
74 | spec.jointLimits:addKeyframe({rx, ry, rz, tx, ty, tz, time = t}) |
75 | i = i +1 |
76 | end |
77 | |
78 | spec.refAnimation = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.hookLiftTrailer.jointLimits#refAnimation"), "unfoldHand") |
79 | spec.unloadingAnimation = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.hookLiftTrailer.unloadingAnimation#name"), "unloading") |
80 | spec.unloadingAnimationSpeed = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.hookLiftTrailer.unloadingAnimation#speed"), 1) |
81 | spec.unloadingAnimationReverseSpeed = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.hookLiftTrailer.unloadingAnimation#reverseSpeed"), -1) |
82 | |
83 | spec.texts = {} |
84 | spec.texts.unloadContainer = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.hookLiftTrailer.texts#unloadContainer"), "unload_container") |
85 | spec.texts.loadContainer = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.hookLiftTrailer.texts#loadContainer"), "load_container") |
86 | spec.texts.unloadArm = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.hookLiftTrailer.texts#unloadArm"), "unload_arm") |
87 | spec.texts.loadArm = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.hookLiftTrailer.texts#loadArm"), "load_arm") |
88 | end |
onPostAttachImplement
DescriptionCalled on attaching a implementDefinition
onPostAttachImplement(table implement)Arguments
table | implement | implement to attach |
129 | function HookLiftTrailer:onPostAttachImplement(attachable, inputJointDescIndex, jointDescIndex) |
130 | local spec = self.spec_hookLiftTrailer |
131 | |
132 | local attacherJoint = attachable:getActiveInputAttacherJoint() |
133 | if attacherJoint ~= nil then |
134 | if attacherJoint.jointType == AttacherJoints.JOINTTYPE_HOOKLIFT then |
135 | local jointDesc = self:getAttacherJointByJointDescIndex(jointDescIndex) |
136 | spec.attachedContainer = {} |
137 | spec.attachedContainer.jointIndex = jointDesc.jointIndex |
138 | spec.attachedContainer.implement = self:getImplementByObject(attachable) |
139 | spec.attachedContainer.object = attachable |
140 | spec.attachedContainer.limitLocked = false |
141 | |
142 | local foldableSpec = self.spec_foldable |
143 | foldableSpec.posDirectionText = spec.texts.unloadContainer |
144 | foldableSpec.negDirectionText = spec.texts.loadContainer |
145 | end |
146 | end |
147 | end |
onPostLoad
DescriptionCalled after loadingDefinition
onPostLoad(table savegame)Arguments
table | savegame | savegame |
93 | function HookLiftTrailer:onPostLoad(savegame) |
94 | local spec = self.spec_hookLiftTrailer |
95 | local foldableSpec = self.spec_foldable |
96 | foldableSpec.posDirectionText = spec.texts.unloadArm |
97 | foldableSpec.negDirectionText = spec.texts.loadArm |
98 | end |
onPreDetachImplement
DescriptionCalled on detaching a implementDefinition
onPreDetachImplement(integer implementIndex)Arguments
integer | implementIndex | index of implement to detach |
152 | function HookLiftTrailer:onPreDetachImplement(implement) |
153 | local spec = self.spec_hookLiftTrailer |
154 | if spec.attachedContainer ~= nil then |
155 | if implement == spec.attachedContainer.implement then |
156 | local foldableSpec = self.spec_foldable |
157 | foldableSpec.posDirectionText = spec.texts.unloadArm |
158 | foldableSpec.negDirectionText = spec.texts.loadArm |
159 | spec.attachedContainer = nil |
160 | end |
161 | end |
162 | end |
onUpdateTick
DescriptionCalled on update tickDefinition
onUpdateTick(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 |
105 | function HookLiftTrailer:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
106 | local spec = self.spec_hookLiftTrailer |
107 | |
108 | if spec.attachedContainer ~= nil then |
109 | local animTime = self:getAnimationTime(spec.refAnimation) |
110 | spec.attachedContainer.object.allowsDetaching = animTime > 0.95 |
111 | |
112 | if (self:getIsAnimationPlaying(spec.refAnimation) or not spec.attachedContainer.limitLocked) and spec.jointLimits ~= nil and not spec.attachedContainer.implement.attachingIsInProgress then |
113 | local v = spec.jointLimits:get(animTime) |
114 | for i=1,3 do |
115 | setJointRotationLimit(spec.attachedContainer.jointIndex, i-1, true, -v[i], v[i]) |
116 | setJointTranslationLimit(spec.attachedContainer.jointIndex, i+2, true, -v[i+3], v[i+3]) |
117 | end |
118 | |
119 | if animTime >= 0.99 then |
120 | spec.attachedContainer.limitLocked = true |
121 | end |
122 | end |
123 | end |
124 | 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 HookLiftTrailer.prerequisitesPresent(specializations) |
18 | return SpecializationUtil.hasSpecialization(AnimatedVehicle, specializations) and SpecializationUtil.hasSpecialization(Foldable, specializations) |
19 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
41 | function HookLiftTrailer.registerEventListeners(vehicleType) |
42 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", HookLiftTrailer) |
43 | SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", HookLiftTrailer) |
44 | SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", HookLiftTrailer) |
45 | SpecializationUtil.registerEventListener(vehicleType, "onPostAttachImplement", HookLiftTrailer) |
46 | SpecializationUtil.registerEventListener(vehicleType, "onPreDetachImplement", HookLiftTrailer) |
47 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
23 | function HookLiftTrailer.registerFunctions(vehicleType) |
24 | SpecializationUtil.registerFunction(vehicleType, "startTipping", HookLiftTrailer.startTipping) |
25 | SpecializationUtil.registerFunction(vehicleType, "stopTipping", HookLiftTrailer.stopTipping) |
26 | SpecializationUtil.registerFunction(vehicleType, "getIsTippingAllowed", HookLiftTrailer.getIsTippingAllowed) |
27 | SpecializationUtil.registerFunction(vehicleType, "getCanDetachContainer", HookLiftTrailer.getCanDetachContainer) |
28 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
32 | function HookLiftTrailer.registerOverwrittenFunctions(vehicleType) |
33 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsFoldAllowed", HookLiftTrailer.getIsFoldAllowed) |
34 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "isDetachAllowed", HookLiftTrailer.isDetachAllowed) |
35 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getDoConsumePtoPower", HookLiftTrailer.getDoConsumePtoPower) |
36 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getPtoRpm", HookLiftTrailer.getPtoRpm) |
37 | end |
startTipping
DescriptionCalled on start tippingDefinition
startTipping()Code
166 | function HookLiftTrailer:startTipping() |
167 | local spec = self.spec_hookLiftTrailer |
168 | self:playAnimation(spec.unloadingAnimation, spec.unloadingAnimationSpeed, self:getAnimationTime(spec.unloadingAnimation), true) |
169 | end |
stopTipping
DescriptionCalled on stop tippingDefinition
stopTipping()Code
173 | function HookLiftTrailer:stopTipping() |
174 | local spec = self.spec_hookLiftTrailer |
175 | self:playAnimation(spec.unloadingAnimation, spec.unloadingAnimationReverseSpeed, self:getAnimationTime(spec.unloadingAnimation), true) |
176 | end |