LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

BuyableBale

Description
Class for a root vehicle that loads bales and is removed afterwards
Functions

initSpecialization

Description
Definition
initSpecialization()
Code
15function BuyableBale.initSpecialization()
16 g_configurationManager:addConfigurationType("buyableBaleAmount", g_i18n:getText("configuration_buyableBaleAmount"), nil, nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION)
17end

loadBaleAtPosition

Description
Definition
loadBaleAtPosition()
Code
107function 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
135end

onDelete

Description
Definition
onDelete()
Code
139function 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
146end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
43function 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
91end

onLoadFinished

Description
Called after loading
Definition
onLoadFinished(table savegame)
Arguments
tablesavegamesavegame
Code
96function 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
103end

onUpdate

Description
Definition
onUpdate()
Code
150function 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
154end

prerequisitesPresent

Description
Definition
prerequisitesPresent()
Code
21function BuyableBale.prerequisitesPresent(specializations)
22 return true
23end

registerEventListeners

Description
Definition
registerEventListeners()
Code
33function 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)
38end

registerFunctions

Description
Definition
registerFunctions()
Code
27function BuyableBale.registerFunctions(vehicleType)
28 SpecializationUtil.registerFunction(vehicleType, "loadBaleAtPosition", BuyableBale.loadBaleAtPosition)
29end