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
- getDataPlaneAssociatedTransformGroup
- getDensityAtWorldPos
- getDensityHeightAtWorldPos
- getDensityMapSize
- getDensityMapSyncerCellIndicesAtWorldPosition
- getDensityRegion
- getDensityRegionWorld
- getFoliageTransformGroupIdByFoliageName
- getTerrainAttributesAtWorldPos
- getTerrainDataPlaneByName
- getTerrainDetailByName
- getTerrainDetailName
- getTerrainDetailNumChannels
- getTerrainDetailTypeIndex
- getTerrainHeightAtWorldPos
- getTerrainNormalAtWorldPos
- getTerrainSize
- setDensityMapSyncerCellChangedCallback
- setEnableDensityMapSyncerCellChangedCallback
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
HandTool
DescriptionClass for handtoolsParent
ObjectFunctions
- delete
- getDailyUpkeep
- getNeedCustomWorkStyle
- getSellPrice
- handToolI3DLoaded
- init
- isBeingUsed
- load
- loadFromXMLFile
- new
- onActivate
- onDeactivate
- periodChanged
- postLoad
- registerActionEvents
- removeActionEvents
- saveToXMLFile
- setHandNode
- update
delete
DescriptionDeleting handtoolDefinition
delete()Code
233 | function HandTool:delete() |
234 | self:removeActionEvents() |
235 | |
236 | if g_currentMission ~= nil then |
237 | g_messageCenter:unsubscribe(MessageType.PERIOD_CHANGED, self) |
238 | end |
239 | if self.rootNode ~= nil and self.rootNode ~= 0 then |
240 | if self.originalHandNodeParent ~= nil and getParent(self.handNode) ~= self.originalHandNodeParent then |
241 | link(self.originalHandNodeParent, self.handNode) |
242 | end |
243 | |
244 | delete(self.rootNode) |
245 | end |
246 | |
247 | if self.sharedLoadRequestId ~= nil then |
248 | g_i3DManager:releaseSharedI3DFile(self.sharedLoadRequestId) |
249 | self.sharedLoadRequestId = nil |
250 | end |
251 | |
252 | HandTool:superClass().delete(self) |
253 | |
254 | self.isDeleted = true |
255 | end |
getDailyUpkeep
DescriptionGet daily up keepDefinition
getDailyUpkeep()Return Values
float | dailyUpkeep | daily up keep |
314 | function HandTool:getDailyUpkeep() |
315 | local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName) |
316 | local multiplier = 1 |
317 | |
318 | if storeItem.lifetime ~= nil and storeItem.lifetime ~= 0 then |
319 | local ageMultiplier = math.min(self.age / storeItem.lifetime, 1) |
320 | multiplier = EconomyManager.MAX_DAILYUPKEEP_MULTIPLIER * ageMultiplier |
321 | end |
322 | |
323 | return StoreItemUtil.getDailyUpkeep(storeItem, nil) * multiplier |
324 | end |
getNeedCustomWorkStyle
DescriptionDefinitiongetNeedCustomWorkStyle()Code
267 | function HandTool:getNeedCustomWorkStyle() |
268 | return true |
269 | end |
getSellPrice
DescriptionGet sell priceDefinition
getSellPrice()Return Values
float | sellPrice | sell price |
329 | function HandTool:getSellPrice() |
330 | local priceMultiplier = 0.5 |
331 | local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName) |
332 | local maxVehicleAge = storeItem.lifetime |
333 | |
334 | if maxVehicleAge ~= nil and maxVehicleAge ~= 0 then |
335 | priceMultiplier = priceMultiplier * math.exp(-3.5 * math.min(self.age/maxVehicleAge, 1)) |
336 | end |
337 | |
338 | return math.floor(self.price * math.max(priceMultiplier, 0.05)) |
339 | end |
handToolI3DLoaded
DescriptionDefinitionhandToolI3DLoaded()Code
132 | function HandTool:handToolI3DLoaded(i3dNode, failedReason, args) |
133 | if i3dNode ~= 0 then |
134 | |
135 | local xmlFile = args.xmlFile |
136 | local asyncCallbackFunction = args.asyncCallbackFunction |
137 | local asyncCallbackArguments = args.asyncCallbackArguments |
138 | |
139 | if not self.isDeleted then |
140 | self.rootNode = getChildAt(i3dNode, 0) |
141 | |
142 | -- fill components |
143 | local numChildren = getNumOfChildren(i3dNode) |
144 | for i=0, numChildren - 1 do |
145 | local component = {} |
146 | component.node = getChildAt(i3dNode, i) |
147 | |
148 | table.insert(self.components, component) |
149 | end |
150 | |
151 | unlink(self.rootNode) |
152 | |
153 | I3DUtil.loadI3DMapping(xmlFile, "handTool", self.components, self.i3dMappings) |
154 | |
155 | self:postLoad(xmlFile) |
156 | end |
157 | |
158 | xmlFile:delete() |
159 | delete(i3dNode) |
160 | |
161 | if asyncCallbackFunction ~= nil then |
162 | asyncCallbackFunction(self.player, self, asyncCallbackArguments) |
163 | end |
164 | end |
165 | end |
init
DescriptionInitialize hand tool and hand tool typesDefinition
init()Code
51 | function HandTool.init() |
52 | for _, classObject in pairs(HandTool.handToolTypes) do |
53 | if rawget(classObject, "init") then |
54 | classObject.init() |
55 | end |
56 | end |
57 | end |
isBeingUsed
DescriptionDefinitionisBeingUsed()Code
349 | function HandTool:isBeingUsed() |
350 | return false |
351 | end |
load
DescriptionLoad chainsaw from xml fileDefinition
load(string xmlFilename, table player)Arguments
string | xmlFilename | xml file name |
table | player | player |
boolean | success | success |
92 | function HandTool:load(xmlFilename, player, asyncCallbackFunction, asyncCallbackArguments) |
93 | self.configFileName = xmlFilename |
94 | |
95 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(xmlFilename) |
96 | |
97 | local xmlFile = XMLFile.load("TempXML", xmlFilename, HandTool.xmlSchema) |
98 | if xmlFile == nil then |
99 | return false |
100 | end |
101 | |
102 | local i3dFilename = xmlFile:getValue("handTool.filename") |
103 | if i3dFilename == nil then |
104 | xmlFile:delete() |
105 | return false |
106 | end |
107 | |
108 | self.i3dFilename = Utils.getFilename(i3dFilename, self.baseDirectory) |
109 | self.player = player |
110 | |
111 | g_i3DManager:pinSharedI3DFileInCache(self.i3dFilename) |
112 | |
113 | local arguments = { |
114 | xmlFile = xmlFile, |
115 | asyncCallbackFunction = asyncCallbackFunction, |
116 | asyncCallbackArguments = asyncCallbackArguments |
117 | } |
118 | |
119 | if asyncCallbackFunction ~= nil then |
120 | self.sharedLoadRequestId = g_i3DManager:loadSharedI3DFileAsync(self.i3dFilename, false, false, self.handToolI3DLoaded, self, arguments) |
121 | else |
122 | local i3dNode, sharedLoadRequestId, failedReason = g_i3DManager:loadSharedI3DFile(self.i3dFilename, false, false) |
123 | self.sharedLoadRequestId = sharedLoadRequestId |
124 | self:handToolI3DLoaded(i3dNode, failedReason, arguments) |
125 | end |
126 | |
127 | return true |
128 | end |
loadFromXMLFile
DescriptionDefinitionloadFromXMLFile()Code
301 | function HandTool:loadFromXMLFile(xmlFile, key, resetVehicles) |
302 | return true |
303 | end |
new
DescriptionCreating handtool objectDefinition
new(boolean isServer, boolean isClient, table customMt)Arguments
boolean | isServer | is server |
boolean | isClient | is client |
table | customMt | custom metatable |
table | instance | Instance of object |
65 | function HandTool.new(isServer, isClient, customMt) |
66 | local mt = customMt |
67 | if mt == nil then |
68 | mt = HandTool_mt |
69 | end |
70 | |
71 | local self = Object.new(isServer, isClient, mt) |
72 | self.static = true |
73 | self.player = nil |
74 | self.owner = nil |
75 | self.currentPlayerHandNode = nil |
76 | self.price = 0 |
77 | self.age = 0 |
78 | self.activatePressed = false |
79 | self.isDeleted = false |
80 | |
81 | self.components = {} |
82 | self.i3dMappings = {} |
83 | |
84 | return self |
85 | end |
onActivate
DescriptionOn activateDefinition
onActivate(boolean allowInput)Arguments
boolean | allowInput | allow input |
274 | function HandTool:onActivate(allowInput) |
275 | setVisibility(self.rootNode, true) |
276 | self.isActive = true |
277 | self:raiseActive() |
278 | |
279 | if self.player.isOwner then |
280 | self:registerActionEvents() |
281 | end |
282 | |
283 | if self:getNeedCustomWorkStyle() then |
284 | self.player:setCustomWorkStylePreset(self.customWorkStylePresetName) |
285 | end |
286 | end |
onDeactivate
DescriptionOn deactivateDefinition
onDeactivate(boolean allowInput)Arguments
boolean | allowInput | allow input |
291 | function HandTool:onDeactivate(allowInput) |
292 | setVisibility(self.rootNode, false) |
293 | self.isActive = false |
294 | self:removeActionEvents() |
295 | |
296 | self.player:setCustomWorkStylePreset(nil) |
297 | end |
periodChanged
DescriptionCalled if day changedDefinition
periodChanged()Code
343 | function HandTool:periodChanged() |
344 | self.age = self.age + 1 |
345 | end |
postLoad
DescriptionCalled after hand tool i3d file was loadedDefinition
postLoad(table xmlFile)Arguments
table | xmlFile | xmlFile |
170 | function HandTool:postLoad(xmlFile) |
171 | self.handNodePosition = {} |
172 | self.handNodeRotation = {} |
173 | self.handNode = nil |
174 | self.originalHandNodeParent = nil |
175 | self.referenceNode = nil |
176 | if self.player == g_currentMission.player then |
177 | self.handNodePosition = xmlFile:getValue("handTool.handNode.firstPerson#position", "0 0 0", true) |
178 | self.handNodeRotation = xmlFile:getValue("handTool.handNode.firstPerson#rotation", "0 0 0", true) |
179 | self.handNode = xmlFile:getValue("handTool.handNode.firstPerson#node", self.rootNode, self.components, self.i3dMappings) |
180 | self.referenceNode = xmlFile:getValue("handTool.handNode.firstPerson#referenceNode", nil, self.components, self.i3dMappings) |
181 | else |
182 | self.handNodePosition = xmlFile:getValue("handTool.handNode.thirdPerson#position", "0 0 0", true) |
183 | self.handNodeRotation = xmlFile:getValue("handTool.handNode.thirdPerson#rotation", "0 0 0", true) |
184 | self.handNode = xmlFile:getValue("handTool.handNode.thirdPerson#node", self.rootNode, self.components, self.i3dMappings) |
185 | self.referenceNode = xmlFile:getValue("handTool.handNode.thirdPerson#referenceNode", nil, self.components, self.i3dMappings) |
186 | end |
187 | |
188 | if self.rootNode ~= self.handNode then |
189 | self.originalHandNodeParent = getParent(self.handNode) |
190 | end |
191 | |
192 | self.customWorkStylePresetName = xmlFile:getValue("handTool.playerWorkStylePreset", nil) |
193 | |
194 | setTranslation(self.handNode, unpack(self.handNodePosition)) |
195 | setRotation(self.handNode, unpack(self.handNodeRotation)) |
196 | |
197 | local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName) |
198 | if self.price == 0 or self.price == nil then |
199 | self.price = StoreItemUtil.getDefaultPrice(storeItem) |
200 | end |
201 | |
202 | if g_currentMission ~= nil and storeItem.canBeSold then |
203 | g_messageCenter:subscribe(MessageType.PERIOD_CHANGED, self.periodChanged, self) |
204 | end |
205 | |
206 | self.targets = {} |
207 | IKUtil.loadIKChainTargets(xmlFile, "handTool.targets", self.components, self.targets, self.i3dMappings) |
208 | |
209 | setVisibility(self.rootNode, false) |
210 | self.isActive = false |
211 | |
212 | return true |
213 | end |
registerActionEvents
DescriptionDefinitionregisterActionEvents()Code
355 | function HandTool:registerActionEvents() |
356 | g_inputBinding:beginActionEventsModification(Player.INPUT_CONTEXT_NAME) |
357 | -- @Note: register general handtool actions here |
358 | g_inputBinding:endActionEventsModification() |
359 | end |
removeActionEvents
DescriptionDefinitionremoveActionEvents()Code
363 | function HandTool:removeActionEvents() |
364 | g_inputBinding:beginActionEventsModification(Player.INPUT_CONTEXT_NAME) |
365 | g_inputBinding:removeActionEventsByTarget(self) |
366 | g_inputBinding:endActionEventsModification() |
367 | end |
saveToXMLFile
DescriptionDefinitionsaveToXMLFile()Code
307 | function HandTool:saveToXMLFile(xmlFile, key, usedModNames) |
308 | xmlFile:setValue(key.."#filename", HTMLUtil.encodeToHTML(NetworkUtil.convertToNetworkFilename(self.configFileName))) |
309 | end |
setHandNode
DescriptionDefinitionsetHandNode()Code
217 | function HandTool:setHandNode(playerHandNode) |
218 | if self.currentPlayerHandNode ~= playerHandNode then |
219 | self.currentPlayerHandNode = playerHandNode |
220 | link(playerHandNode, self.handNode) |
221 | |
222 | if self.referenceNode ~= nil then |
223 | local x, y, z = getWorldTranslation(self.referenceNode) |
224 | x, y, z = worldToLocal(getParent(self.handNode), x, y, z) |
225 | local a, b, c = getTranslation(self.handNode) |
226 | setTranslation(self.handNode, a - x, b - y, c - z) |
227 | end |
228 | end |
229 | end |
update
DescriptionDefinitionupdate()Code
259 | function HandTool:update(dt, allowInput) |
260 | if self.isActive then |
261 | self:raiseActive() |
262 | end |
263 | end |