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
HighPressureWasherLance
DescriptionClass for high pressure washer lanceParent
HandToolFunctions
- cleanVehicle
- delete
- getIsActiveForInput
- isBeingUsed
- load
- new
- onDeactivate
- setIsWashing
- update
- washRaycastCallback
cleanVehicle
DescriptionClean vehicleDefinition
cleanVehicle(integer node, float dt)Arguments
integer | node | node id |
float | dt | time since last call in ms |
123 | function HighPressureWasherLance:cleanVehicle(node, dt) |
124 | local x, y, z = getWorldTranslation(node) |
125 | local dx, dy, dz = localDirectionToWorld(node, 0, 0, -1) |
126 | local lastFoundVehicle = self.foundVehicle |
127 | raycastAll(x, y, z, dx, dy, dz, "washRaycastCallback", self.washDistance, self, 32+64+128+256+4096+8194) |
128 | |
129 | if self.foundVehicle ~= nil and lastFoundVehicle ~= self.foundVehicle then |
130 | self.foundVehicle:addDirtAmount(-self.washMultiplier * dt / self.foundVehicle:getWashDuration()) |
131 | end |
132 | end |
delete
DescriptionDeletingDefinition
delete()Code
53 | function HighPressureWasherLance:delete() |
54 | g_effectManager:deleteEffects(self.effects) |
55 | g_soundManager:deleteSample(self.washingSample) |
56 | HighPressureWasherLance:superClass().delete(self) |
57 | end |
getIsActiveForInput
DescriptionGet is active for inputDefinition
getIsActiveForInput()Return Values
boolean | isActiveForInput | is active for input |
172 | function HighPressureWasherLance:getIsActiveForInput() |
173 | if self.player == g_currentMission.player and not g_gui:getIsGuiVisible() then |
174 | return true |
175 | end |
176 | return false |
177 | end |
isBeingUsed
DescriptionDefinitionisBeingUsed()Code
181 | function HighPressureWasherLance:isBeingUsed() |
182 | return self.doWashing |
183 | end |
load
DescriptionDefinitionload()Code
29 | function HighPressureWasherLance:load(xmlFilename, player) |
30 | if not HighPressureWasherLance:superClass().load(self, xmlFilename, player) then |
31 | return false |
32 | end |
33 | |
34 | -- Lance model |
35 | local xmlFile = loadXMLFile("TempXML", xmlFilename) |
36 | self.lanceNode = I3DUtil.indexToObject(self.rootNode, getXMLString(xmlFile, "handTool.highPressureWasherLance.lance#node")) |
37 | self.lanceRaycastNode = I3DUtil.indexToObject(self.rootNode, getXMLString(xmlFile, "handTool.highPressureWasherLance.lance#raycastNode")) |
38 | self.washDistance = Utils.getNoNil(getXMLFloat(xmlFile, "handTool.highPressureWasherLance.lance#washDistance"), 10) |
39 | self.washMultiplier = Utils.getNoNil(getXMLFloat(xmlFile, "handTool.highPressureWasherLance.lance#washMultiplier"), 1) |
40 | self.pricePerSecond = Utils.getNoNil(getXMLFloat(xmlFile, "handTool.highPressureWasherLance.lance#pricePerMinute"), 10) / 1000 |
41 | |
42 | self.effects = g_effectManager:loadEffect(xmlFile, "handTool.highPressureWasherLance.effects", self.rootNode, self) |
43 | g_effectManager:setFillType(self.effects, FillType.WATER) |
44 | |
45 | -- Sounds |
46 | self.washingSample = g_soundManager:loadSampleFromXML(xmlFile, "handTool.highPressureWasherLance.sounds", "washing", self.baseDirectory, self.rootNode, 0, AudioGroup.VEHICLE, nil, self) |
47 | |
48 | return true |
49 | end |
new
DescriptionDefinitionnew()Code
14 | function HighPressureWasherLance:new(isServer, isClient, customMt) |
15 | local self = HighPressureWasherLance:superClass().new(self, isServer, isClient, customMt or HighPressureWasherLance_mt) |
16 | |
17 | self.foundVehicle = nil |
18 | self.doWashing = false |
19 | self.washDistance = 10.0 |
20 | self.washMultiplier = 1.0 |
21 | self.pricePerSecond = 10 |
22 | self.isHPWLance = true |
23 | |
24 | return self |
25 | end |
onDeactivate
DescriptionDefinitiononDeactivate()Code
61 | function HighPressureWasherLance:onDeactivate() |
62 | self:setIsWashing(false, true, true) |
63 | HighPressureWasherLance:superClass().onDeactivate(self) |
64 | end |
setIsWashing
DescriptionSet is washingDefinition
setIsWashing(boolean doWashing, boolean force, boolean noEventSend)Arguments
boolean | doWashing | do washing |
boolean | force | force |
boolean | noEventSend | no event send |
100 | function HighPressureWasherLance:setIsWashing(doWashing, force, noEventSend) |
101 | HPWLanceStateEvent.sendEvent(self.player, doWashing, noEventSend) |
102 | if self.doWashing ~= doWashing then |
103 | if doWashing then |
104 | g_effectManager:setFillType(self.effects, FillType.WATER) |
105 | g_effectManager:startEffects(self.effects) |
106 | g_soundManager:playSample(self.washingSample) |
107 | else |
108 | if force then |
109 | g_effectManager:resetEffects(self.effects) |
110 | else |
111 | g_effectManager:stopEffects(self.effects) |
112 | end |
113 | g_soundManager:stopSample(self.washingSample) |
114 | end |
115 | self.doWashing = doWashing |
116 | end |
117 | end |
update
DescriptionDefinitionupdate()Code
68 | function HighPressureWasherLance:update(dt, allowInput) |
69 | HighPressureWasherLance:superClass().update(self, dt) |
70 | |
71 | if allowInput then |
72 | self:setIsWashing(self.activatePressed, false, false) |
73 | end |
74 | |
75 | if self.isServer then |
76 | if self.doWashing then |
77 | self.foundVehicle = nil |
78 | self:cleanVehicle(self.player.cameraNode, dt) |
79 | if self.lanceRaycastNode ~= nil then |
80 | self:cleanVehicle(self.lanceRaycastNode, dt) |
81 | end |
82 | if self.foundVehicle ~= nil then |
83 | local farmId = self.foundVehicle:getOwnerFarmId() |
84 | local price = self.pricePerSecond * (dt / 1000) |
85 | local stats = g_farmManager:getFarmById(self.player.farmId).stats |
86 | stats:updateStats("expenses", price) |
87 | g_currentMission:addMoney(-price, farmId, MoneyType.VEHICLE_RUNNING_COSTS) |
88 | end |
89 | end |
90 | end |
91 | self.activatePressed = false |
92 | self:raiseActive() |
93 | end |
washRaycastCallback
DescriptionWash raycast callbackDefinition
washRaycastCallback(integer hitActorId, float x, float y, float z, float distance, float nx, float ny, float nz, integer subShapeIndex, integer hitShapeId)Arguments
integer | hitActorId | id of hit object actor |
float | x | x raycast position |
float | y | y raycast position |
float | z | z raycast position |
float | distance | distance to raycast position |
float | nx | x component of hit surface normal (unused) |
float | ny | y component of hit surface normal (unused) |
float | nz | z component of hit surface normal (unused) |
integer | subShapeIndex | sub shape index of hit object |
integer | hitShapeId | id of hit object shape |
146 | function HighPressureWasherLance:washRaycastCallback(hitActorId, x, y, z, distance, nx, ny, nz, subShapeIndex, hitShapeId) |
147 | local vehicle = g_currentMission.nodeToObject[hitActorId] |
148 | if hitActorId ~= hitShapeId then |
149 | -- object is a compoundChild. Try to find the compound |
150 | local parentId = hitShapeId |
151 | while parentId ~= 0 do |
152 | if g_currentMission.nodeToObject[parentId] ~= nil then |
153 | -- found valid compound |
154 | vehicle = g_currentMission.nodeToObject[parentId] |
155 | break |
156 | end |
157 | parentId = getParent(parentId) |
158 | end |
159 | end |
160 | |
161 | if vehicle ~= nil and vehicle.getAllowsWashingByType ~= nil and vehicle:getAllowsWashingByType(Washable.WASHTYPE_HIGH_PRESSURE_WASHER) then |
162 | self.foundVehicle = vehicle |
163 | return false |
164 | end |
165 | return true |
166 | end |