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
ReceivingHopper
DescriptionSpecialization for receiving hoppers filling tipped filltypes into boxes (e.g. potatoes)Functions
- actionEventToggleBoxCreation
- collisionTestCallback
- createBox
- getCanBeSelected
- getCanSpawnNextBox
- handleDischargeRaycast
- onFillUnitFillLevelChanged
- onLoad
- onRegisterActionEvents
- onUpdateTick
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerOverwrittenFunctions
- saveToXMLFile
- setCreateBoxes
- updateActionEvents
actionEventToggleBoxCreation
DescriptionDefinitionactionEventToggleBoxCreation()Code
253 | function ReceivingHopper.actionEventToggleBoxCreation(self, actionName, inputValue, callbackState, isAnalog) |
254 | local spec = self.spec_receivingHopper |
255 | self:setCreateBoxes(not spec.createBoxes) |
256 | end |
collisionTestCallback
DescriptionDefinitioncollisionTestCallback()Code
172 | function ReceivingHopper:collisionTestCallback(transformId) |
173 | if g_currentMission.nodeToObject[transformId] ~= nil or g_currentMission.players[transformId] ~= nil or g_currentMission:getNodeObject(transformId) ~= nil then |
174 | if g_currentMission.nodeToObject[transformId] ~= self then |
175 | local spec = self.spec_receivingHopper |
176 | spec.foundObjectAtSpawnPlace = true |
177 | end |
178 | end |
179 | end |
createBox
DescriptionCreate boxDefinition
createBox()Code
183 | function ReceivingHopper:createBox() |
184 | local spec = self.spec_receivingHopper |
185 | if self.isServer then |
186 | if spec.createBoxes then |
187 | local fillType = self:getFillUnitFillType(spec.fillUnitIndex) |
188 | if spec.boxes[fillType] ~= nil then |
189 | local x, _, z = getWorldTranslation(spec.spawnPlace) |
190 | local dirX, _, dirZ = localDirectionToWorld(spec.spawnPlace, 0, 1, 0) |
191 | local yRot = MathUtil.getYRotationFromDirection(dirX, dirZ); |
192 | local xmlFilename = Utils.getFilename(spec.boxes[fillType], self.baseDirectory) |
193 | local vehicle = g_currentMission:loadVehicle(xmlFilename, x, nil, z, 0, yRot, true, 0, Vehicle.PROPERTY_STATE_OWNED, self:getOwnerFarmId(), nil, nil) |
194 | if vehicle ~= nil then |
195 | spec.lastBox = vehicle |
196 | end |
197 | end |
198 | end |
199 | end |
200 | end |
getCanBeSelected
DescriptionDefinitiongetCanBeSelected()Code
225 | function ReceivingHopper:getCanBeSelected(superFunc) |
226 | return true |
227 | end |
getCanSpawnNextBox
DescriptionDefinitiongetCanSpawnNextBox()Code
144 | function ReceivingHopper:getCanSpawnNextBox() |
145 | local spec = self.spec_receivingHopper |
146 | |
147 | local fillType = self:getFillUnitFillType(spec.fillUnitIndex) |
148 | if spec.boxes[fillType] ~= nil then |
149 | if spec.lastBox ~= nil then |
150 | if spec.lastBox:getFillUnitFreeCapacity(1) > 0 then |
151 | return false |
152 | end |
153 | end |
154 | |
155 | local xmlFilename = Utils.getFilename(spec.boxes[fillType], self.baseDirectory) |
156 | local sizeWidth, sizeLength, _, _ = StoreItemUtil.getSizeValues(xmlFilename, "vehicle", 0) |
157 | |
158 | local x,y,z = getWorldTranslation(spec.spawnPlace) |
159 | local rx,ry,rz = getWorldRotation(spec.spawnPlace) |
160 | |
161 | spec.foundObjectAtSpawnPlace = false |
162 | overlapBox(x, y, z, rx, ry, rz, sizeWidth*0.5, 2, sizeLength*0.5, "collisionTestCallback", self, 5468288) |
163 | |
164 | return not spec.foundObjectAtSpawnPlace |
165 | end |
166 | |
167 | return false |
168 | end |
handleDischargeRaycast
DescriptionDefinitionhandleDischargeRaycast()Code
204 | function ReceivingHopper:handleDischargeRaycast(superFunc, dischargeNode, hitObject, hitShape, hitDistance, hitFillUnitIndex, hitTerrain) |
205 | local stopDischarge = false |
206 | if hitObject ~= nil then |
207 | local fillType = self:getDischargeFillType(dischargeNode) |
208 | local allowFillType = hitObject:getFillUnitAllowsFillType(hitFillUnitIndex, fillType) |
209 | if allowFillType and hitObject:getFillUnitFreeCapacity(hitFillUnitIndex) > 0 then |
210 | self:setDischargeState(Dischargeable.DISCHARGE_STATE_OBJECT, true) |
211 | else |
212 | stopDischarge = true |
213 | end |
214 | else |
215 | stopDischarge = true |
216 | end |
217 | |
218 | if stopDischarge and self:getDischargeState() == Dischargeable.DISCHARGE_STATE_OBJECT then |
219 | self:setDischargeState(Dischargeable.DISCHARGE_STATE_OFF, true) |
220 | end |
221 | end |
onFillUnitFillLevelChanged
DescriptionDefinitiononFillUnitFillLevelChanged()Code
245 | function ReceivingHopper:onFillUnitFillLevelChanged(fillUnitIndex, fillLevelDelta, fillType, toolType, fillPositionData, appliedDelta) |
246 | if self:getFillUnitFillLevel(fillUnitIndex) > 0 then |
247 | self:raiseActive() |
248 | end |
249 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
51 | function ReceivingHopper:onLoad(savegame) |
52 | local spec = self.spec_receivingHopper |
53 | |
54 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.receivingHopper#unloadingDelay", "Dischargeable functionalities") -- FS17 to FS19 |
55 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.receivingHopper#unloadInfoIndex", "Dischargeable functionalities") -- FS17 to FS19 |
56 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.receivingHopper#dischargeInfoIndex", "Dischargeable functionalities") -- FS17 to FS19 |
57 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.receivingHopper.tipTrigger#index", "Dischargeable functionalities") -- FS17 to FS19 |
58 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.receivingHopper.boxTrigger#index", "Dischargeable functionalities") -- FS17 to FS19 |
59 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.receivingHopper.fillScrollerNodes.fillScrollerNode", "Dischargeable functionalities") -- FS17 to FS19 |
60 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.receivingHopper.fillEffect", "Dischargeable functionalities") -- FS17 to FS19 |
61 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.receivingHopper.fillEffect", "Dischargeable functionalities") -- FS17 to FS19 |
62 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.receivingHopper.boxTrigger#litersPerMinute", "Dischargeable functionalities") -- FS17 to FS19 |
63 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.receivingHopper.raycastNode#index", "Dischargeable functionalities") -- FS17 to FS19 |
64 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.receivingHopper.raycastNode#raycastLength", "Dischargeable functionalities") -- FS17 to FS19 |
65 | |
66 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.receivingHopper.boxTrigger#boxSpawnPlaceIndex", "vehicle.receivingHopper.boxes#spawnPlaceNode") -- FS17 to FS19 |
67 | XMLUtil.checkDeprecatedXMLElements(self.xmlFile, self.configFileName, "vehicle.receivingHopper.boxTrigger.box(0)", "vehicle.receivingHopper.boxes.box(0)") -- FS17 to FS19 |
68 | |
69 | spec.fillUnitIndex = Utils.getNoNil(getXMLInt(self.xmlFile, "vehicle.receivingHopper#fillUnitIndex"), 1) |
70 | spec.spawnPlace = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.receivingHopper.boxes#spawnPlaceNode"), self.i3dMappings) |
71 | |
72 | spec.boxes = {} |
73 | local i = 0 |
74 | while true do |
75 | local baseName = string.format("vehicle.receivingHopper.boxes.box(%d)", i) |
76 | if not hasXMLProperty(self.xmlFile, baseName) then |
77 | break |
78 | end |
79 | |
80 | local fillTypeStr = getXMLString(self.xmlFile, baseName.."#fillType") |
81 | local filename = getXMLString(self.xmlFile, baseName.."#filename") |
82 | local fillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(fillTypeStr) |
83 | if fillTypeIndex ~= nil then |
84 | spec.boxes[fillTypeIndex] = filename |
85 | else |
86 | g_logManager:xmlWarning(self.configFileName, "Invalid fillType '%s'", fillTypeStr) |
87 | end |
88 | |
89 | i = i + 1 |
90 | end |
91 | |
92 | spec.createBoxes = false |
93 | spec.lastBox = nil |
94 | |
95 | if savegame ~= nil then |
96 | spec.createBoxes = Utils.getNoNil(getXMLBool(savegame.xmlFile, savegame.key..".receivingHopper#createBoxes"), spec.createBoxes) |
97 | end |
98 | end |
onRegisterActionEvents
DescriptionDefinitiononRegisterActionEvents()Code
231 | function ReceivingHopper:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection) |
232 | if self.isClient then |
233 | local spec = self.spec_receivingHopper |
234 | self:clearActionEventsTable(spec.actionEvents) |
235 | if isActiveForInputIgnoreSelection then |
236 | local _, actionEventId = self:addActionEvent(spec.actionEvents, InputAction.IMPLEMENT_EXTRA, self, ReceivingHopper.actionEventToggleBoxCreation, false, true, false, true, nil) |
237 | g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_NORMAL) |
238 | ReceivingHopper.updateActionEvents(self) |
239 | end |
240 | end |
241 | 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 |
113 | function ReceivingHopper:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
114 | if self.isServer then |
115 | local spec = self.spec_receivingHopper |
116 | if spec.createBoxes then |
117 | if self:getDischargeState() == Dischargeable.DISCHARGE_STATE_OFF then |
118 | if self:getCanSpawnNextBox() then |
119 | self:createBox() |
120 | end |
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 |
19 | function ReceivingHopper.prerequisitesPresent(specializations) |
20 | return SpecializationUtil.hasSpecialization(FillUnit, specializations) and SpecializationUtil.hasSpecialization(Dischargeable, specializations) |
21 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
41 | function ReceivingHopper.registerEventListeners(vehicleType) |
42 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", ReceivingHopper) |
43 | SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", ReceivingHopper) |
44 | SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", ReceivingHopper) |
45 | SpecializationUtil.registerEventListener(vehicleType, "onFillUnitFillLevelChanged", ReceivingHopper) |
46 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
25 | function ReceivingHopper.registerFunctions(vehicleType) |
26 | SpecializationUtil.registerFunction(vehicleType, "setCreateBoxes", ReceivingHopper.setCreateBoxes) |
27 | SpecializationUtil.registerFunction(vehicleType, "getCanSpawnNextBox", ReceivingHopper.getCanSpawnNextBox) |
28 | SpecializationUtil.registerFunction(vehicleType, "collisionTestCallback", ReceivingHopper.collisionTestCallback) |
29 | SpecializationUtil.registerFunction(vehicleType, "createBox", ReceivingHopper.createBox) |
30 | end |
registerOverwrittenFunctions
DescriptionDefinitionregisterOverwrittenFunctions()Code
34 | function ReceivingHopper.registerOverwrittenFunctions(vehicleType) |
35 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "handleDischargeRaycast", ReceivingHopper.handleDischargeRaycast) |
36 | SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanBeSelected", ReceivingHopper.getCanBeSelected) |
37 | end |
saveToXMLFile
DescriptionDefinitionsaveToXMLFile()Code
102 | function ReceivingHopper:saveToXMLFile(xmlFile, key, usedModNames) |
103 | local spec = self.spec_receivingHopper |
104 | |
105 | setXMLBool(xmlFile, key.."#createBoxes", spec.createBoxes) |
106 | end |
setCreateBoxes
DescriptionToggle box creatingDefinition
setCreateBoxes(boolean state, boolean noEventSend)Arguments
boolean | state | new state |
boolean | noEventSend | no event send |
130 | function ReceivingHopper:setCreateBoxes(state, noEventSend) |
131 | local spec = self.spec_receivingHopper |
132 | if state ~= spec.createBoxes then |
133 | ReceivingHopperSetCreateBoxesEvent.sendEvent(self, state, noEventSend) |
134 | |
135 | spec.createBoxes = state |
136 | ReceivingHopper.updateActionEvents(self) |
137 | |
138 | spec.lastBox = nil |
139 | end |
140 | end |
updateActionEvents
DescriptionDefinitionupdateActionEvents()Code
260 | function ReceivingHopper.updateActionEvents(self) |
261 | local spec = self.spec_receivingHopper |
262 | local actionEvent = spec.actionEvents[InputAction.IMPLEMENT_EXTRA] |
263 | if actionEvent ~= nil then |
264 | if spec.createBoxes then |
265 | g_inputBinding:setActionEventText(actionEvent.actionEventId, g_i18n:getText("action_disablePalletSpawning")) |
266 | else |
267 | g_inputBinding:setActionEventText(actionEvent.actionEventId, g_i18n:getText("action_enablePalletSpawning")) |
268 | end |
269 | end |
270 | end |