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
- AnimatedMapObject
- AnimatedObject
- Bale
- Basketball
- BgaSellStation
- BunkerSilo
- BuyingStation
- DigitalDisplay
- DogBall
- HelpIcons
- InlineBale
- InlineBaleSingle
- LoadingStation
- MountableObject
- NightIllumination
- Nightlight2
- NightlightFlicker
- PackedBale
- PhysicsObject
- ProductionPoint
- Rotator
- SellingStation
- SimParticleSystem
- Storage
- SunAdmirer
- TourIconsMobile
- UnloadingStation
- VehicleSellingPoint
- WildlifeSpawner
- 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
PackedBale
DescriptionClass for packed balesParent
BaleFunctions
delete
DescriptionDeleting bale objectDefinition
delete()Code
40 | function PackedBale:delete() |
41 | g_currentMission.activatableObjectsSystem:removeActivatable(self.packedBaleActivatable) |
42 | |
43 | PackedBale:superClass().delete(self) |
44 | end |
getCanInteract
DescriptionDefinitiongetCanInteract()Code
107 | function PackedBale:getCanInteract() |
108 | local x1, y1, z1 = self:getInteractionPosition() |
109 | if x1 ~= nil then |
110 | local x2, y2, z2 = getWorldTranslation(self.nodeId) |
111 | local distance = MathUtil.vector3Length(x1-x2, y1-y2, z1-z2) |
112 | if distance < self.maxUnpackDistance then |
113 | return true |
114 | end |
115 | end |
116 | |
117 | return false |
118 | end |
getInteractionPosition
DescriptionDefinitiongetInteractionPosition()Code
122 | function PackedBale:getInteractionPosition() |
123 | if not g_currentMission.controlPlayer then |
124 | return |
125 | end |
126 | |
127 | if not g_currentMission.accessHandler:canPlayerAccess(self) then |
128 | return |
129 | end |
130 | |
131 | return getWorldTranslation(g_currentMission.player.rootNode) |
132 | end |
loadBaleAttributesFromXML
DescriptionLoads bale attributes from xml fileDefinition
loadBaleAttributesFromXML(table xmlFile)Arguments
table | xmlFile | xml file object |
49 | function PackedBale:loadBaleAttributesFromXML(xmlFile) |
50 | if not PackedBale:superClass().loadBaleAttributesFromXML(self, xmlFile) then |
51 | return false |
52 | end |
53 | |
54 | self.singleBaleFilename = xmlFile:getValue("bale.packedBale#singleBale") |
55 | self.singleBaleFilename = Utils.getFilename(self.singleBaleFilename, self.baseDirectory) |
56 | if self.singleBaleFilename == nil or not fileExists(self.singleBaleFilename) then |
57 | Logging.xmlError(xmlFile, "Could not find single bale reference for bale (%s)", self.singleBaleFilename) |
58 | return false |
59 | end |
60 | |
61 | xmlFile:iterate("bale.packedBale.singleBale", function(_, key) |
62 | local node = xmlFile:getValue(key .. "#node", nil, self.nodeId) |
63 | if node ~= nil then |
64 | table.insert(self.singleBaleNodes, node) |
65 | end |
66 | end) |
67 | |
68 | g_currentMission.activatableObjectsSystem:addActivatable(self.packedBaleActivatable) |
69 | |
70 | return true |
71 | end |
new
DescriptionCreating bale objectDefinition
new(boolean isServer, boolean isClient, table customMt)Arguments
boolean | isServer | is server |
boolean | isClient | is client |
table | customMt | customMt |
table | instance | Instance of object |
26 | function PackedBale.new(isServer, isClient, customMt) |
27 | local self = Bale.new(isServer, isClient, customMt or PackedBale_mt) |
28 | registerObjectClassName(self, "PackedBale") |
29 | |
30 | self.singleBaleNodes = {} |
31 | self.packedBaleActivatable = PackedBaleActivatable.new(self) |
32 | |
33 | self.maxUnpackDistance = PackedBale.MAX_UNPACK_DISTANCE |
34 | |
35 | return self |
36 | end |
unpack
DescriptionSet wrapping state of baleDefinition
unpack(boolean wrappingState)Arguments
boolean | wrappingState | new wrapping state |
77 | function PackedBale:unpack(noEventSend) |
78 | g_currentMission.activatableObjectsSystem:removeActivatable(self.packedBaleActivatable) |
79 | |
80 | if self.isServer then |
81 | for i=1, #self.singleBaleNodes do |
82 | local singleBaleNode = self.singleBaleNodes[i] |
83 | |
84 | if self.fillLevel > 1 then |
85 | local baleObject = Bale.new(self.isServer, self.isClient) |
86 | local x, y, z = getWorldTranslation(singleBaleNode) |
87 | local rx, ry, rz = getWorldRotation(singleBaleNode) |
88 | if baleObject:loadFromConfigXML(self.singleBaleFilename, x, y, z, rx, ry, rz) then |
89 | baleObject:setFillType(self.fillType) |
90 | baleObject:setFillLevel(math.min(self.fillLevel, baleObject:getCapacity())) |
91 | baleObject:setOwnerFarmId(self.ownerFarmId, true) |
92 | baleObject:register() |
93 | |
94 | self.fillLevel = self.fillLevel - baleObject:getFillLevel() |
95 | end |
96 | end |
97 | end |
98 | |
99 | self:delete() |
100 | else |
101 | g_client:getServerConnection():sendEvent(BaleUnpackEvent.new(self)) |
102 | end |
103 | end |