LUADOC - Farming Simulator 17

Printable Version

Script v1.4.4.0

Engine v7.0.0.2

Foundation Reference

Honk

Description
Specialization for honking
Functions

prerequisitesPresent

Description
Checks if all prerequisite specializations are loaded
Definition
prerequisitesPresent(table specializations)
Arguments
tablespecializationsspecializations
Return Values
booleanhasPrerequisitetrue if all prerequisite specializations are loaded
Code
19function Honk.prerequisitesPresent(specializations)
20 return SpecializationUtil.hasSpecialization(Drivable, specializations);
21end;

load

Description
Called on loading
Definition
load(table savegame)
Arguments
tablesavegamesavegame
Code
26function 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;
33end;

delete

Description
Called on deleting
Definition
delete()
Code
37function Honk:delete()
38 if self.isClient then
39 SoundUtil.deleteSample(self.sampleHonk);
40 end;
41end;

update

Description
Called on update
Definition
update(float dt)
Arguments
floatdttime since last call in ms
Code
58function 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;
73end;

draw

Description
Called on draw
Definition
draw()
Code
80function 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;
84end;

onDeactivateSounds

Description
Called on deactivating sounds
Definition
onDeactivateSounds()
Code
88function Honk:onDeactivateSounds()
89 if self.isClient then
90 SoundUtil.stopSample(self.sampleHonk, true);
91 SoundUtil.stop3DSample(self.sampleHonk);
92 end;
93end;

playHonk

Description
Play honk
Definition
playHonk(boolean isPlaying)
Arguments
booleanisPlayingnew is playing
Code
98function 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;
118end;