madis Posted November 17, 2009 Share Posted November 17, 2009 Is it possible to attach playSound3D to vehicle? Idea would be that people would hear whatever player is listening in a vehicle (probably some song from server side selection of music). I have an idea to make a resource similar to Battlefield Vietnam (yeah, there is battlefield69 or something but it doesn't work with latest MTA and I actually want to do it myself - which probably means I'll never get it done). Link to comment
50p Posted November 17, 2009 Share Posted November 17, 2009 You can't stream music from other vehicles' radio channel to other players... playSound3D plays sound file not radio. If you want to attach some sound (sound file you added to your resource) then use these: - onClientRender or onClientPreRender - to get vehicle's position and set the sound position to vehicle's position every frame - getElementPosition - to get vehicle's position - setElementPosition - to set sound position to where the vehicle is (coordinates returned from getElementPosition) Link to comment
madis Posted November 17, 2009 Author Share Posted November 17, 2009 Thank you, 50p, for the quick answer! Link to comment
madis Posted November 17, 2009 Author Share Posted November 17, 2009 Another question, maybe a bit off topic, but needed for the same reason... What is the best method to get a race spawnpoint element via lua script (by what I actually mean the moving vehicle) which is defined in .map? Edit: Oh I guess I found it https://wiki.multitheftauto.com/wiki/Writing_Gamemodes -- retrieve a table with all flag elementslocal flagElements = getElementsByType ( "flag" ) -- loop through them for key, value in pairs(flagElements) do -- get our info local posX = getElementData ( value, "posX" ) local posY = getElementData ( value, "posY" ) local posZ = getElementData ( value, "posZ" ) local team = getElementData ( value, "team" ) -- create an object according to the flag position createObject ( 1337, posX, posY, posZ ) -- output the team that we created a base for outputChatBox ( "Base for team " .. team .. " created" ) end EDIT2: Mhm, yeah, of course, the spawnpoint itself isn't updated, so I need to get the vehicle or ped (player) position instead. Any help on that ? Link to comment
eAi Posted November 18, 2009 Share Posted November 18, 2009 getElementsByType("vehicle") will give you all the vehicles (even ones without players in). getElementsByType("player") will give you all the players, from them you can get which vehicle they are in using getPedOccupiedVehicle. Link to comment
madis Posted November 18, 2009 Author Share Posted November 18, 2009 Thanks for the reply. Also, I guess this is a good place to also use the collision functions, as audio isn't heared to unlimited area anyway. Link to comment
50p Posted November 18, 2009 Share Posted November 18, 2009 Thanks for the reply.Also, I guess this is a good place to also use the collision functions, as audio isn't heared to unlimited area anyway. It's not, but it can be, https://wiki.multitheftauto.com/wiki/SetSoundMaxDistance Unless, there is a limit which I don't know of. Link to comment
madis Posted November 18, 2009 Author Share Posted November 18, 2009 Yes, with highering SetSoundMaxDistance and SetSoundMinDistance values, the audio can be heared to greater distance. I usually don't like to ask too much... but still, I just haven't figured out following. I've implemented a song selector for players when they are in vehicles. Now, there are two possibilities, as eAi pointed out, I could check vehicles or players. I would actually prefer vehicles - which means: Every player can set a musicfile playing in his/her vehicle and optionally leave it playing when leaving vehicle (by default this would be off, though) - which means that every vehicle needs to be checked, instead of players and their vehicles. So, I have this: 1) On every frame, play3DSound element needs to be repositioned, so it follows a vehicle. This is done by clientside script: function reposition3DSound(soundSource, x, y, z) setElementPosition(soundSource, x, y, z) end function vehiclesWithDriver() -- getElementsWithinColShape might be better in future local vehicles = getElementsByType("vehicle") for theKey, aVehicle in ipairs(vehicles) do vehicleOccupant = getVehicleOccupant(aVehicle, 0) -- if someone is driving the vehicle if vehicleOccupant then local songId = getElementData(playerVehicle, "song_id") local songPosition = getElementData(playerVehicle, "song_pos") if songId then local x, y, z = getElementPosition(aVehicle) reposition3DSound(musicSound, x, y, z) end end end end addEventHandler("onClientRender", root, function() vehiclesWithDriver() end ) It's a bit messy code... When a client is in vehicle and starts a song, it will set element data for that vehicle setElementData(playerVehicle, "song_id", "a") setElementData(playerVehicle, "song_pos", false) where, song_id is the song I'm playing (in this example "a" and song_pos is the seeking position of song (so that it would be synced) Okay, I can't understand my post either... well my problem is: How should/could I sync the playing sound, so that when someone starts a song for a vehicle, others would hear it, included players who join the server when the song is already playing. One of the problems is that in one case I need to initialize the sound and later on update the position. EDIT: nvm, I guess I've figured it out... I'll get back when it's done. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now