LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

Pickup

Description
Specialization for vehicles with independently lowerable PickUps (e.g. forage wagon, baler, ...)
Functions

actionEventTogglePickup

Description
Definition
actionEventTogglePickup()
Code
211function Pickup.actionEventTogglePickup(self, actionName, inputValue, callbackState, isAnalog)
212 local spec = self.spec_pickup
213 if self:getCanChangePickupState(not spec.isLowered) then
214 self:setPickupState(not spec.isLowered)
215 end
216end

allowPickingUp

Description
Definition
allowPickingUp()
Code
130function Pickup:allowPickingUp()
131 local spec = self.spec_pickup
132 return spec.isLowered
133end

getCanChangePickupState

Description
Definition
getCanChangePickupState()
Code
144function Pickup:getCanChangePickupState(newState)
145 return true
146end

getDirtMultiplier

Description
Definition
getDirtMultiplier()
Code
150function Pickup:getDirtMultiplier(superFunc)
151 local spec = self.spec_pickup
152
153 if spec.isLowered and (self.getIsTurnedOn == nil or self:getIsTurnedOn()) then
154 return superFunc(self) + self:getWorkDirtMultiplier() * self:getLastSpeed() / self.speedLimit
155 end
156
157 return superFunc(self)
158end

getIsLowered

Description
Definition
getIsLowered()
Code
137function Pickup:getIsLowered(superFunc, default)
138 local spec = self.spec_pickup
139 return spec.isLowered
140end

getWearMultiplier

Description
Definition
getWearMultiplier()
Code
162function Pickup:getWearMultiplier(superFunc)
163 local spec = self.spec_pickup
164
165 if spec.isLowered and (self.getIsTurnedOn == nil or self:getIsTurnedOn()) then
166 return superFunc(self) + self:getWorkWearMultiplier() * self:getLastSpeed() / self.speedLimit
167 end
168
169 return superFunc(self)
170end

onLoad

Description
Definition
onLoad()
Code
50function Pickup:onLoad(savegame)
51 local spec = self.spec_pickup
52
53 XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.pickupAnimation", "vehicle.pickup.animation") --FS17 to FS19
54
55 spec.isLowered = false
56 spec.animationName = Utils.getNoNil(getXMLString(self.xmlFile, "vehicle.pickup.animation#name"), "")
57 if self.playAnimation == nil or self.getIsAnimationPlaying == nil then
58 spec.animationName = ""
59 spec.isLowered = true
60 end
61 spec.animationLowerSpeed = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.pickup.animation#lowerSpeed"), 1)
62 spec.animationLiftSpeed = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.pickup.animation#liftSpeed"), -spec.animationLowerSpeed)
63 spec.animationIsDefaultLowered = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.pickup.animation#isDefaultLowered"), false)
64end

onPostLoad

Description
Definition
onPostLoad()
Code
68function Pickup:onPostLoad(savegame)
69 local spec = self.spec_pickup
70
71 if spec.animationName ~= "" then
72 local dir = -20
73 if spec.animationIsDefaultLowered then
74 dir = 20
75 spec.isLowered = true
76 end
77 self:playAnimation(spec.animationName, dir, nil, true)
78 AnimatedVehicle.updateAnimations(self, 99999999)
79 end
80end

onReadStream

Description
Definition
onReadStream()
Code
84function Pickup:onReadStream(streamId, connection)
85 local isPickupLowered = streamReadBool(streamId)
86 self:setPickupState(isPickupLowered, true)
87end

onSetLoweredAll

Description
Definition
onSetLoweredAll()
Code
98function Pickup:onSetLoweredAll(doLowering, jointDescIndex)
99 self:setPickupState(doLowering)
100end

onWriteStream

Description
Definition
onWriteStream()
Code
91function Pickup:onWriteStream(streamId, connection)
92 local spec = self.spec_pickup
93 streamWriteBool(streamId, spec.isLowered)
94end

prerequisitesPresent

Description
Definition
prerequisitesPresent()
Code
17function Pickup.prerequisitesPresent(specializations)
18 return true
19end

registerEventListeners

