Jump to content

JoinSound


Adde

Recommended Posts

Posted

Hello, I made a script that play a sound on join and then stop it on login. The problem is that the sound don´t start, what´s wrong? Thankfull for answears :)

function playSoundOnJoin() 
    local sound = playSound("scary.mp3") 
    setSoundVolume(sound, 1) 
end 
addEventHandler("onPlayerJoin", root, playSoundOnJoin) 
  
function stopSoundOnLogin() 
stopSound(scary) 
end 
addEvent("stop", true) 
addEventHandler("onPlayerLogin", root, stopSoundOnLogin) 

btw, nothing in debug

My ingame nickname is: Mr.Snus

Posted

playSound is only client side, and your script is server side.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

I using it as client..

Okay, so like this?

client

addEventHandler( "onClientResourceStart", root, 
function () 
    local sound = playSound("scary.mp3") 
    setSoundVolume(sound, 1) 
    end 
) 
  
function stopSoundOnLogin() 
stopSound(sound) 
end 
addEvent("stop", true) 
addEventHandler("onPlayerLogin", root, stopSoundOnLogin) 

My ingame nickname is: Mr.Snus

Posted

-- Server

  
  
function stopSoundOnLogin() 
    triggerClientEvent(source,"stop",source) 
end 
addEventHandler("onPlayerLogin", root, stopSoundOnLogin) 
  
  

- Client

  
  
  
local sound 
  
addEventHandler( "onClientResourceStart", resourceRoot, 
function () 
      sound = playSound("scary.mp3") 
      setSoundVolume(sound, 1) 
    end 
) 
  
function stopSoundOnLogin() 
    if isElement(sound) then 
        stopSound(sound) 
    end  
end 
addEvent("stop", true) 
addEventHandler("stop", root, stopSoundOnLogin) 
  
  

Welcom to my server Q.5

Current game type in my server Drift

350x20_FFFFFF_FFFFFF_000000_000000.png

my Email : [email protected]

Programming level: 90%

  • 11 months later...
Posted

I know this topic is almost a year old, but my problem is similar to this (at least I searched before posting a new topic?)

Anyways, I'm completely new to Lua and am playing around with making a new RP server from scratch.

You actually taught me how to create and trigger events. Thanks!

I tried using what you have pasted and it does play, however, where you have:

addEventHandler("onPlayerLogin", root, stopSoundOnLogin) 

Mine is:

addEventHandler("spawnCharacter", root, stopSoundOnLogin) 

And it continues to play. I'm having trouble understanding this "addEventHandler" and such. I cannot count how many times i've read the wiki on this and it's like I'm reading Spanish.

If someone could explain this and maybe explain the difference of you putting root rather than getRootElement() or some of the others I see in the Wiki?

I have discovered that theirs no popcorn in popcorn chicken. I guess there’s no point in bothering with hash browns then.
Posted

root is just a shortcut for getRootElement ( ).

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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