Jump to content

i need help


Stranger

Recommended Posts

hello guys

how can i attach sounds to the vehicle !!

i try to do it but it's hard

what is wrong in this:

local mm55 = createVehicle(560, 1586.3, -1656.8, 28.6) 
function sound () 
local sound = playSound3D("s.mp3",1586.3, -1656.8, 28.6, true) 
setSoundMaxDistance( sound, 50 ) 
attachElements(sound, mm55, 0, 0, 0) 
end 
addEventHandler("onClientResourceStart", resourceRoot, sound) 

Link to comment
local mm55 = createVehicle(560, 1586.3, -1656.8, 28.6) 
  
function sound () 
local x, y, z = getElementPosition ( mm55 ) 
local sound = playSound3D("s.mp3",x, y, z, true) 
setSoundMaxDistance( sound, 50 ) 
attachElements(sound, mm55) 
end 
addEventHandler("onClientResourceStart", resourceRoot, sound) 

Link to comment
function sound () 
local x, y, z = getElementPosition ( mm55 ) 
local sound = playSound3D("s.mp3",x, y, z, true) 
setSoundMaxDistance( sound, 50 ) 
attachElements(sound, mm55) 
triggerServerEvent("vehicle", localPlayer) 
end 
addEventHandler("onClientResourceStart", resourceRoot, sound) 

addEvent("vehicle", true) 
addEventHandler("vehicle", root, 
function () 
local mm55 = createVehicle(560, 1586.3, -1656.8, 28.6) 
end 
) 

Link to comment

CLIENT

local sound = { } 
addEvent( "onStartMusic", true ) 
addEventHandler( "onStartMusic", getRootElement(),  
    function (vehicle) 
        if vehicle then 
            local x,y,z = getElementPosition(vehicle) 
            local d = getElementDimension(vehicle) 
            local i = getElementInterior(vehicle) 
            local sound[vehicle] = playSound3D( "s.mp3", x, y, z, true) 
            attachElements(sound[vehicle],vehicle,0,0,0) 
            setSoundMaxDistance(sound[vehicle], 200) 
            setElementDimension(sound[vehicle], d) 
            setElementInterior(sound[vehicle], i) 
        end    
    end 
) 

SERVER

addEventHandler("onResourceStart", getRootElement(), 
    function () 
        local mm55 = createVehicle(560, 1586.3, -1656.8, 28.6) 
        triggerClientEvent ( "onStartMusic", getRootElement(), mm55 ) 
    end 
) 

Link to comment
local sound = { } 
addEvent( "onStartMusic", true ) 
addEventHandler( "onStartMusic", root, 
    function (vehicle) 
        if vehicle then 
            local x,y,z = getElementPosition(vehicle) 
            local d = getElementDimension(vehicle) 
            local i = getElementInterior(vehicle) 
            sound[vehicle] = playSound3D( "s.mp3", x, y, z, true) 
            attachElements(sound[vehicle],vehicle,0,0,0) 
            setSoundMaxDistance(sound[vehicle], 200) 
            setElementDimension(sound[vehicle], d) 
            setElementInterior(sound[vehicle], i) 
        end   
    end 
) 

It didn't worked because the table element sound[vehicle] was local.

Show us your meta.xml

Link to comment

It won't trigger because the client side script isn't loaded yet, you can fix this by this:

server:

addEventHandler("onResourceStart",resourceRoot, 
    function () 
      mm55 = createVehicle(560, 1586.3, -1656.8, 28.6) 
setTimer ( function () 
triggerClientEvent ( "onStartMusic", root, mm55 ) 
end, 3000,1) 
    end 
) 

client:

local sound = { } 
  
addEvent( "onStartMusic", true ) 
addEventHandler( "onStartMusic", getRootElement(), 
function(vehicle) 
        if vehicle then 
            local x,y,z = getElementPosition(vehicle) 
            local d = getElementDimension(vehicle) 
            local i = getElementInterior(vehicle) 
            sound[vehicle] = playSound3D( "s.mp3", x, y, z, true) 
            attachElements(sound[vehicle],vehicle,0,0,0) 
            setSoundMaxDistance(sound[vehicle], 200) 
            setElementDimension(sound[vehicle], d) 
            setElementInterior(sound[vehicle], i) 
        end   
    end) 
  

Note: it won't be synced if someone else is joining since you are only trigging it for everyone in the server (root)

Link to comment
It won't trigger because the client side script isn't loaded yet, you can fix this by this:

server:

addEventHandler("onResourceStart",resourceRoot, 
    function () 
      mm55 = createVehicle(560, 1586.3, -1656.8, 28.6) 
setTimer ( function () 
triggerClientEvent ( "onStartMusic", root, mm55 ) 
end, 3000,1) 
    end 
) 

client:

local sound = { } 
  
addEvent( "onStartMusic", true ) 
addEventHandler( "onStartMusic", getRootElement(), 
function(vehicle) 
        if vehicle then 
            local x,y,z = getElementPosition(vehicle) 
            local d = getElementDimension(vehicle) 
            local i = getElementInterior(vehicle) 
            sound[vehicle] = playSound3D( "s.mp3", x, y, z, true) 
            attachElements(sound[vehicle],vehicle,0,0,0) 
            setSoundMaxDistance(sound[vehicle], 200) 
            setElementDimension(sound[vehicle], d) 
            setElementInterior(sound[vehicle], i) 
        end   
    end) 
  

Note: it won't be synced if someone else is joining since you are only trigging it for everyone in the server (root)

Thank you for helping me

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...