28WL Posted February 9, 2014 Share Posted February 9, 2014 Help me, please. How to make: A) If you click on the button, sound starts playing, you hear it. B) If you click on the button again, that sound stops in directed time (for example in 10 seconds). ...buttons mark, unmark functions and other things (from login.lua DayZ). function clickPanelButton(button, state) if button == "left" and state == "up" then local element = getElementData(getLocalPlayer(), "clickedButton") if element then local info = getElementData(element, "info") if info and info == "login" then do local username = guiGetText(Login_Edit[1]) local password = guiGetText(Login_Edit[2]) if tostring(username) ~= "" and tostring(password) ~= "" then triggerServerEvent("onClientSendLoginDataToServer", getLocalPlayer(), username, password) else reason = "Missing Password or Username." outputChatBox("[Login]:#FF9900 " .. reason, 255, 255, 255, true) end end elseif info and info == "intro" then do playSound("Sounds/Intro.mp3") end elseif info and info == "guest" then showLoginWindow(false) elseif info and info == "register" then local username = guiGetText(Login_Edit[3]) local pass1 = guiGetText(Login_Edit[4]) local pass2 = guiGetText(Login_Edit[5]) if tostring(username) ~= "" then if tostring(pass1) ~= "" then if pass1 == pass2 then triggerServerEvent("onClientSendRegisterDataToServer", getLocalPlayer(), username, pass1) else reason = "Passwords not match." outputChatBox("[Register]:#FF9900 " .. reason, 255, 255, 255, true) end else reason = "No password was entered." outputChatBox("[Register]:#FF9900 " .. reason, 255, 255, 255, true) end else reason = "No username was entered." outputChatBox("[Register]:#FF9900 " .. reason, 255, 255, 255, true) end end end end end addEventHandler("onClientClick", getRootElement(), clickPanelButton) ...other scripts, functions. Link to comment
myonlake Posted February 9, 2014 Share Posted February 9, 2014 You can use setTimer to delay the stop. You can use variables to define whether the timer is running and if the sound is playing, this way you won't get issues with multiple sounds and multiple timers and such. You can use the code below. local secondsToWait = 10 local soundElement, soundTimer function clickPanelButton(button, state) if (button == "left") and (state == "up") then local element = getElementData(localPlayer, "clickedButton") if (element) then local info = getElementData(element, "info") if (info) then if (info == "login") then local username = guiGetText(Login_Edit[1]) local password = guiGetText(Login_Edit[2]) if (tostring(username) ~= "") and (tostring(password) ~= "") then triggerServerEvent("onClientSendLoginDataToServer", localPlayer, username, password) else reason = "Missing password or username." outputChatBox("[Login]:#FF9900 " .. reason, 255, 255, 255, true) end elseif (info == "intro") then if (not soundElement) then -- If there is no sound playing yet soundElement = playSound("Sounds/Intro.mp3") -- Define and play the sound else if (not soundTimer) then -- If there is no timer yet soundTimer = setTimer(function() -- Create a new timer if (isElement(soundElement)) then -- Check if the sound exists destroyElement(soundElement) -- Destroy the sound soundElement, soundTimer = nil -- Reset the variables end end, secondsToWait*1000, 1) -- Wait for the amount of seconds defined in 'secondsToWait' end end elseif (info == "guest") then showLoginWindow(false) elseif (info == "register") then local username = guiGetText(Login_Edit[3]) local pass1 = guiGetText(Login_Edit[4]) local pass2 = guiGetText(Login_Edit[5]) if (tostring(username) ~= "") then if (tostring(pass1) ~= "") then if (pass1 == pass2) then triggerServerEvent("onClientSendRegisterDataToServer", localPlayer, username, pass1) else reason = "Passwords don't match." outputChatBox("[Register]:#FF9900 " .. reason, 255, 255, 255, true) end else reason = "No password was entered." outputChatBox("[Register]:#FF9900 " .. reason, 255, 255, 255, true) end else reason = "No username was entered." outputChatBox("[Register]:#FF9900 " .. reason, 255, 255, 255, true) end end end end end end addEventHandler("onClientClick", root, clickPanelButton) By the way, you had some unnecessary do statements there, you don't need those, I doubt it would even work since you need some form of loop to even use do statement in the first place. Link to comment
Damien_Teh_Demon Posted February 11, 2014 Share Posted February 11, 2014 Put the stop sound code you would normally use, but in a timer like this setTimer(function() --code here end, 1000, 1) the 1000 is delay, the 1 is how many times Link to comment
myonlake Posted February 11, 2014 Share Posted February 11, 2014 Do you mind checking /debugscript 3 for any possible errors and post them in here. That's the only way we know what's wrong. Link to comment
28WL Posted February 23, 2014 Author Share Posted February 23, 2014 Hmmm... I was thinking about that, but no. Well, now I don't need that help, because +1 more button at the login panel fucks all beautiful view. How it should look like: decreasing sound's voice in 5 seconds and then stopping it 100%? Server: addCommandHandler ( "playsound1", function ( play_sound_1 ) if isAccountInGroup ( { "Super Admin", "Admin" }, getAccountName ( getPlayerAccount ( play_sound_1 ) ) ) then setTimer ( triggerClientEvent, 1000, 1, "play_sound_1", root, "sounds/sound_1.mp3" ) else outputChatBox ("` You have no acces to that command.", play_sound_1 ) end end ) function isAccountInGroup ( groups, account ) local theGroup = false for _, group in ipairs ( groups ) do if isObjectInACLGroup ( "user.".. account, aclGetGroup ( group ) ) then theGroup = group break end end return theGroup end Client: addEvent ( "play_sound_1", true ) addEventHandler ( "play_sound_1", root, function ( path1 ) playSound ( path1 ) end ) 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