-- server side:
addEventHandler ( "onResourceStart", resourceRoot,
function ( )
for _, player in ipairs ( getElementsByType ( "player" ) ) do
bindKey ( player, "H", "down", playHorn )
bindKey ( player, "H", "up", playHorn )
end
end
)
addEventHandler ( "onPlayerJoin", root,
function ( )
bindKey ( source, "H", "down", playHorn )
bindKey ( source, "H", "up", playHorn )
end
)
function playHorn ( thePlayer, key, keyState )
local theVehicle = getPedOccupiedVehicle ( thePlayer )
if ( not theVehicle ) then
return
end
if ( getElementModel ( theVehicle ) == 537 ) then
triggerClientEvent ( "vehicleHorn", root, ( keyState == "down" and true or false ), theVehicle )
end
end
-- client side:
addEvent ( "vehicleHorn", true )
addEventHandler ( "vehicleHorn", root,
function ( state, theVehicle )
if isElement ( desusound ) then
stopSound ( desusound )
end
if ( state ) then
local x, y, z = getElementPosition ( theVehicle )
desusound = playSound3D ( 'hupe/ZUGHUPE.mp3', x, y, z )
setSoundVolume ( desusound, 5.0 )
setSoundMaxDistance ( desusound, 190 )
attachElements ( desusound, theVehicle )
end
end
)