function createHorn ( )
local x, y, z = getElementPosition ( player ) -- variable player not defined
local vehicle = getPedOccupiedVehicle ( player ) -- variable player not defined
local sound = playSound3( "newhorn.mp3" ) -- function playSound3 not exists, should be playSound3D but this function only client side
setSoundVolume ( sound, 0.5 ) -- client side function, but you use in server side
attachElements ( sound, vehicle )
end
addCommandHandler("horn", createHorn)
function onPlayerJoin()
bindKey( source, "h", "both", createHorn )
end
addEventHandler( "onPlayerJoin", root, onPlayerJoin )
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()),
function ()
for i,v in pairs(getElementsByType("player")) do
bindKey(v,"h","both",createHorn)
end
end)
Read comments
Also tabulate your code in next time.
https://wiki.multitheftauto.com/wiki/Scr ... troduction