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
PlaceableWeighingStation
DescriptionSpecialization for placeablesFunctions
- onDelete
- onLoad
- onWeighingTriggerCallback
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerXMLPaths
- setWeightDisplay
- updateWeightDisplay
onDelete
DescriptionDefinitiononDelete()Code
112 | function PlaceableWeighingStation:onDelete() |
113 | local spec = self.spec_weighingStation |
114 | |
115 | if spec.trigger ~= nil then |
116 | removeTrigger(spec.trigger) |
117 | spec.trigger = nil |
118 | end |
119 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
61 | function PlaceableWeighingStation:onLoad(savegame) |
62 | local spec = self.spec_weighingStation |
63 | |
64 | local key = "placeable.weighingStation" |
65 | |
66 | spec.trigger = self.xmlFile:getValue(key .. "#triggerNode", nil, self.components, self.i3dMappings) |
67 | if spec.trigger == nil then |
68 | Logging.xmlError(self.xmlFile, "Missing vehicle triggerNode for weighing station") |
69 | return |
70 | end |
71 | |
72 | addTrigger(spec.trigger, "onWeighingTriggerCallback", self) |
73 | spec.triggerVehicleNodes = {} |
74 | spec.vehicles = {} |
75 | |
76 | spec.displays = {} |
77 | self.xmlFile:iterate(key .. ".display", function(_, displayKey) |
78 | local displayNode = self.xmlFile:getValue(displayKey .. "#node", nil, self.components, self.i3dMappings) |
79 | if displayNode ~= nil then |
80 | local fontName = self.xmlFile:getValue(displayKey .. "#font", "DIGIT"):upper() |
81 | local fontMaterial = g_materialManager:getFontMaterial(fontName, self.customEnvironment) |
82 | |
83 | if fontMaterial ~= nil then |
84 | local display = {} |
85 | |
86 | local alignmentStr = self.xmlFile:getValue(displayKey .. "#alignment", "RIGHT") |
87 | local alignment = RenderText["ALIGN_" .. alignmentStr:upper()] or RenderText.ALIGN_RIGHT |
88 | |
89 | local size = self.xmlFile:getValue(displayKey .. "#size", 0.03) |
90 | local scaleX = self.xmlFile:getValue(displayKey .. "#scaleX", 1) |
91 | local scaleY = self.xmlFile:getValue(displayKey .. "#scaleY", 1) |
92 | local mask = self.xmlFile:getValue(displayKey .. "#mask", "00.0") |
93 | local emissiveScale = self.xmlFile:getValue(displayKey .. "#emissiveScale", 0.2) |
94 | local color = self.xmlFile:getValue(displayKey .. "#color", {0.9, 0.9, 0.9, 1}, true) |
95 | local hiddenColor = self.xmlFile:getValue(displayKey .. "#hiddenColor", nil, true) |
96 | |
97 | display.displayNode = displayNode |
98 | display.formatStr, display.formatPrecision = string.maskToFormat(mask) |
99 | display.fontMaterial = fontMaterial |
100 | display.characterLine = fontMaterial:createCharacterLine(display.displayNode, mask:len(), size, color, hiddenColor, emissiveScale, scaleX, scaleY, alignment) |
101 | |
102 | table.insert(spec.displays, display) |
103 | end |
104 | end |
105 | end) |
106 | |
107 | self:setWeightDisplay(0) |
108 | end |
onWeighingTriggerCallback
DescriptionTrigger callbackDefinition
onWeighingTriggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)Arguments
integer | triggerId | id of trigger |
integer | otherId | id of actor |
boolean | onEnter | on enter |
boolean | onLeave | on leave |
boolean | onStay | on stay |
167 | function PlaceableWeighingStation:onWeighingTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay) |
168 | if onEnter or onLeave then |
169 | local spec = self.spec_weighingStation |
170 | if onEnter then |
171 | spec.triggerVehicleNodes[otherId] = true |
172 | else |
173 | -- on leave |
174 | spec.triggerVehicleNodes[otherId] = nil |
175 | end |
176 | |
177 | self:updateWeightDisplay() |
178 | end |
179 | 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 |
18 | function PlaceableWeighingStation.prerequisitesPresent(specializations) |
19 | return true |
20 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
32 | function PlaceableWeighingStation.registerEventListeners(placeableType) |
33 | SpecializationUtil.registerEventListener(placeableType, "onLoad", PlaceableWeighingStation) |
34 | SpecializationUtil.registerEventListener(placeableType, "onDelete", PlaceableWeighingStation) |
35 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
24 | function PlaceableWeighingStation.registerFunctions(placeableType) |
25 | SpecializationUtil.registerFunction(placeableType, "onWeighingTriggerCallback", PlaceableWeighingStation.onWeighingTriggerCallback) |
26 | SpecializationUtil.registerFunction(placeableType, "updateWeightDisplay", PlaceableWeighingStation.updateWeightDisplay) |
27 | SpecializationUtil.registerFunction(placeableType, "setWeightDisplay", PlaceableWeighingStation.setWeightDisplay) |
28 | end |
registerXMLPaths
DescriptionDefinitionregisterXMLPaths()Code
39 | function PlaceableWeighingStation.registerXMLPaths(schema, basePath) |
40 | schema:setXMLSpecializationType("WeighingStation") |
41 | |
42 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".weighingStation#triggerNode", "Vehicle trigger") |
43 | |
44 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".weighingStation.display(?)#node", "Display start node") |
45 | schema:register(XMLValueType.STRING, basePath .. ".weighingStation.display(?)#font", "Display font name") |
46 | schema:register(XMLValueType.STRING, basePath .. ".weighingStation.display(?)#alignment", "Display text alignment") |
47 | schema:register(XMLValueType.FLOAT, basePath .. ".weighingStation.display(?)#size", "Display text size") |
48 | schema:register(XMLValueType.FLOAT, basePath .. ".weighingStation.display(?)#scaleX", "Display text x scale") |
49 | schema:register(XMLValueType.FLOAT, basePath .. ".weighingStation.display(?)#scaleY", "Display text y scale") |
50 | schema:register(XMLValueType.STRING, basePath .. ".weighingStation.display(?)#mask", "Display text mask") |
51 | schema:register(XMLValueType.FLOAT, basePath .. ".weighingStation.display(?)#emissiveScale", "Display emissive scale") |
52 | schema:register(XMLValueType.COLOR, basePath .. ".weighingStation.display(?)#color", "Display text color") |
53 | schema:register(XMLValueType.COLOR, basePath .. ".weighingStation.display(?)#hiddenColor", "Display text hidden color") |
54 | |
55 | schema:setXMLSpecializationType() |
56 | end |
setWeightDisplay
DescriptionDefinitionsetWeightDisplay()Code
150 | function PlaceableWeighingStation:setWeightDisplay(mass) |
151 | local spec = self.spec_weighingStation |
152 | for _, display in ipairs(spec.displays) do |
153 | local int, floatPart = math.modf(mass) |
154 | |
155 | local value = string.format(display.formatStr, int, math.abs(math.floor(floatPart * (10 ^ display.formatPrecision)))) |
156 | display.fontMaterial:updateCharacterLine(display.characterLine, value) |
157 | end |
158 | end |
updateWeightDisplay
DescriptionDefinitionupdateWeightDisplay()Code
123 | function PlaceableWeighingStation:updateWeightDisplay() |
124 | local spec = self.spec_weighingStation |
125 | |
126 | -- resolve nodes to vehicles, add to table to eliminate duplicates |
127 | for node, _ in pairs(spec.triggerVehicleNodes) do |
128 | if entityExists(node) then |
129 | local vehicle = g_currentMission:getNodeObject(node) |
130 | if vehicle ~= nil and vehicle.getTotalMass ~= nil then |
131 | spec.vehicles[vehicle] = true |
132 | end |
133 | else |
134 | -- vehicle does not exist anymore |
135 | spec.triggerVehicleNodes[node] = nil |
136 | end |
137 | end |
138 | |
139 | local mass = 0 |
140 | for vehicle in pairs(spec.vehicles) do |
141 | mass = mass + vehicle:getTotalMass(true) |
142 | end |
143 | table.clear(spec.vehicles) |
144 | |
145 | self:setWeightDisplay(mass*1000) |
146 | end |