Jump to content

Play multiple sounds (Sound function)


MTA.Castiel

Recommended Posts

Hi there im working on a bit of code but i need a bit of guidance on this idea.

To keep things as short and simple, I was thinking of a way to play multiple sounds using a single function - "multi_sounds" instead of having to make another function for each of the sounds.

So all you'll need to do in this case is type /win cops or /win robbers and bob's your uncle.

I just need the barebones of how it should be done, so i can continue from there. I just can't figure out where to start.

We got client and server:

 

-- CLIENT

function cops()
 local sound = playSound("sirens.mp3")
  setSoundVolume(sound, 1)
  setSoundMaxDistance(sound, 100)
end
addEvent("playcops", true)
addEventHandler("playcops", getRootElement(), cops)

function robbers()
 local sound = playSound("gangsters.mp3")
  setSoundVolume(sound, 1)
  setSoundMaxDistance(sound, 100)
end
addEvent("playrobbers", true)
addEventHandler("playrobbers", getRootElement(), robbers)


-- SERVER

function multi_sounds ( player )

 --triggerClientEvent(player, "playcops", player)
 triggerClientEvent(player, "playrobbers", player)
end
addCommandHandler("win", multi_sounds)

 

 

Link to comment

hi you can try this but i didn't test it

--Client
addEvent("playWinSound", true)
addEventHandler("playWinSound", root,
    function(soundFile)
       local sound = playSound(soundFile) --play the sound file that comes as a parameter
       setSoundVolume(sound, 1)
       setSoundMaxDistance(sound, 100)
    end
)

--server
function multi_sounds(player, commandName, soundType)
   if not (soundType) then return outputChatBox("You must be enter sound type.", player) end --if the player has not entered the soundType, exit immediately
   if(soundType == "cops") then --if soundType is "cops" enter here
      triggerClientEvent(player, "playWinSound", player, "sirens.mp3")
   elseif(soundType == "robbers") then --if soundType is "robbers" enter here
      triggerClientEvent(player, "playWinSound", player, "gangsters.mp3")
   end
end
addCommandHandler("win", multi_sounds)
Edited by Burak5312
  • Thanks 1
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...