Script v1.4.4.0
Engine v7.0.0.2
- General
- Entity
- Node
- Scenegraph
- Lighting
- Camera
- Shape
- Particle System
- Physics
- Spline
- Animation
- Overlays
- Sound
- Input
- XML
- Network
- Callbacks
- Text Rendering
- Terrain Detail
- Tire Track
- Editor
- Rendering
- String
- Math
- I3D
- Fillplanes
Foundation Reference
HandTool
DescriptionClass for handtoolsFunctions
- registerHandTool
- new
- load
- readStream
- writeStream
- delete
- onActivate
- onDeactivate
- getDailyUpKeep
- getSellPrice
- dayChanged
registerHandTool
DescriptionRegister handtool typeDefinition
registerHandTool(string typeName, table classObject)Arguments
string | typeName | name of new type |
table | classObject | class object |
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.owner = nil; |
39 | self.price = 0; |
40 | self.age = 0; |
41 | return self; |
42 | end; |
load
DescriptionLoad chainsaw from xml fileDefinition
load(string xmlFilename, table player)Arguments
string | xmlFilename | xml file name |
table | player | player |
boolean | success | success |
49 | function HandTool:load(xmlFilename, player) |
50 | self.configFileName = xmlFilename; |
51 | |
52 | self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(xmlFilename); |
53 | |
54 | local xmlFile = loadXMLFile("TempXML", xmlFilename); |
55 | if xmlFile == 0 then |
56 | return false; |
57 | end; |
58 | local i3dFilename = getXMLString(xmlFile, "handTool.filename"); |
59 | self.position = Utils.getVectorNFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.position#value"), "0 0 0"), 3); |
60 | self.rotation = Utils.getRadiansFromString(Utils.getNoNil(getXMLString(xmlFile, "handTool.rotation#value"), "0 0 0"), 3); |
61 | |
62 | if i3dFilename == nil then |
63 | delete(xmlFile); |
64 | return false; |
65 | end; |
66 | self.i3dFilename = Utils.getFilename(i3dFilename, self.baseDirectory); |
67 | |
68 | local node = Utils.loadSharedI3DFile(self.i3dFilename); |
69 | self.rootNode = getChildAt(node, 0); |
70 | self.player = player; |
71 | |
72 | local storeItem = StoreItemsUtil.storeItemsByXMLFilename[self.configFileName:lower()] |
73 | if self.price == 0 or self.price == nil then |
74 | self.price = StoreItemsUtil.getDefaultPrice(storeItem); |
75 | end |
76 | |
77 | if g_currentMission ~= nil and storeItem.canBeSold then |
78 | g_currentMission.environment:addDayChangeListener(self) |
79 | end |
80 | |
81 | self.targets = {}; |
82 | IKUtil.loadIKChainTargets(xmlFile, "handTool.targets", self.rootNode, self.targets); |
83 | |
84 | link(player.toolsRootNode, self.rootNode); |
85 | setTranslation(self.rootNode, self.position[1], self.position[2], self.position[3]); |
86 | setRotation(self.rootNode, self.rotation[1], self.rotation[2], self.rotation[3]); |
87 | |
88 | delete(node); |
89 | delete(xmlFile); |
90 | setVisibility(self.rootNode, false); |
91 | |
92 | if player.isOwner then |
93 | g_currentMission:addHandTool(self); |
94 | end; |
95 | |
96 | return true; |
97 | end; |
readStream
DescriptionCalled on client side on joinDefinition
readStream(integer streamId, table connection, table player)Arguments
integer | streamId | stream ID |
table | connection | connection |
table | player | player |
107 | function HandTool:readStream(streamId, connection, player) |
108 | local filename = Utils.convertFromNetworkFilename(streamReadString(streamId)); |
109 | self:load(filename, player); |
110 | self.age = streamReadUInt16(streamId); |
111 | self.price = streamReadUInt16(streamId); |
112 | end; |
writeStream
DescriptionCalled on server side on joinDefinition
writeStream(integer streamId, table connection)Arguments
integer | streamId | stream ID |
table | connection | connection |
118 | function HandTool:writeStream(streamId, connection) |
119 | streamWriteString(streamId, Utils.convertToNetworkFilename(self.configFileName)); |
120 | streamWriteUInt16(streamId, self.age); |
121 | streamWriteUInt16(streamId, self.price); |
122 | end; |
delete
DescriptionDeleting handtoolDefinition
delete()Code
126 | function HandTool:delete() |
127 | if g_currentMission ~= nil then |
128 | g_currentMission.environment:removeDayChangeListener(self) |
129 | end |
130 | if self.player.isOwner then |
131 | g_currentMission:removeHandTool(self); |
132 | end; |
133 | if self.rootNode ~= nil and self.rootNode ~= 0 then |
134 | Utils.releaseSharedI3DFile(self.i3dFilename, nil, true); |
135 | delete(self.rootNode); |
136 | end; |
137 | end; |
onActivate
DescriptionOn activateDefinition
onActivate(boolean allowInput)Arguments
boolean | allowInput | allow input |
151 | function HandTool:onActivate(allowInput) |
152 | setVisibility(self.rootNode, true); |
153 | end; |
onDeactivate
DescriptionOn deactivateDefinition
onDeactivate(boolean allowInput)Arguments
boolean | allowInput | allow input |
158 | function HandTool:onDeactivate(allowInput) |
159 | setVisibility(self.rootNode, false); |
160 | end; |
getDailyUpKeep
DescriptionGet daily up keepDefinition
getDailyUpKeep()Return Values
float | dailyUpKeep | daily up keep |
175 | function HandTool:getDailyUpKeep() |
176 | local storeItem = StoreItemsUtil.storeItemsByXMLFilename[self.configFileName:lower()] |
177 | local multiplier = 1 |
178 | if storeItem.lifetime ~= nil and storeItem.lifetime ~= 0 then |
179 | local ageMultiplier = math.min(self.age/storeItem.lifetime, 1) |
180 | multiplier = EconomyManager.MAX_DAILYUPKEEP_MULTIPLIER * ageMultiplier |
181 | end |
182 | return StoreItemsUtil.getDailyUpkeep(storeItem, nil) * multiplier |
183 | end |
getSellPrice
DescriptionGet sell priceDefinition
getSellPrice()Return Values
float | sellPrice | sell price |
188 | function HandTool:getSellPrice() |
189 | local priceMultiplier = 0.5 |
190 | local maxVehicleAge = StoreItemsUtil.storeItemsByXMLFilename[self.configFileName:lower()].lifetime; |
191 | |
192 | if maxVehicleAge ~= nil and maxVehicleAge ~= 0 then |
193 | priceMultiplier = priceMultiplier * math.exp(-3.5 * math.min(self.age/maxVehicleAge, 1)) |
194 | end |
195 | |
196 | return math.floor(self.price * math.max(priceMultiplier, 0.05)); |
197 | end |
dayChanged
DescriptionCalled if day changedDefinition
dayChanged()Code
201 | function HandTool:dayChanged() |
202 | self.age = self.age + 1; |
203 | end |