Jump to content

attachElements not work!


Viudes

Recommended Posts

attachElement not work. i dont know how i can solve this :S

This clientside script is called by server root but still not work all player only who play music hear that

unction startMusicFinally(Playerx,Playery,Playerz,MusicLink,MusicPlayer)
		Vehicle = getPedOccupiedVehicle (localPlayer)
		if Vehicle then		
			stopSound(speakerSound [localPlayerName])
			speakerSound [localPlayerName]= playSound3D(MusicLink,Playerx,Playery,Playerz,true)
			attachElements(speakerSound [localPlayerName],Vehicle,0,0,0.5)
			attachTimer = setTimer(KeepSound,50,0)
		else
			stopSound(speakerSound [localPlayerName])
			speakerSound [localPlayerName]= playSound3D(MusicLink,Playerx,Playery,Playerz,true)
		end
	end
function KeepSound()
	attachElements(speakerSound [localPlayerName],Vehicle,0,0,0.5)
	end

 

Link to comment
  • Moderators

Wiki: https://wiki.multitheftauto.com/wiki/PlaySound3D

Creates a sound element in the GTA world and plays it immediately after creation for the local player. setElementPosition can be used to move the sound element around after it has been created. Remember to use setElementDimension after creating the sound to play it outside of dimension 0.

 

Possible solution:

local sound = playSound3D(MusicLink,Playerx,Playery,Playerz,true)
local customMusicElement = createElement("customSoundElement")
setElementParent(sound, customMusicElement)
setElementParent(customMusicElement, MusicPlayer)
addEventHandler("onClientRender", root,
function ()
      local customMusicElements = getElementsByType("customMusicElement", resourceRoot)
      for i=1, #customMusicElements do
          local customMusicElement = customMusicElements[i]
          local player = getElementParent(customMusicElement)
          if player then
              local soundElement = getElementChild(customMusicElement, 0)
              if soundElement then
                  local x, y, z = getElementPosition(player)
                  setElementPosition(soundElement, x, y, z)
              end
          end
      end
end)

It is a shame that not many people are using the element tree, since it saves you a lot table cleaning trouble.

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