Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- 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
Farmland
DescriptionThis class wraps all farmland dataXML Configuration Parameters
farmland#name | string Name of the farmland |
farmland#areaInHa | float [optional, default=2.5] Area of farmland in hectares |
farmland#price | float [optional, default=<calculated by area>] Fixed price of farmland |
farmland#priceFactor | float [optional, default=1.0] Price modification factor used in price calculations |
farmland#npcIndex | int [optional, default=<random NPC>] Fixed NPC assignment by index |
farmland#defaultFarmProperty | bool [optional, default=false] If true, this farmland is owned by the player in a new game (on easy difficulty) |
Functions
delete
DescriptionDelete field definition objectDefinition
delete()Code
78 | function Farmland:delete() |
79 | end |
load
DescriptionLoad farmland data from xmlDefinition
load(integer xmlFile, string key)Arguments
integer | xmlFile | handle of xml file |
string | key | current xml element key |
boolean | true | if loading was successful else false |
39 | function Farmland:load(xmlFile, key) |
40 | self.id = getXMLInt(xmlFile, key.."#id") |
41 | |
42 | if self.id == nil or self.id == 0 then |
43 | print("Error: Invalid farmland id '"..tostring(self.id).."'!") |
44 | return false |
45 | end |
46 | |
47 | self.name = Utils.getNoNil(getXMLString(xmlFile, key.."#name"), "") |
48 | self.areaInHa = Utils.getNoNil(getXMLFloat(xmlFile, key.."#areaInHa"), 2.5) |
49 | |
50 | self.fixedPrice = getXMLFloat(xmlFile, key.."#price") |
51 | if self.fixedPrice == nil then |
52 | self.priceFactor = Utils.getNoNil(getXMLFloat(xmlFile, key.."#priceScale"), 1) |
53 | end |
54 | self.price = self.fixedPrice or 1 |
55 | |
56 | self:updatePrice() |
57 | |
58 | local npc = g_npcManager:getNPCByIndex(getXMLInt(xmlFile, key.."#npcIndex")) |
59 | self.npcIndex = g_npcManager:getRandomIndex() |
60 | if npc ~= nil then |
61 | self.npcIndex = npc.index |
62 | end |
63 | |
64 | -- Names are used with custom NPC sets |
65 | local npc = g_npcManager:getNPCByName(getXMLString(xmlFile, key.."#npcName")) |
66 | if npc ~= nil then |
67 | self.npcIndex = npc.index |
68 | end |
69 | |
70 | self.isOwned = false |
71 | self.defaultFarmProperty = Utils.getNoNil(getXMLBool(xmlFile, key.."#defaultFarmProperty"), false) |
72 | |
73 | return true |
74 | end |
new
DescriptionCreate field definition objectDefinition
new()Return Values
table | instance | Instance of object |
24 | function Farmland:new(customMt) |
25 | local self = setmetatable({}, customMt or Farmland_mt) |
26 | |
27 | self.isOwned = false |
28 | self.xWorldPos = 0 |
29 | self.zWorldPos = 0 |
30 | |
31 | return self |
32 | end |
setArea
DescriptionSet farmland areaDefinition
setArea(float areaInHa)Arguments
float | areaInHa | farmland size in ha |
92 | function Farmland:setArea(areaInHa) |
93 | self.areaInHa = areaInHa |
94 | if self.fixedPrice == nil then |
95 | self:updatePrice() |
96 | end |
97 | end |
setFarmlandIndicatorPosition
DescriptionSet farmland area indicator world positionDefinition
setFarmlandIndicatorPosition(float xWorldPos, float zWorldPos)Arguments
float | xWorldPos | farmland indicator x world position |
float | zWorldPos | farmland size in ha |
85 | function Farmland:setFarmlandIndicatorPosition(xWorldPos, zWorldPos) |
86 | self.xWorldPos, self.zWorldPos = xWorldPos, zWorldPos |
87 | end |