Description
Definition
registerEventListeners()
Code
40function Pickup.registerEventListeners(vehicleType)
41 SpecializationUtil.registerEventListener(vehicleType, "onLoad", Pickup)
42 SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", Pickup)
43 SpecializationUtil.registerEventListener(vehicleType, "onReadStream", Pickup)
44 SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", Pickup)
45 SpecializationUtil.registerEventListener(vehicleType, "onSetLoweredAll", Pickup)
46end

registerFunctions

Description
Definition
registerFunctions()
Code
23function Pickup.registerFunctions(vehicleType)
24 SpecializationUtil.registerFunction(vehicleType, "allowPickingUp", Pickup.allowPickingUp)
25 SpecializationUtil.registerFunction(vehicleType, "setPickupState", Pickup.setPickupState)
26 SpecializationUtil.registerFunction(vehicleType, "getCanChangePickupState", Pickup.getCanChangePickupState)
27end

registerLoweringActionEvent

Description
Definition
registerLoweringActionEvent()
Code
174function Pickup:registerLoweringActionEvent(superFunc, actionEventsTable, inputAction, target, callback, triggerUp, triggerDown, triggerAlways, startActive, callbackState, customIconName)
175 local spec = self.spec_pickup
176 if spec.animationName ~= "" then
177 local _, actionEventId = self:addActionEvent(spec.actionEvents, InputAction.LOWER_IMPLEMENT, self, Pickup.actionEventTogglePickup, triggerUp, triggerDown, triggerAlways, startActive, callbackState, customIconName)
178 g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_HIGH)
179
180 Pickup.updateActionEvents(self)
181
182 if inputAction == InputAction.LOWER_IMPLEMENT then
183 return
184 end
185 end
186
187 superFunc(self, actionEventsTable, inputAction, target, callback, triggerUp, triggerDown, triggerAlways, startActive, callbackState, customIconName)
188end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
31function Pickup.registerOverwrittenFunctions(vehicleType)
32 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getIsLowered", Pickup.getIsLowered)
33 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getDirtMultiplier", Pickup.getDirtMultiplier)
34 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getWearMultiplier", Pickup.getWearMultiplier)
35 SpecializationUtil.registerOverwrittenFunction(vehicleType, "registerLoweringActionEvent", Pickup.registerLoweringActionEvent)
36end

setPickupState

Description
Definition
setPickupState()
Code
104function Pickup:setPickupState(isPickupLowered, noEventSend)
105 local spec = self.spec_pickup
106
107 if isPickupLowered ~= spec.isLowered then
108 PickupSetStateEvent.sendEvent(self, isPickupLowered, noEventSend)
109
110 spec.isLowered = isPickupLowered
111
112 if spec.animationName ~= "" then
113 local animTime = nil
114 if self:getIsAnimationPlaying(spec.animationName) then
115 animTime = self:getAnimationTime(spec.animationName)
116 end
117 if isPickupLowered then
118 self:playAnimation(spec.animationName, spec.animationLowerSpeed, animTime, true)
119 else
120 self:playAnimation(spec.animationName, spec.animationLiftSpeed, animTime, true)
121 end
122 end
123
124 Pickup.updateActionEvents(self)
125 end
126end

updateActionEvents

Description
Definition
updateActionEvents()
Code
192function Pickup.updateActionEvents(self)
193 local spec = self.spec_pickup
194
195 if spec.animationName ~= "" then
196 local actionEvent = spec.actionEvents[InputAction.LOWER_IMPLEMENT]
197 if actionEvent ~= nil then
198 if spec.isLowered then
199 g_inputBinding:setActionEventText(actionEvent.actionEventId, string.format(g_i18n:getText("action_liftOBJECT"), g_i18n:getText("typeDesc_pickup")))
200 else
201 g_inputBinding:setActionEventText(actionEvent.actionEventId, string.format(g_i18n:getText("action_lowerOBJECT"), g_i18n:getText("typeDesc_pickup")))
202 end
203
204 g_inputBinding:setActionEventActive(actionEvent.actionEventId, self:getCanChangePickupState(not spec.isLowered))
205 end
206 end
207end