Hi,
I'm from Germany and i have a Problem with my Script.
I'd like a train horn create the all hear on the server.
Unfortunately, my script does not work and I can not continue to hope for your help.
File train_horn.lua Server:
function onTrainHornUse (player, key, keyState)
local theVehicle = getPedOccupiedVehicle(player)
if (not theVehicle) then
return
end
if (getElementModel(theVehicle) == 537) or (getElementModel(theVehicle) == 538) then
if (keyState == "down") then
triggerClientEvent(root, "onStartTrainHorn", player)
elseif (keyState == "up") then
triggerClientEvent(root, "stopTrainHorn", player)
end
end
end
function onBindPlayerTrain(player)
bindKey(player, "h", "down", onTrainHornUse)
bindKey(player, "h", "up", onTrainHornUse)
end
addEventHandler("onPlayerSpawn", getRootElement(), onBindPlayerTrain)
File train_horn_sound.lua Client:
function onStartTrainHorn(player)
if (player) then
local theVehicle = getPedOccupiedVehicle(player)
if (not theVehicle) then
return
end
local x, y, z = getElementPosition(player)
getTrainSound = playSound3D("addons/trainhorn/trainhorn.wav", x, y, z)
setSoundVolume(getTrainSound, 1.0)
setSoundMaxDistance(getTrainSound, 190)
attachElements(getTrainSound, theVehicle)
end
end
addEvent("onStartTrainHorn", true)
addEventHandler("onStartTrainHorn", getRootElement(), onStartTrainHorn)
function stopTrainHorn()
if isElement(getTrainSound) then
stopSound(getTrainSound)
end
end
addEvent("stopTrainHorn", true)
addEventHandler("stopTrainHorn", getRootElement(), stopTrainHorn)
Now I wait for an answer.