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
Honk
DescriptionSpecialization for honkingFunctions
prerequisitesPresent
DescriptionChecks if all prerequisite specializations are loadedDefinition
prerequisitesPresent(table specializations)Arguments
table | specializations | specializations |
boolean | hasPrerequisite | true if all prerequisite specializations are loaded |
19 | function Honk.prerequisitesPresent(specializations) |
20 | return SpecializationUtil.hasSpecialization(Drivable, specializations); |
21 | end; |
load
DescriptionCalled on loadingDefinition
load(table savegame)Arguments
table | savegame | savegame |
26 | function Honk:load(savegame) |
27 | |
28 | self.playHonk = Utils.overwrittenFunction(self.playHonk, Honk.playHonk); |
29 | |
30 | if self.isClient then |
31 | self.sampleHonk = SoundUtil.loadSample(self.xmlFile, {}, "vehicle.honkSound", nil, self.baseDirectory, self.components[1].node); |
32 | end; |
33 | end; |
delete
DescriptionCalled on deletingDefinition
delete()Code
37 | function Honk:delete() |
38 | if self.isClient then |
39 | SoundUtil.deleteSample(self.sampleHonk); |
40 | end; |
41 | end; |
update
DescriptionCalled on updateDefinition
update(float dt)Arguments
float | dt | time since last call in ms |
58 | function Honk:update(dt) |
59 | if self.isEntered and self.isClient and self:getIsActiveForInput(false) then |
60 | if self.sampleHonk ~= nil then |
61 | -- only send event if honking key is pressed or released |
62 | if InputBinding.isPressed(InputBinding.HONK) then |
63 | if not self.sampleHonk.isPlaying then |
64 | self:playHonk(true); |
65 | end; |
66 | else |
67 | if self.sampleHonk.isPlaying then |
68 | self:playHonk(false); |
69 | end; |
70 | end; |
71 | end; |
72 | end; |
73 | end; |
draw
DescriptionCalled on drawDefinition
draw()Code
80 | function Honk:draw() |
81 | if self.isClient and self:getIsActiveForInput(true) then |
82 | g_currentMission:addHelpButtonText(g_i18n:getText("action_honk"), InputBinding.HONK, nil, GS_PRIO_VERY_LOW); |
83 | end; |
84 | end; |
onDeactivateSounds
DescriptionCalled on deactivating soundsDefinition
onDeactivateSounds()Code
88 | function Honk:onDeactivateSounds() |
89 | if self.isClient then |
90 | SoundUtil.stopSample(self.sampleHonk, true); |
91 | SoundUtil.stop3DSample(self.sampleHonk); |
92 | end; |
93 | end; |
playHonk
DescriptionPlay honkDefinition
playHonk(boolean isPlaying)Arguments
boolean | isPlaying | new is playing |
98 | function Honk:playHonk(superFunc, isPlaying, noEventSend) |
99 | if superFunc ~= nil then |
100 | superFunc(self, isPlaying, noEventSend) |
101 | end |
102 | if self.sampleHonk ~= nil then |
103 | HonkEvent.sendEvent(self, isPlaying, noEventSend); |
104 | |
105 | if isPlaying then |
106 | if self:getIsActive() then |
107 | if self:getIsActiveForSound() then |
108 | SoundUtil.playSample(self.sampleHonk, 0, 0, nil); |
109 | elseif self.isControlled then |
110 | -- enable 3d sound to vehicle on another player's game |
111 | SoundUtil.play3DSample(self.sampleHonk); |
112 | end; |
113 | end; |
114 | else |
115 | Honk.onDeactivateSounds(self); |
116 | end; |
117 | end; |
118 | end; |