1
- local spam = {}
1
+ local spam = 0
2
2
3
- function initBind (thePlayer )
4
- if (thePlayer == localPlayer and getVehicleType (source ) == " Train" ) then
5
- bindKey (" H " , " down" , soundHorn )
3
+ function initBind (theVehicle )
4
+ if (getVehicleType (theVehicle ) == " Train" ) then
5
+ bindKey (" horn " , " down" , soundHorn )
6
6
end
7
7
end
8
- addEventHandler (" onClientVehicleEnter " , getRootElement () , initBind )
8
+ addEventHandler (" onClientPlayerVehicleEnter " , localPlayer , initBind )
9
9
10
10
function soundHorn ()
11
11
local vehicle = getPedOccupiedVehicle (localPlayer )
12
-
13
- if getVehicleType (vehicle ) ~= " Train" then return end
14
-
15
12
-- Make it so they can't play multiple train horns at the same time (causes lag and distortion)
16
- if spam [localPlayer ] and getTickCount () - spam [localPlayer ] < 5000 then
17
- return
18
- end
19
-
20
- if (vehicle and getVehicleController (vehicle ) == localPlayer ) then
21
- spam [localPlayer ] = getTickCount ()
22
- x , y , z = getElementPosition (vehicle )
23
- triggerServerEvent (" onSyncHorn" , getRootElement (), localPlayer , vehicle )
24
- sound = playSound3D (" horn.aac" , x , y , z , false )
25
- setSoundVolume (sound , 1.0 )
13
+ if (vehicle and getVehicleType (vehicle ) == " Train" and getVehicleController (vehicle ) == localPlayer and getTickCount () - spam >= 5000 ) then
14
+ spam = getTickCount ()
15
+ triggerServerEvent (" onSyncHorn" , resourceRoot )
16
+ local x , y , z = getElementPosition (vehicle )
17
+ local sound = playSound3D (" horn.aac" , x , y , z , false )
26
18
attachElements (sound , vehicle )
27
19
setSoundMaxDistance (sound , 250 )
28
20
end
29
21
end
30
22
31
23
function syncedHorn (train , x , y , z )
32
- if (isElement (train ) and getVehicleType (train ) == " Train" ) then
33
- sound = playSound3D (" horn.aac" , x , y , z , false )
34
- setSoundVolume (sound , 1.0 )
24
+ if (isElement (train ) and getVehicleType (train ) == " Train" and source ~= localPlayer ) then
25
+ local sound = playSound3D (" horn.aac" , x , y , z , false )
35
26
attachElements (sound , train )
36
27
setSoundMaxDistance (sound , 250 )
37
28
end
38
29
end
39
30
addEvent (" onPlaySyncedHorn" , true )
40
- addEventHandler (" onPlaySyncedHorn" , localPlayer , syncedHorn )
31
+ addEventHandler (" onPlaySyncedHorn" , root , syncedHorn )
41
32
42
- function cleanUp (thePlayer )
43
- if (thePlayer == localPlayer and getVehicleType (source ) == " Train" ) then
44
- unbindKey (" H " , " down" , soundHorn )
33
+ function cleanUp (theVehicle )
34
+ if (getVehicleType (theVehicle ) == " Train" ) then
35
+ unbindKey (" horn " , " down" , soundHorn )
45
36
end
46
37
end
47
- addEventHandler (" onClientVehicleExit " , getRootElement () , cleanUp )
38
+ addEventHandler (" onClientPlayerVehicleExit " , localPlayer , cleanUp )
48
39
49
- -- Dying in train, so not triggering onClientVehicleExit
40
+ -- Dying in train, so not triggering onClientPlayerVehicleExit
50
41
function integrityCheck ()
51
42
local vehicle = getPedOccupiedVehicle (localPlayer )
52
43
53
44
if (vehicle and getVehicleType (vehicle ) == " Train" ) then
54
- unbindKey (" H " , " down" , soundHorn )
45
+ unbindKey (" horn " , " down" , soundHorn )
55
46
end
56
47
end
57
48
addEventHandler (" onClientPlayerWasted" , localPlayer , integrityCheck )
0 commit comments