Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- AIConveyorBelt
- AIDrivable
- AIFieldWorker
- AIImplement
- AIJobVehicle
- AIVehicle
- AIVehicleObstacle
- AnimatedVehicle
- ArticulatedAxis
- Attachable
- AttacherJointControl
- AttacherJoints
- AutoLoader
- BaleGrab
- BaleLoader
- Baler
- BaleWrapper
- BaseMaterial
- BigBag
- BunkerSiloCompacter
- BunkerSiloInteractor
- CCTDrivable
- Combine
- ConnectionHoses
- ConveyorBelt
- Cover
- CrabSteering
- Crawlers
- CropSensor
- Cultivator
- Cutter
- Cylindered
- CylinderedFoldable
- Dashboard
- Dischargeable
- Drivable
- DynamicallyLoadedParts
- DynamicMountAttacher
- Enterable
- ExtendedAIVehicle
- ExtendedCombine
- ExtendedMotorized
- ExtendedMower
- ExtendedSowingMachine
- ExtendedSprayer
- ExtendedWearable
- FertilizingCultivator
- FertilizingSowingMachine
- FillTriggerVehicle
- FillUnit
- FillVolume
- Foldable
- FoliageBending
- ForageWagon
- FrontloaderAttacher
- FruitPreparer
- GroundAdjustedNodes
- GroundReference
- HeadlandAnimation
- Honk
- HookLiftContainer
- HookLiftTrailer
- IKChains
- InlineWrapper
- JigglingParts
- Leveler
- LicensePlates
- Lights
- LivestockTrailer
- Locomotive
- LogGrab
- ManureBarrel
- ManureSensor
- MixerWagon
- Motorized
- Mountable
- Mower
- Mulcher
- MultipleItemPurchase
- Pallet
- Pickup
- Pipe
- PlaceableAI
- PlaceableAnimatedObjects
- PlaceableBeehive
- PlaceableBeehivePalletSpa...
- PlaceableBunkerSilo
- PlaceableBuyingStation
- PlaceableCartridgePlayer
- PlaceableChargingStation
- PlaceableClearAreas
- PlaceableColorable
- PlaceableDeletedNodes
- PlaceableDoghouse
- PlaceableDynamicallyLoade...
- PlaceableFarmhouse
- PlaceableFence
- PlaceableFoliageAreas
- PlaceableGreenhouse
- PlaceableHighPressureWash...
- PlaceableHotspots
- PlaceableHusbandry
- PlaceableHusbandryAnimals
- PlaceableHusbandryFeeding...
- PlaceableHusbandryFence
- PlaceableHusbandryFood
- PlaceableHusbandryLiquidM...
- PlaceableHusbandryMilk
- PlaceableHusbandryPallets
- PlaceableHusbandryStraw
- PlaceableHusbandryWater
- PlaceableIncomePerHour
- PlaceableIndoorAreas
- PlaceableInfoTrigger
- PlaceableLeveling
- PlaceableLights
- PlaceableManureHeap
- PlaceablePlacement
- PlaceableProductionPoint
- PlaceableSellingStation
- PlaceableSilo
- PlaceableSiloExtension
- PlaceableSolarPanels
- PlaceableTipOcclusionArea...
- PlaceableTrainSystem
- PlaceableTriggerMarkers
- PlaceableVine
- PlaceableWardrobe
- PlaceableWeatherStation
- PlaceableWeighingStation
- PlaceableWindTurbine
- PlaceableWorkshop
- Plow
- PlowPacker
- PowerConsumer
- PowerTakeOffs
- PrecisionFarmingStatistic
- PushHandTool
- RandomlyMovingParts
- ReceivingHopper
- ReverseDriving
- Rideable
- RidgeMarker
- Roller
- Ropes
- RTKStation
- SaltSpreader
- SemiTrailerFront
- Shovel
- SlopeCompensation
- SmartAttach
- SoilSampler
- SowingMachine
- SpeedRotatingParts
- SplineVehicle
- Sprayer
- StonePicker
- StrawBlower
- StumpCutter
- SupportVehicle
- Suspensions
- Tedder
- TensionBeltObject
- TensionBelts
- TestAreas
- TipOccluder
- Trailer
- TreePlanter
- TreeSaplingPallet
- TreeSaw
- TurnOnVehicle
- VariableWorkWidth
- VehicleSettings
- VineCutter
- VineDetector
- VinePrepruner
- Washable
- WaterTrailer
- Wearable
- Weeder
- WeedSpotSpray
- Wheels
- WindBending
- Windrower
- Wipers
- WoodCrusher
- WoodHarvester
- WorkArea
- WorkMode
- WorkParticles
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
ReceivingHopper
DescriptionSpecialization for receiving hoppers filling tipped filltypes into boxes (e.g. potatoes)Functions
- actionEventToggleBoxCreation
- collisionTestCallback
- createBox
- getCanBeSelected
- getCanSpawnNextBox
- handleDischargeRaycast
- initSpecialization
- onCreateBoxFinished
- onFillUnitFillLevelChanged
- onLoad
- onRegisterActionEvents
- onUpdateTick
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- saveToXMLFile
- setCreateBoxes
- updateActionEvents
actionEventToggleBoxCreation
DescriptionDefinitionactionEventToggleBoxCreation()Code
289 | function ReceivingHopper.actionEventToggleBoxCreation(self, actionName, inputValue, callbackState, isAnalog) |
290 | local spec = self.spec_receivingHopper |
291 | self:setCreateBoxes(not spec.createBoxes) |
292 | end |
collisionTestCallback
DescriptionDefinitioncollisionTestCallback()Code
197 | function ReceivingHopper:collisionTestCallback(transformId) |
198 | if g_currentMission.nodeToObject[transformId] ~= nil or g_currentMission.players[transformId] ~= nil then |
199 | if g_currentMission.nodeToObject[transformId] ~= self then |
200 | local spec = self.spec_receivingHopper |
201 | spec.foundObjectAtSpawnPlace = true |
202 | end |
203 | end |
204 | end |
createBox
DescriptionCreate boxDefinition
createBox()Code
208 | function ReceivingHopper:createBox() |
209 | local spec = self.spec_receivingHopper |
210 | if self.isServer then |
211 | if spec.createBoxes then |
212 | local fillType = self:getFillUnitFillType(spec.fillUnitIndex) |
213 | if spec.boxes[fillType] ~= nil then |
214 | local x, _, z = getWorldTranslation(spec.spawnPlace) |
215 | local dirX, _, dirZ = localDirectionToWorld(spec.spawnPlace, 0, 0, 1) |
216 | local yRot = MathUtil.getYRotationFromDirection(dirX, dirZ) |
217 | local xmlFilename = Utils.getFilename(spec.boxes[fillType], self.baseDirectory) |
218 | local location = {x=x, z=z, yRot=yRot} |
219 | |
220 | spec.creatingBox = true |
221 | VehicleLoadingUtil.loadVehicle(xmlFilename, location, true, 0, Vehicle.PROPERTY_STATE_OWNED, self:getOwnerFarmId(), nil, nil, self.onCreateBoxFinished, self) |
222 | end |
223 | end |
224 | end |
225 | end |
getCanBeSelected
DescriptionDefinitiongetCanBeSelected()Code
261 | function ReceivingHopper:getCanBeSelected(superFunc) |
262 | return true |
263 | end |
getCanSpawnNextBox
DescriptionDefinitiongetCanSpawnNextBox()Code
165 | function ReceivingHopper:getCanSpawnNextBox() |
166 | local spec = self.spec_receivingHopper |
167 | |
168 | if spec.creatingBox then |
169 | return false |
170 | end |
171 | |
172 | local fillType = self:getFillUnitFillType(spec.fillUnitIndex) |
173 | if spec.boxes[fillType] ~= nil then |
174 | if spec.lastBox ~= nil then |
175 | if spec.lastBox:getFillUnitFreeCapacity(1) > 0 then |
176 | return false |
177 | end |
178 | end |
179 | |
180 | local xmlFilename = Utils.getFilename(spec.boxes[fillType], self.baseDirectory) |
181 | local size = StoreItemUtil.getSizeValues(xmlFilename, "vehicle", 0) |
182 | |
183 | local x,y,z = getWorldTranslation(spec.spawnPlace) |
184 | local rx,ry,rz = getWorldRotation(spec.spawnPlace) |
185 | |
186 | spec.foundObjectAtSpawnPlace = false |
187 | overlapBox(x, y, z, rx, ry, rz, size.width*0.5, 2, size.length*0.5, "collisionTestCallback", self, 5468288) |
188 | |
189 | return not spec.foundObjectAtSpawnPlace |
190 | end |
191 | |
192 | return false |
193 | end |
handleDischargeRaycast
DescriptionDefinitionhandleDischargeRaycast()Code
240 | function ReceivingHopper:handleDischargeRaycast(superFunc, dischargeNode, hitObject, hitShape, hitDistance, hitFillUnitIndex, hitTerrain) |
241 | local stopDischarge = false |
242 | if hitObject ~= nil then |
243 | local fillType = self:getDischargeFillType(dischargeNode) |
244 | local allowFillType = hitObject:getFillUnitAllowsFillType(hitFillUnitIndex, fillType) |
245 | if allowFillType and hitObject:getFillUnitFreeCapacity(hitFillUnitIndex) > 0 then |
246 | self:setDischargeState(Dischargeable.DISCHARGE_STATE_OBJECT, true) |
247 | else |
248 | stopDischarge = true |
249 | end |
250 | else |
251 | stopDischarge = true |
252 | end |
253 | |
254 | if stopDischarge and self:getDischargeState() == Dischargeable.DISCHARGE_STATE_OBJECT then |
255 | self:setDischargeState(Dischargeable.DISCHARGE_STATE_OFF, true) |
256 | end |
257 | end |
initSpecialization
DescriptionDefinitioninitSpecialization()Code
25 | function ReceivingHopper.initSpecialization() |
26 | local schema = Vehicle.xmlSchema |
27 | schema:setXMLSpecializationType("ReceivingHopper") |
28 | |
29 | schema:register(XMLValueType.INT, "vehicle.receivingHopper#fillUnitIndex", "Fill unit index", 1) |
30 | schema:register(XMLValueType.NODE_INDEX, "vehicle.receivingHopper.boxes#spawnPlaceNode", "Spawn place node") |
31 | schema:register(XMLValueType.STRING, "vehicle.receivingHopper.boxes.box(?)#fillType", "Fill type name") |
32 | schema:register(XMLValueType.STRING, "vehicle.receivingHopper.boxes.box(?)#filename", "Box filename") |
33 | |
34 | schema:setXMLSpecializationType() |
35 | |
36 | local schemaSavegame = Vehicle.xmlSchemaSavegame |
37 | schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?).receivingHopper#createBoxes", "Create boxes") |
38 | end |
onCreateBoxFinished
DescriptionDefinitiononCreateBoxFinished()Code
229 | function ReceivingHopper:onCreateBoxFinished(vehicle, vehicleLoadState, arguments) |
230 | local spec = self.spec_receivingHopper |
231 | spec.creatingBox = false |
232 | |
233 | if vehicleLoadState == VehicleLoadingUtil.VEHICLE_LOAD_OK then |
234 | spec.lastBox = vehicle |
235 | end |
236 | end |
onFillUnitFillLevelChanged
DescriptionDefinitiononFillUnitFillLevelChanged()Code
281 | function ReceivingHopper:onFillUnitFillLevelChanged(fillUnitIndex, fillLevelDelta, fillType, toolType, fillPositionData, appliedDelta) |
282 | if self:getFillUnitFillLevel(fillUnitIndex) > 0 then |
283 | self:raiseActive() |
284 | end |
285 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
69 | function ReceivingHopper:onLoad(savegame) |
70 | local spec = self.spec_receivingHopper |
71 | |
72 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.receivingHopper#unloadingDelay", "Dischargeable functionalities") -- FS17 to FS19 |
73 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.receivingHopper#unloadInfoIndex", "Dischargeable functionalities") -- FS17 to FS19 |
74 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.receivingHopper#dischargeInfoIndex", "Dischargeable functionalities") -- FS17 to FS19 |
75 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.receivingHopper.tipTrigger#index", "Dischargeable functionalities") -- FS17 to FS19 |
76 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.receivingHopper.boxTrigger#index", "Dischargeable functionalities") -- FS17 to FS19 |
77 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.receivingHopper.fillScrollerNodes.fillScrollerNode", "Dischargeable functionalities") -- FS17 to FS19 |
78 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.receivingHopper.fillEffect", "Dischargeable functionalities") -- FS17 to FS19 |
79 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.receivingHopper.fillEffect", "Dischargeable functionalities") -- FS17 to FS19 |
80 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.receivingHopper.boxTrigger#litersPerMinute", "Dischargeable functionalities") -- FS17 to FS19 |
81 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.receivingHopper.raycastNode#index", "Dischargeable functionalities") -- FS17 to FS19 |
82 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.receivingHopper.raycastNode#raycastLength", "Dischargeable functionalities") -- FS17 to FS19 |
83 | |
84 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.receivingHopper.boxTrigger#boxSpawnPlaceIndex", "vehicle.receivingHopper.boxes#spawnPlaceNode") -- FS17 to FS19 |
85 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.receivingHopper.boxTrigger.box(0)", "vehicle.receivingHopper.boxes.box(0)") -- FS17 to FS19 |
86 | |
87 | spec.fillUnitIndex = self.xmlFile:getValue("vehicle.receivingHopper#fillUnitIndex", 1) |
88 | spec.spawnPlace = self.xmlFile:getValue("vehicle.receivingHopper.boxes#spawnPlaceNode", nil, self.components, self.i3dMappings) |
89 | |
90 | spec.boxes = {} |
91 | local i = 0 |
92 | while true do |
93 | local baseName = string.format("vehicle.receivingHopper.boxes.box(%d)", i) |
94 | if not self.xmlFile:hasProperty(baseName) then |
95 | break |
96 | end |
97 | |
98 | local fillTypeStr = self.xmlFile:getValue(baseName.."#fillType") |
99 | local filename = self.xmlFile:getValue(baseName.."#filename") |
100 | local fillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(fillTypeStr) |
101 | if fillTypeIndex ~= nil then |
102 | spec.boxes[fillTypeIndex] = filename |
103 | else |
104 | Logging.xmlWarning(self.xmlFile, "Invalid fillType '%s'", fillTypeStr) |
105 | end |
106 | |
107 | i = i + 1 |
108 | end |
109 | |
110 | spec.createBoxes = false |
111 | spec.lastBox = nil |
112 | spec.creatingBox = false |
113 | |
114 | if savegame ~= nil then |
115 | spec.createBoxes = savegame.xmlFile:getValue(savegame.key..".receivingHopper#createBoxes", spec.createBoxes) |
116 | end |
117 | |
118 | if not self.isServer then |
119 | SpecializationUtil.removeEventListener(self, "onUpdateTick", ReceivingHopper) |
120 | end |
121 | end |
onRegisterActionEvents
DescriptionDefinitiononRegisterActionEvents()Code
267 | function ReceivingHopper:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection) |
268 | if self.isClient then |
269 | local spec = self.spec_receivingHopper |
270 | self:clearActionEventsTable(spec.actionEvents) |
271 | if isActiveForInputIgnoreSelection then |
272 | local _, actionEventId = self:addActionEvent(spec.actionEvents, InputAction.IMPLEMENT_EXTRA, self, ReceivingHopper.actionEventToggleBoxCreation, false, true, false, true, nil) |
273 | g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_NORMAL) |
274 | ReceivingHopper.updateActionEvents(self) |
275 | end |
276 | end |
277 | 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 |
136 | function ReceivingHopper:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
137 | local spec = self.spec_receivingHopper |
138 | if spec.createBoxes then |
139 | if self:getDischargeState() == Dischargeable.DISCHARGE_STATE_OFF then |
140 | if self:getCanSpawnNextBox() then |
141 | self:createBox() |
142 | end |
143 | end |
144 | end |
145 | 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 |
19 | function ReceivingHopper.prerequisitesPresent(specializations) |
20 | return SpecializationUtil.hasSpecialization(FillUnit, specializations) and SpecializationUtil.hasSpecialization(Dischargeable, specializations) |
21 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
59 | function ReceivingHopper.registerEventListeners(vehicleType) |
60 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", ReceivingHopper) |
61 | SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", ReceivingHopper) |
62 | SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", ReceivingHopper) |
63 | SpecializationUtil.registerEventListener(vehicleType, "onFillUnitFillLevelChanged", ReceivingHopper) |
64 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
42 | function ReceivingHopper.registerFunctions(vehicleType) |
43 | SpecializationUtil.registerFunction(vehicleType, "setCreateBoxes", ReceivingHopper.setCreateBoxes) |
44 | SpecializationUtil.registerFunction(vehicleType, "getCanSpawnNextBox", ReceivingHopper.getCanSpawnNextBox) |
45 | SpecializationUtil.registerFunction(vehicleType, "collisionTestCallback", ReceivingHopper.collisionTestCallback) |
46 | SpecializationUtil.registerFunction(vehicleType, "createBox", ReceivingHopper.createBox) |
47 | SpecializationUtil.registerFunction(vehicleType, "onCreateBoxFinished", ReceivingHopper.onCreateBoxFinished) |
48 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
52 | function ReceivingHopper.registerOverwrittenFunctions(vehicleType) |
53 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "handleDischargeRaycast", ReceivingHopper.handleDischargeRaycast) |
54 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanBeSelected", ReceivingHopper.getCanBeSelected) |
55 | end |
saveToXMLFile
DescriptionDefinitionsaveToXMLFile()Code
125 | function ReceivingHopper:saveToXMLFile(xmlFile, key, usedModNames) |
126 | local spec = self.spec_receivingHopper |
127 | |
128 | xmlFile:setValue(key.."#createBoxes", spec.createBoxes) |
129 | end |
setCreateBoxes
DescriptionToggle box creatingDefinition
setCreateBoxes(boolean state, boolean noEventSend)Arguments
boolean | state | new state |
boolean | noEventSend | no event send |
151 | function ReceivingHopper:setCreateBoxes(state, noEventSend) |
152 | local spec = self.spec_receivingHopper |
153 | if state ~= spec.createBoxes then |
154 | ReceivingHopperSetCreateBoxesEvent.sendEvent(self, state, noEventSend) |
155 | |
156 | spec.createBoxes = state |
157 | ReceivingHopper.updateActionEvents(self) |
158 | |
159 | spec.lastBox = nil |
160 | end |
161 | end |
updateActionEvents
DescriptionDefinitionupdateActionEvents()Code
296 | function ReceivingHopper.updateActionEvents(self) |
297 | local spec = self.spec_receivingHopper |
298 | local actionEvent = spec.actionEvents[InputAction.IMPLEMENT_EXTRA] |
299 | if actionEvent ~= nil then |
300 | if spec.createBoxes then |
301 | g_inputBinding:setActionEventText(actionEvent.actionEventId, g_i18n:getText("action_disablePalletSpawning")) |
302 | else |
303 | g_inputBinding:setActionEventText(actionEvent.actionEventId, g_i18n:getText("action_enablePalletSpawning")) |
304 | end |
305 | end |
306 | end |