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
- getMaterialCustomShader
- getMaterialCustomShaderVariation
- getMaterialDiffuseMap
- getMaterialDiffuseMapHasAlpha
- getMaterialEmissiveMap
- getMaterialEmissiveMapHasAlpha
- getMaterialGlossMap
- getMaterialHasRefractionMap
- getMaterialIsAlphaBlended
- getMaterialIsAlphaTested
- getMaterialNormalMap
- getMaterialNormalMapFormat
- getMaterialReflectionMapScaling
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
HandTool
DescriptionClass for handtoolsParent
ObjectFunctions
- dayChanged
- delete
- getDailyUpkeep
- getSellPrice
- isBeingUsed
- load
- new
- onActivate
- onDeactivate
- registerActionEvents
- removeActionEvents
- setHandNode
- update
dayChanged
DescriptionCalled if day changedDefinition
dayChanged()Code
219 | function HandTool:dayChanged() |
220 | self.age = self.age + 1 |
221 | end |
delete
DescriptionDeleting handtoolDefinition
delete()Code
133 | function HandTool:delete() |
134 | self:removeActionEvents() |
135 | |
136 | if g_currentMission ~= nil then |
137 | g_currentMission.environment:removeDayChangeListener(self) |
138 | end |
139 | if self.rootNode ~= nil and self.rootNode ~= 0 then |
140 | if self.originalHandNodeParent ~= nil and getParent(self.handNode) ~= self.originalHandNodeParent then |
141 | link(self.originalHandNodeParent, self.handNode) |
142 | end |
143 | g_i3DManager:releaseSharedI3DFile(self.i3dFilename, g_currentMission.baseDirectory, false) |
144 | delete(self.rootNode) |
145 | end |
146 | HandTool:superClass().delete(self) |
147 | end |
getDailyUpkeep
DescriptionGet daily up keepDefinition
getDailyUpkeep()Return Values
float | dailyUpkeep | daily up keep |
190 | function HandTool:getDailyUpkeep() |
191 | local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName) |
192 | local multiplier = 1 |
193 | |
194 | if storeItem.lifetime ~= nil and storeItem.lifetime ~= 0 then |
195 | local ageMultiplier = math.min(self.age / storeItem.lifetime, 1) |
196 | multiplier = EconomyManager.MAX_DAILYUPKEEP_MULTIPLIER * ageMultiplier |
197 | end |
198 | |
199 | return StoreItemUtil.getDailyUpkeep(storeItem, nil) * multiplier |
200 | end |
getSellPrice
DescriptionGet sell priceDefinition
getSellPrice()Return Values
float | sellPrice | sell price |
205 | function HandTool:getSellPrice() |
206 | local priceMultiplier = 0.5 |
207 | local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName) |
208 | local maxVehicleAge = storeItem.lifetime |
209 | |
210 | if maxVehicleAge ~= nil and maxVehicleAge ~= 0 then |
211 | priceMultiplier = priceMultiplier * math.exp(-3.5 * math.min(self.age/maxVehicleAge, 1)) |
212 | end |
213 | |
214 | return math.floor(self.price * math.max(priceMultiplier, 0.05)) |
215 | end |
isBeingUsed
DescriptionDefinitionisBeingUsed()Code
225 | function HandTool:isBeingUsed() |
226 | return false |
227 | end |
load
DescriptionLoad chainsaw from xml fileDefinition
load(string xmlFilename, table player)Arguments
string | xmlFilename | xml file name |
table | player | player |
boolean | success | success |
52 | function HandTool:load(xmlFilename, player) |
53 | self.configFileName = xmlFilename |
54 | |
55 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(xmlFilename) |
56 | |
57 | local xmlFile = loadXMLFile("TempXML", xmlFilename) |
58 | if xmlFile == 0 then |
59 | return false |
60 | end |
61 | local i3dFilename = getXMLString(xmlFile, "handTool.filename") |
62 | |
63 | if i3dFilename == nil then |
64 | delete(xmlFile) |
65 | return false |
66 | end |
67 | self.i3dFilename = Utils.getFilename(i3dFilename, self.baseDirectory) |
68 | |
69 | local node = g_i3DManager:loadSharedI3DFile(self.i3dFilename) |
70 | self.rootNode = getChildAt(node, 0) |
71 | self.player = player |
72 | |
73 | self.handNodePosition = {} |
74 | self.handNodeRotation = {} |
75 | self.handNode = nil |
76 | self.originalHandNodeParent = nil |
77 | self.referenceNode = nil |
78 | if self.player == g_currentMission.player then |
79 | self.handNodePosition = StringUtil.getVectorNFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.handNode.firstPerson#position"), "0 0 0"), 3) |
80 | self.handNodeRotation = StringUtil.getRadiansFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.handNode.firstPerson#rotation"), "0 0 0"), 3) |
81 | self.handNode = Utils.getNoNil(I3DUtil.indexToObject(self.rootNode, getXMLString(xmlFile, "handTool.handNode.firstPerson#node")), self.rootNode) |
82 | self.referenceNode = I3DUtil.indexToObject(self.rootNode, getXMLString(xmlFile, "handTool.handNode.firstPerson#referenceNode")) |
83 | else |
84 | self.handNodePosition = StringUtil.getVectorNFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.handNode.thirdPerson#position"), "0 0 0"), 3) |
85 | self.handNodeRotation = StringUtil.getRadiansFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.handNode.thirdPerson#rotation"), "0 0 0"), 3) |
86 | self.handNode = Utils.getNoNil(I3DUtil.indexToObject(self.rootNode, getXMLString(xmlFile, "handTool.handNode.thirdPerson#node")), self.rootNode) |
87 | self.referenceNode = I3DUtil.indexToObject(self.rootNode, getXMLString(xmlFile, "handTool.handNode.thirdPerson#referenceNode")) |
88 | end |
89 | |
90 | if self.rootNode ~= self.handNode then |
91 | self.originalHandNodeParent = getParent(self.handNode) |
92 | end |
93 | |
94 | setTranslation(self.handNode, unpack(self.handNodePosition)) |
95 | setRotation(self.handNode, unpack(self.handNodeRotation)) |
96 | |
97 | local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName) |
98 | if self.price == 0 or self.price == nil then |
99 | self.price = StoreItemUtil.getDefaultPrice(storeItem) |
100 | end |
101 | |
102 | if g_currentMission ~= nil and storeItem.canBeSold then |
103 | g_currentMission.environment:addDayChangeListener(self) |
104 | end |
105 | |
106 | self.targets = {} |
107 | IKUtil.loadIKChainTargets(xmlFile, "handTool.targets", self.rootNode, self.targets, nil) |
108 | |
109 | setVisibility(self.rootNode, false) |
110 | self.isActive = false |
111 | delete(xmlFile) |
112 | return true |
113 | 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 |
30 | function HandTool:new(isServer, isClient, customMt) |
31 | local mt = customMt |
32 | if mt == nil then |
33 | mt = HandTool_mt |
34 | end |
35 | |
36 | local self = Object:new(isServer, isClient, mt) |
37 | self.static = true |
38 | self.player = nil |
39 | self.owner = nil |
40 | self.currentPlayerHandNode = nil |
41 | self.price = 0 |
42 | self.age = 0 |
43 | self.activatePressed = false |
44 | return self |
45 | end |
onActivate
DescriptionOn activateDefinition
onActivate(boolean allowInput)Arguments
boolean | allowInput | allow input |
160 | function HandTool:onActivate(allowInput) |
161 | setVisibility(self.rootNode, true) |
162 | self.isActive = true |
163 | self:raiseActive() |
164 | |
165 | if self.player.isOwner then |
166 | self:registerActionEvents() |
167 | end |
168 | end |
onDeactivate
DescriptionOn deactivateDefinition
onDeactivate(boolean allowInput)Arguments
boolean | allowInput | allow input |
173 | function HandTool:onDeactivate(allowInput) |
174 | setVisibility(self.rootNode, false) |
175 | self.isActive = false |
176 | self:removeActionEvents() |
177 | end |
registerActionEvents
DescriptionDefinitionregisterActionEvents()Code
231 | function HandTool:registerActionEvents() |
232 | g_inputBinding:beginActionEventsModification(Player.INPUT_CONTEXT_NAME) |
233 | -- @Note: register general handtool actions here |
234 | g_inputBinding:endActionEventsModification() |
235 | end |
removeActionEvents
DescriptionDefinitionremoveActionEvents()Code
239 | function HandTool:removeActionEvents() |
240 | g_inputBinding:beginActionEventsModification(Player.INPUT_CONTEXT_NAME) |
241 | g_inputBinding:removeActionEventsByTarget(self) |
242 | g_inputBinding:endActionEventsModification() |
243 | end |
setHandNode
DescriptionDefinitionsetHandNode()Code
117 | function HandTool:setHandNode(playerHandNode) |
118 | if self.currentPlayerHandNode ~= playerHandNode then |
119 | self.currentPlayerHandNode = playerHandNode |
120 | link(playerHandNode, self.handNode) |
121 | |
122 | if self.referenceNode ~= nil then |
123 | local x, y, z = getWorldTranslation(self.referenceNode) |
124 | x, y, z = worldToLocal(getParent(self.handNode), x, y, z) |
125 | local a, b, c = getTranslation(self.handNode) |
126 | setTranslation(self.handNode, a - x, b - y, c - z) |
127 | end |
128 | end |
129 | end |
update
DescriptionDefinitionupdate()Code
151 | function HandTool:update(dt, allowInput) |
152 | if self.isActive then |
153 | self:raiseActive() |
154 | end |
155 | end |