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
Honk
DescriptionSpecialization adding honk/horn functionality to a vehicleFunctions
- actionEventHonk
- onDelete
- onLeaveVehicle
- onLoad
- onRegisterActionEvents
- onUpdate
- playHonk
- prerequisitesPresent
- registerEventListeners
- registerFunctions
actionEventHonk
DescriptionDefinitionactionEventHonk()Code
121 | function Honk.actionEventHonk(self, actionName, inputValue, callbackState, isAnalog) |
122 | local spec = self.spec_honk |
123 | spec.inputPressed = true |
124 | end |
onDelete
DescriptionCalled on deletingDefinition
onDelete()Code
51 | function Honk:onDelete() |
52 | if self.isClient then |
53 | local spec = self.spec_honk |
54 | g_soundManager:deleteSample(spec.sample) |
55 | end |
56 | end |
onLeaveVehicle
DescriptionCalled on leaving the vehicleDefinition
onLeaveVehicle()Code
78 | function Honk:onLeaveVehicle() |
79 | self:playHonk(false, true) |
80 | end |
onLoad
DescriptionDefinitiononLoad()Code
39 | function Honk:onLoad(savegame) |
40 | local spec = self.spec_honk |
41 | |
42 | spec.inputPressed = false |
43 | spec.isPlaying = false |
44 | if self.isClient then |
45 | spec.sample = g_soundManager:loadSampleFromXML(self.xmlFile, "vehicle.honk", "sound", self.baseDirectory, self.components, 0, AudioGroup.VEHICLE, self.i3dMappings, self) |
46 | end |
47 | end |
onRegisterActionEvents
DescriptionDefinitiononRegisterActionEvents()Code
105 | function Honk:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection) |
106 | if self.isClient then |
107 | local spec = self.spec_honk |
108 | self:clearActionEventsTable(spec.actionEvents) |
109 | |
110 | if isActiveForInputIgnoreSelection and spec.sample ~= nil then |
111 | local _, actionEventId = self:addActionEvent(spec.actionEvents, InputAction.HONK, self, Honk.actionEventHonk, false, true, true, true, nil) |
112 | g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_VERY_LOW) |
113 | g_inputBinding:setActionEventActive(actionEventId, true) |
114 | g_inputBinding:setActionEventText(actionEventId, g_i18n:getText("action_honk")) |
115 | end |
116 | end |
117 | end |
onUpdate
DescriptionDefinitiononUpdate()Code
60 | function Honk:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected) |
61 | if self.isClient and isActiveForInputIgnoreSelection then |
62 | local spec = self.spec_honk |
63 | if spec.inputPressed then |
64 | if not g_soundManager:getIsSamplePlaying(spec.sample) then |
65 | self:playHonk(true) |
66 | end |
67 | else |
68 | if spec.isPlaying then |
69 | self:playHonk(false) |
70 | end |
71 | end |
72 | spec.inputPressed = false |
73 | end |
74 | end |
playHonk
DescriptionDefinitionplayHonk()Code
84 | function Honk:playHonk(isPlaying, noEventSend) |
85 | HonkEvent.sendEvent(self, isPlaying, noEventSend) |
86 | local spec = self.spec_honk |
87 | |
88 | spec.isPlaying = isPlaying |
89 | if spec.sample ~= nil then |
90 | |
91 | if isPlaying then |
92 | if self:getIsActive() then |
93 | if self.isClient then |
94 | g_soundManager:playSample(spec.sample) |
95 | end |
96 | end |
97 | else |
98 | g_soundManager:stopSample(spec.sample) |
99 | end |
100 | end |
101 | end |
prerequisitesPresent
DescriptionDefinitionprerequisitesPresent()Code
17 | function Honk.prerequisitesPresent(specializations) |
18 | return SpecializationUtil.hasSpecialization(Drivable, specializations) |
19 | end |
registerEventListeners
DescriptionDefinitionregisterEventListeners()Code
29 | function Honk.registerEventListeners(vehicleType) |
30 | SpecializationUtil.registerEventListener(vehicleType, "onLoad", Honk) |
31 | SpecializationUtil.registerEventListener(vehicleType, "onDelete", Honk) |
32 | SpecializationUtil.registerEventListener(vehicleType, "onUpdate", Honk) |
33 | SpecializationUtil.registerEventListener(vehicleType, "onLeaveVehicle", Honk) |
34 | SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", Honk) |
35 | end |
registerFunctions
DescriptionDefinitionregisterFunctions()Code
23 | function Honk.registerFunctions(vehicleType) |
24 | SpecializationUtil.registerFunction(vehicleType, "playHonk", Honk.playHonk) |
25 | end |