LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

WaterTrailer

Description
Specialization for water trailer allowing it to also be filled at any water plane in the world
Functions

getDrawFirstFillText

Description
Definition
getDrawFirstFillText()
Code
162function WaterTrailer:getDrawFirstFillText(superFunc)
163 local spec = self.spec_waterTrailer
164 if self.isClient then
165 if self:getIsActiveForInput() and self:getIsSelected() then
166 if self:getFillUnitFillLevel(spec.fillUnitIndex) <= 0 and self:getFillUnitCapacity(spec.fillUnitIndex) ~= 0 then
167 return true
168 end
169 end
170 end
171
172 return superFunc(self)
173end

onDelete

Description
Called on deleting
Definition
onDelete()
Code
67function WaterTrailer:onDelete()
68 local spec = self.spec_waterTrailer
69 if spec.activatableAdded then
70 g_currentMission:removeActivatableObject(spec.activatable)
71 spec.activatableAdded = false
72 end
73
74 if self.isClient then
75 g_soundManager:deleteSamples(spec.samples)
76 end
77end

onLoad

Description
Called on loading
Definition
onLoad(table savegame)
Arguments
tablesavegamesavegame
Code
45function WaterTrailer:onLoad(savegame)
46 local spec = self.spec_waterTrailer
47
48 local fillUnitIndex = getXMLInt(self.xmlFile, "vehicle.waterTrailer#fillUnitIndex")
49 if fillUnitIndex ~= nil then
50 spec.fillUnitIndex = fillUnitIndex
51 spec.fillLitersPerSecond = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.waterTrailer#fillLitersPerSecond"), 500)
52 spec.waterFillNode = Utils.getNoNil(I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, "vehicle.waterTrailer#fillNode"), self.i3dMappings), self.components[1].node)
53 end
54
55 spec.isFilling = false
56 spec.activatableAdded = false
57 spec.activatable = WaterTrailerActivatable:new(self)
58
59 if self.isClient then
60 spec.samples = {}
61 spec.samples.refill = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.waterTrailer.sounds", "refill", self.baseDirectory, self.components, 0, AudioGroup.VEHICLE, self.i3dMappings, self)
62 end
63end

onPreDetach

Description
Called if vehicle gets detached
Definition
onPreDetach(table attacherVehicle, table implement)
Arguments
tableattacherVehicleattacher vehicle
tableimplementimplement
Code
179function WaterTrailer:onPreDetach(attacherVehicle, implement)
180 local spec = self.spec_waterTrailer
181 if spec.activatableAdded then
182 g_currentMission:removeActivatableObject(spec.activatable)
183 spec.activatableAdded = false
184 end
185end

onReadStream

Description
Called on client side on join
Definition
onReadStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
83function WaterTrailer:onReadStream(streamId, connection)
84 local isFilling = streamReadBool(streamId)
85 self:setIsWaterTrailerFilling(isFilling, true)
86end

onUpdateTick

Description
Called on update tick
Definition
onUpdateTick(float dt, boolean isActiveForInput, boolean isSelected)
Arguments
floatdttime since last call in ms
booleanisActiveForInputtrue if vehicle is active for input
booleanisSelectedtrue if vehicle is selected
Code
102function WaterTrailer:onUpdateTick(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
103 local spec = self.spec_waterTrailer
104
105 local _,y,_ = getWorldTranslation(spec.waterFillNode)
106 local isNearWater = (y <= g_currentMission.waterY + 0.2)
107
108 if isNearWater then
109 if not spec.activatableAdded then
110 g_currentMission:addActivatableObject(spec.activatable)
111 spec.activatableAdded = true
112 end
113 else
114 if spec.activatableAdded then
115 g_currentMission:removeActivatableObject(spec.activatable)
116 spec.activatableAdded = false
117 end
118 end
119
120 if self.isServer then
121 if spec.isFilling then
122 -- stop filling if not near the water anymore
123 if not isNearWater then
124 self:setIsWaterTrailerFilling(false)
125 end
126 end
127
128 if spec.isFilling then
129 if self:getFillUnitAllowsFillType(spec.fillUnitIndex, FillType.WATER) then
130 local delta = self:addFillUnitFillLevel(self:getOwnerFarmId(), spec.fillUnitIndex, spec.fillLitersPerSecond*dt*0.001, FillType.WATER, ToolType.TRIGGER, nil)
131 if delta <= 0 then
132 self:setIsWaterTrailerFilling(false)
133 end
134 end
135 end
136 end
137end

onWriteStream

Description
Called on server side on join
Definition
onWriteStream(integer streamId, integer connection)
Arguments
integerstreamIdstreamId
integerconnectionconnection
Code
92function WaterTrailer:onWriteStream(streamId, connection)
93 local spec = self.spec_waterTrailer
94 streamWriteBool(streamId, spec.isFilling)
95end

prerequisitesPresent

Description
Checks if all prerequisite specializations are loaded
Definition
prerequisitesPresent(table specializations)
Arguments
tablespecializationsspecializations
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
16function WaterTrailer.prerequisitesPresent(specializations)
17 return SpecializationUtil.hasSpecialization(FillUnit, specializations)
18end

registerEventListeners

Description
Definition
registerEventListeners()
Code
34function WaterTrailer.registerEventListeners(vehicleType)
35 SpecializationUtil.registerEventListener(vehicleType, "onLoad", WaterTrailer)
36 SpecializationUtil.registerEventListener(vehicleType, "onDelete", WaterTrailer)
37 SpecializationUtil.registerEventListener(vehicleType, "onReadStream", WaterTrailer)
38 SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", WaterTrailer)
39 SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", WaterTrailer)
40end

registerFunctions

Description
Definition
registerFunctions()
Code
22function WaterTrailer.registerFunctions(vehicleType)
23 SpecializationUtil.registerFunction(vehicleType, "setIsWaterTrailerFilling", WaterTrailer.setIsWaterTrailerFilling)
24end

registerOverwrittenFunctions

Description
Definition
registerOverwrittenFunctions()
Code
28function WaterTrailer.registerOverwrittenFunctions(vehicleType)
29 SpecializationUtil.registerOverwrittenFunction(vehicleType, "getDrawFirstFillText", WaterTrailer.getDrawFirstFillText)
30end

setIsWaterTrailerFilling

Description
Set is water trailer filling state
Definition
setIsWaterTrailerFilling(boolean isFilling, boolean noEventSend)
Arguments
booleanisFillingnew is filling state
booleannoEventSendno event send
Code
143function WaterTrailer:setIsWaterTrailerFilling(isFilling, noEventSend)
144 local spec = self.spec_waterTrailer
145 if isFilling ~= spec.isFilling then
146 WaterTrailerSetIsFillingEvent.sendEvent(self, isFilling, noEventSend)
147
148 spec.isFilling = isFilling
149
150 if self.isClient then
151 if isFilling then
152 g_soundManager:playSample(spec.samples.refill)
153 else
154 g_soundManager:stopSample(spec.samples.refill)
155 end
156 end
157 end
158end