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
BuyableBale
DescriptionClass for a root vehicle that loads bales and is removed afterwardsFunctions
- initSpecialization
- loadBaleAtPosition
- onDelete
- onLoad
- onLoadFinished
- onUpdate
- prerequisitesPresent
- registerEventListeners
- registerFunctions
initSpecialization
DescriptionDefinitioninitSpecialization()Code
15 | function BuyableBale.initSpecialization() |
16 | g_configurationManager:addConfigurationType("buyableBaleAmount", g_i18n:getText("configuration_buyableBaleAmount"), nil, nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION) |
17 | end |
loadBaleAtPosition
DescriptionDefinitionloadBaleAtPosition()Code
107 | function BuyableBale:loadBaleAtPosition(position) |
108 | local spec = self.spec_buyableBale |
109 | |
110 | if self.isServer or self.propertyState == Vehicle.PROPERTY_STATE_SHOP_CONFIG then |
111 | local x, y, z = localToWorld(self.components[1].node, unpack(position.position)) |
112 | local rx, ry, rz = localRotationToWorld(self.components[1].node, unpack(position.rotation)) |
113 | |
114 | local baleObject = Bale:new(self.isServer, self.isClient) |
115 | baleObject:load(spec.baleFilename, x,y,z, rx,ry,rz) |
116 | baleObject:setOwnerFarmId(self:getActiveFarm(), true) |
117 | if self.propertyState ~= Vehicle.PROPERTY_STATE_SHOP_CONFIG then |
118 | baleObject:register() |
119 | end |
120 | baleObject:setCanBeSold(false) |
121 | |
122 | if spec.isWrapped then |
123 | baleObject:setWrappingState(1) |
124 | |
125 | if self.configurations["baseColor"] ~= nil then |
126 | local color = ConfigurationUtil.getColorByConfigId(self, "baseColor", self.configurations["baseColor"]) |
127 | baleObject:setColor(unpack(color)) |
128 | end |
129 | end |
130 | |
131 | setPairCollision(self.components[1].node, baleObject.nodeId, false) |
132 | |
133 | table.insert(spec.loadedBales, baleObject) |
134 | end |
135 | end |
onDelete
DescriptionDefinitiononDelete()Code
139 | function BuyableBale:onDelete() |
140 | if self.propertyState == Vehicle.PROPERTY_STATE_SHOP_CONFIG then |
141 | local spec = self.spec_buyableBale |
142 | for _, bale in ipairs(spec.loadedBales) do |
143 | bale:delete() |
144 | end |
145 | end |
146 | end |
onLoad
DescriptionCalled on loadingDefinition
onLoad(table savegame)Arguments
table | savegame | savegame |
43 | function BuyableBale:onLoad(savegame) |
44 | local spec = self.spec_buyableBale |
45 | |
46 | spec.loadedBales = {} |
47 | |
48 | spec.baleFilename = getXMLString(self.xmlFile, "vehicle.buyableBale#filename") |
49 | spec.isWrapped = Utils.getNoNil(getXMLBool(self.xmlFile, "vehicle.buyableBale#isWrapped"), false) |
50 | |
51 | local positionOffset = {0, 0, 0} |
52 | local i = 0 |
53 | while true do |
54 | local baseKey = string.format("vehicle.buyableBale.offsets.offset(%d)", i) |
55 | if not hasXMLProperty(self.xmlFile, baseKey) then |
56 | break |
57 | end |
58 | |
59 | local offset = StringUtil.getVectorNFromString(getXMLString(self.xmlFile, baseKey.."#offset"), 3) |
60 | local amount = getXMLInt(self.xmlFile, baseKey.."#amount") |
61 | |
62 | if amount <= self.configurations["buyableBaleAmount"] then |
63 | positionOffset = offset |
64 | end |
65 | |
66 | i = i + 1 |
67 | end |
68 | |
69 | spec.positions = {} |
70 | i = 0 |
71 | while true do |
72 | local baseKey = string.format("vehicle.buyableBale.balePositions.balePosition(%d)", i) |
73 | if not hasXMLProperty(self.xmlFile, baseKey) then |
74 | break |
75 | end |
76 | |
77 | local position = StringUtil.getVectorNFromString(getXMLString(self.xmlFile, baseKey.."#position"), 3) |
78 | local rotation = StringUtil.getRadiansFromString(getXMLString(self.xmlFile, baseKey.."#rotation"), 3) |
79 | if position ~= nil and rotation ~= nil then |
80 | if positionOffset ~= nil then |
81 | for j=1, 3 do |
82 | position[j] = position[j] + positionOffset[j] |
83 | end |
84 | end |
85 | |
86 | table.insert(spec.positions, {position=position, rotation=rotation}) |
87 | end |
88 | |
89 | i = i + 1 |
90 | end |
91 | end |
onLoadFinished
DescriptionCalled after loadingDefinition
onLoadFinished(table savegame)Arguments
table | savegame | savegame |
96 | function BuyableBale:onLoadFinished(savegame) |
97 | local spec = self.spec_buyableBale |
98 | for j, position in ipairs(spec.positions) do |
99 | if j <= self.configurations["buyableBaleAmount"] then |
100 | self:loadBaleAtPosition(position) |
101 | end |
102 | end |
103 | end |
onUpdate
DescriptionDefinitiononUpdate()Code
150 | function BuyableBale:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
151 | if self.isServer and self.propertyState ~= Vehicle.PROPERTY_STATE_SHOP_CONFIG then |
152 | g_currentMission:removeVehicle(self) |
153 | end |
154 | end |
prerequisitesPresent
DescriptionDefinitionprerequisitesPresent()Code
21 | function BuyableBale.prerequisitesPresent(specializations) |
22 | return true |
23 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
33 | function BuyableBale.registerEventListeners(vehicleType) |
34 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", BuyableBale) |
35 | SpecializationUtil.registerEventListener(vehicleType, "onLoadFinished", BuyableBale) |
36 | SpecializationUtil.registerEventListener(vehicleType, "onDelete", BuyableBale) |
37 | SpecializationUtil.registerEventListener(vehicleType, "onUpdate", BuyableBale) |
38 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
27 | function BuyableBale.registerFunctions(vehicleType) |
28 | SpecializationUtil.registerFunction(vehicleType, "loadBaleAtPosition", BuyableBale.loadBaleAtPosition) |
29 | end |