Jump to content

PlaySound does not work??


Fabio(GNR)

Recommended Posts

I want to create a script that plays sound when enters marker and stops when enters another marker, i finished the start script, but idk whats wrong? when i enter the marker nothing happens, no errors on debugscript, en btw when i accidentally used script as server :) it said nil value cause it was server but it does detect the marker, but doesnt play the sound, btw the sound is pretty big, a bit less then 10 mb :D code:

function soundclub(hitElement, matchingDimension) 
    local sound = playSound("club.mp3")  
    setSoundVolume(sound, 0.6)  
end 
  
local myMarker2 = createMarker ( 48.590377807617,2252.8537597656,270.80096948242, "arrow", 1.0, 120, 255, 0, 170 )  
addEventHandler("onMarkerHit", myMarker2, soundclub) 
  

Meta:

<meta> 
    <info author="aa" version="1.0" type="misc" name="sound" description="Play's sound" /> 
    <script src="Untitled 1.lua" type="client" /> 
        <file src="club.mp3" /> 
</meta> 

Link to comment
Are you sure the sound path is OK? And do you see the marker above the ground, right?

Yes, i put the sound file in the resource root folder, so example: sound.mp3 (if it was a mp3) but it doesn't play, yes. cause it detects marker too. Thanks for responding :P

EDIT:

onMarkerHit is server side event..

Use onClientMarkerHit instead..

I hope you know the difference between server and client side.. because In that the sound won't be synchronised

Srry didn't see your post, ill try that it will work i think xD

EDIT2: Thanks it worked, varez thi is like the tenth time you helped me out ;) Thanks alot!!

EDIT3: 1 more thing :D now when i walk trough the marker the sound get played over the other, is there any way to let it know its still playing? And making it available when its done?

Link to comment
There is no way to check if sound is already playing. If MTA Devs accepted my patch, you'd be able to detect when the sound has stopped or started playing. Currently, there is no way to check if sound is being played.

your patch?? :o

  
isPlaying = false 
function soundclub(hitElement, matchingDimension) 
  if not isPlaying then 
    isPlaying=true 
    stopSound(sound) 
    local sound = playSound("club.mp3")  
    setSoundVolume(sound, 0.6) 
    setTimer(function() isPlaying=false end, 32500, 1) 
  end 
end 
  

like that

Thanks i'll try :D btw does the /lua code thing still works??? Thanks

EDIT: it didn't work ill try debugscript now....

Edited by Guest
Link to comment
what??

Thanks i'll try :D btw does the /lua code thing still works??? Thanks

EDIT: it didn't work ill try debugscript now....

the sound, when i walk trough the second time it starts a new one but doesn't stop the old one so two are playing at the same time....can't we try this with a command instead of marker and then make the command avaible after the lenght?

Link to comment
And My solution is not working?

No, well maybe its me but i tested it first with marker now i changed to command, maybe i broke something:

  
function soundclub (playerSource) 
    local sound = playSound("club.mp3",true)  
    setSoundVolume(sound, 0.7)  
end 
 addCommandHandler ( "clubstart", soundclub )  
  
isPlaying = false 
function soundclub(playerSource) 
  if not isPlaying then 
    isPlaying=true 
    stopSound (sound) 
    local sound = playSound("club.mp3") 
    setSoundVolume(sound, 0.7) 
    setTimer(function() isPlaying=false end, 600000, 1) 
  end 
end 

Link to comment

hmm

there isnt needed for command..

just, make it like varez sayd

  
local isPlaying = false -- hmm, dont know is local needed, but i think it is? 
  
local myMarker2 = createMarker ( 48.590377807617,2252.8537597656,270.80096948242, "arrow", 1.0, 120, 255, 0, 170 ) 
  
function soundclub(hitElement, matchingDimension) 
    if not isPlaying then 
     isPlaying=true 
     stopSound(sound) 
     local sound = playSound("club.mp3") 
     setSoundVolume(sound, 0.6) 
     setTimer(function() isPlaying=false end, 32500, 1) 
   end 
 end   
addEventHandler("onMarkerHit", myMarker2, soundclub) 
  

Link to comment

thanks varez, and CowTurbo will try now :D

EDIT: it worked :D Great!! But can i ask one more question how to make a command to make it stop? :D The one on the wiki doesn't work/explain :/ Thanks really thanks!!

btw: stop what i have so far:

function stopclub (playerSource) 
    stopSound("club.mp3")  
end 
addCommandHandler ( "clubstop", stopclub )  

Link to comment
thanks varez, and CowTurbo will try now :D

EDIT: it worked :D Great!! But can i ask one more question how to make a command to make it stop? :D The one on the wiki doesn't work/explain :/ Thanks really thanks!!

btw: stop what i have so far:

function stopclub (playerSource) 
    stopSound("club.mp3")  
end 
addCommandHandler ( "clubstop", stopclub )  

try,

function stopclub () 
    stopSound(sound)  
end 
addCommandHandler ( "clubstop", stopclub )  

Link to comment
thanks varez, and CowTurbo will try now :D

EDIT: it worked :D Great!! But can i ask one more question how to make a command to make it stop? :D The one on the wiki doesn't work/explain :/ Thanks really thanks!!

btw: stop what i have so far:

function stopclub (playerSource) 
    stopSound("club.mp3")  
end 
addCommandHandler ( "clubstop", stopclub )  

try,

function stopclub () 
    stopSound(sound)  
end 
addCommandHandler ( "clubstop", stopclub )  

ok ill try :D

EDIT:

Also Remove "local" from line 10 of cowturbo snippet

No i used the command, thing not his :D

varez, thanks again :D it worked by deleting local :P:P:P:P You are really helpful

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