Jump to content

Need help with attachElements


AlexWo

Recommended Posts

Hi guys I have a script where I can write "/placespeaker" a speaker get placed on the map and than some music starts playing.

But now I want to attach the music to a vehicle. The problem is I can't find the element for the music. :?

Server:

function createSpeaker(thePlayer) 
    local x, y, z = getElementPosition(thePlayer) 
    car = createVehicle(470, x, y, z-1) 
    speakerObject = createObject(2229, x, y, z-1) 
     attachElements ( speakerObject, car, 0, 0, 2 ) 
        outputChatBox("Succesfully created a speaker!", thePlayer, 0, 250, 0) 
    triggerClientEvent(root, "playTheSound", root, x, y, z) 
    attachElements( , speakerObject, 0, 0, 2 ) 
end 
addCommandHandler("placespeaker", createSpeaker) 
  
function deleteSpeaker(thePlayer) 
    if (isElement(speakerObject)) then 
        destroyElement(speakerObject) 
        outputChatBox("Succesfully destroyed", thePlayer, 0, 250, 0) 
                triggerClientEvent("stopTheSound", root) 
    else 
        outputChatBox("Object is not created.", thePlayer, 250, 0, 0) 
    end 
end 
addCommandHandler("destroyspeaker", deleteSpeaker) 

Client:

local url = "http://a.tumblr.com/tumblr_m316nasa2R1rnvv34o1_r1.mp3" 
  
function playTheSound(x, y, z) 
    sound = playSound3D(url, x, y, z) 
end 
addEvent("playTheSound", true) 
addEventHandler("playTheSound", root, playTheSound) 
  
function stopTheSound(x, y, z) 
    stopSound(sound) 
end 
addEvent("stopTheSound", true) 
addEventHandler("stopTheSound", root, stopTheSound) 

at the server-script side line no. 8 ... I don't know what the "SOUND" element is named.

Maybe you guys can help me.... :D

Xaiberalex

Link to comment

Well, you can create Collision Shape, attach it to vehicle, and when player hit the ColShape you can start play music.

UPDATE: Music element is only client-side. You can attach music client-side, but you are the only who will hear it.

So, use Colshape.

Link to comment
function createSpeaker(thePlayer) 
    local x, y, z = getElementPosition(thePlayer) 
    car = createVehicle(470, x, y, z-1) 
    speakerObject = createObject(2229, x, y, z-1) 
    attachElements(speakerObject, car, 0, 0, 2) 
    outputChatBox("Succesfully created a speaker!", thePlayer, 0, 250, 0) 
    triggerClientEvent(root, "playTheSound", root, x, y, z, speakerObject) 
end 
addCommandHandler("placespeaker", createSpeaker) 
  
function deleteSpeaker(thePlayer) 
    if (isElement(speakerObject)) then 
        destroyElement(speakerObject) 
        outputChatBox("Succesfully destroyed", thePlayer, 0, 250, 0) 
        triggerClientEvent("stopTheSound", root) 
    else 
        outputChatBox("Object is not created.", thePlayer, 250, 0, 0) 
    end 
end 
addCommandHandler("destroyspeaker", deleteSpeaker) 

local url = "http://a.tumblr.com/tumblr_m316nasa2R1rnvv34o1_r1.mp3" 
  
function playTheSound(x, y, z, object) 
    sound = playSound3D(url, x, y, z) 
    attachElements(sound, object) 
end 
addEvent("playTheSound", true) 
addEventHandler("playTheSound", root, playTheSound) 
  
function stopTheSound(x, y, z) 
    stopSound(sound) 
end 
addEvent("stopTheSound", true) 
addEventHandler("stopTheSound", root, stopTheSound) 

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...