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
- 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
FarmlandStatistic
FunctionsgetValue
DescriptionDefinitiongetValue()Code
78 | function FarmlandStatistic:getValue(total, name) |
79 | local counter = self.periodCounter |
80 | if total then |
81 | counter = self.totalCounter |
82 | end |
83 | |
84 | if counter[name] ~= nil then |
85 | return counter[name] |
86 | end |
87 | |
88 | return 0 |
89 | end |
loadFromItemsXML
DescriptionDefinitionloadFromItemsXML()Code
30 | function FarmlandStatistic:loadFromItemsXML(xmlFile, key) |
31 | if xmlFile:getInt(key .. "#farmlandId") == self.farmlandId then |
32 | self.periodCounter:loadFromItemsXML(xmlFile, key .. ".periodCounter") |
33 | self.totalCounter:loadFromItemsXML(xmlFile, key .. ".totalCounter") |
34 | else |
35 | Logging.warning("Failed to load FarmlandStatistic from items xml (%s)", key) |
36 | end |
37 | end |
new
DescriptionDefinitionnew()Code
16 | function FarmlandStatistic.new(farmlandId, customMt) |
17 | local self = setmetatable({}, customMt or FarmlandStatistic_mt) |
18 | |
19 | self.farmlandId = farmlandId |
20 | self.hasChanged = false |
21 | |
22 | self.periodCounter = FarmlandStatisticCounter.new() |
23 | self.totalCounter = FarmlandStatisticCounter.new() |
24 | |
25 | return self |
26 | end |
onReadStream
DescriptionCalled on client side on joinDefinition
onReadStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
51 | function FarmlandStatistic:onReadStream(streamId, connection) |
52 | self.periodCounter:onReadStream(streamId, connection) |
53 | self.totalCounter:onReadStream(streamId, connection) |
54 | end |
onWriteStream
DescriptionCalled on server side on joinDefinition
onWriteStream(integer streamId, integer connection)Arguments
integer | streamId | streamId |
integer | connection | connection |
61 | function FarmlandStatistic:onWriteStream(streamId, connection) |
62 | self.periodCounter:onWriteStream(streamId, connection) |
63 | self.totalCounter:onWriteStream(streamId, connection) |
64 | end |
reset
DescriptionDefinitionreset()Code
68 | function FarmlandStatistic:reset(clearTotal) |
69 | self.periodCounter:reset() |
70 | |
71 | if clearTotal then |
72 | self.totalCounter:reset() |
73 | end |
74 | end |
saveToXMLFile
DescriptionDefinitionsaveToXMLFile()Code
41 | function FarmlandStatistic:saveToXMLFile(xmlFile, key, usedModNames) |
42 | xmlFile:setInt(key .. "#farmlandId", self.farmlandId) |
43 | self.periodCounter:saveToXMLFile(xmlFile, key .. ".periodCounter", usedModNames) |
44 | self.totalCounter:saveToXMLFile(xmlFile, key .. ".totalCounter", usedModNames) |
45 | end |
updateStatistic
DescriptionDefinitionupdateStatistic()Code
93 | function FarmlandStatistic:updateStatistic(name, value) |
94 | if self.periodCounter[name] ~= nil then |
95 | self.periodCounter[name] = self.periodCounter[name] + value |
96 | end |
97 | |
98 | if self.totalCounter[name] ~= nil then |
99 | self.totalCounter[name] = self.totalCounter[name] + value |
100 | end |
101 | |
102 | self.hasChanged = true |
103 | end |