SjoerdPSV Posted November 19, 2013 Share Posted November 19, 2013 Hello, Yesterday I downloaded a speaker script and I made some changes for the distance etc. But today I was thinking of a new option in the GUI to set the distance, so I added the an edit box to enter the distance for the speaker and tried some things in the script but it isn't working. What should I add? This is the whole client side: ------------------------------------------ -- Author: xXMADEXx -- -- Name: 3D Speakers 2.0 -- -- File: client.lua -- -- Copywrite 2013 ( C ) Braydon Davis -- ------------------------------------------ -- Decompile Security -- sec = {{{{{{},{},{},{}}}}}} -- ------------------------------ -- Variables -- ------------------------------ local subTrackOnSoundDown = 0.1 -- The volume that goes down, when the player clicks "Volume -" local subTrackOnSoundUp = 0.1 -- The volume that goes up, when the player clicks "Volume +" ------------------------------ -- The GUI -- ------------------------------ local rx, ry = guiGetScreenSize ( ) button = { } window = guiCreateWindow( ( rx - 295 ), ( ry / 2 - 253 / 2 ), 293, 313, "Speakers", false) guiWindowSetSizable(window, false) guiSetVisible ( window, false ) CurrentSpeaker = guiCreateLabel(8, 33, 254, 17, "Do you have a currently have a speaker: No", false, window) volume = guiCreateLabel(10, 50, 252, 17, "Current Volume: 100%", false, window) pos = guiCreateLabel(10, 66, 252, 15, "X: 0 | Y: 0 | Z: 0", false, window) guiCreateLabel(11, 81, 251, 15, "URL:", false, window) url = guiCreateEdit(11, 96, 272, 23, "", false, window) --url = guiCreateEdit(11, 96, 272, 23, "http://roscripts.netau.net/sound.mp3", false, window) -- (This link may not work, by the time you get the script) button["place"] = guiCreateButton(9, 129, 274, 20, "Create Speaker", false, window) button["remove"] = guiCreateButton(9, 159, 274, 20, "Destroy Speaker", false, window) button["v-"] = guiCreateButton(9, 189, 128, 20, "Volume -", false, window) button["v+"] = guiCreateButton(155, 189, 128, 20, "Volume +", false, window) button["close"] = guiCreateButton(9, 219, 274, 20, "Exit", false, window) guiCreateLabel(9, 249, 284, 20, "Reach:", false, window) reach = guiCreateEdit(11, 269, 284, 20, "", false, window) -------------------------- -- My sweet codes -- -------------------------- local isSound = false addEvent ( "onPlayerViewSpeakerManagment", true ) addEventHandler ( "onPlayerViewSpeakerManagment", root, function ( current ) local toState = not guiGetVisible ( window ) guiSetVisible ( window, toState ) showCursor ( toState ) if ( toState == true ) then guiSetInputMode ( "no_binds_when_editing" ) local x, y, z = getElementPosition ( localPlayer ) guiSetText ( pos, "X: "..math.floor ( x ).." | Y: "..math.floor ( y ).." | Z: "..math.floor ( z ) ) if ( current ) then guiSetText ( CurrentSpeaker, "Do you currently have a speaker: Yes" ) isSound = true else guiSetText ( CurrentSpeaker, "Do you currently have a speaker: No" ) end end end ) addEventHandler ( "onClientGUIClick", root, function ( ) if ( source == button["close"] ) then guiSetVisible ( window, false ) showCursor ( false ) elseif ( source == button["place"] ) then if ( isURL ( ) ) then triggerServerEvent ( "onPlayerPlaceSpeakerBox", localPlayer, guiGetText ( url ), isPedInVehicle ( localPlayer ) ) guiSetText ( CurrentSpeaker, "Do you currently have a speaker: Yes" ) isSound = true guiSetText ( volume, "Current Volume: 100%" ) else outputChatBox ( "You need to enter a URL.", 255, 0, 0 ) end elseif ( source == button["remove"] ) then triggerServerEvent ( "onPlayerDestroySpeakerBox", localPlayer ) guiSetText ( CurrentSpeaker, "Do you currently have a speaker: No" ) isSound = false guiSetText ( volume, "Current Volume: 100%" ) elseif ( source == button["v-"] ) then if ( isSound ) then local toVol = math.round ( getSoundVolume ( speakerSound [ localPlayer ] ) - subTrackOnSoundDown, 2 ) if ( toVol > 0.0 ) then outputChatBox ( "Volume set to "..math.floor ( toVol * 100 ).."%!", 0, 255, 0 ) triggerServerEvent ( "onPlayerChangeSpeakerBoxVolume", localPlayer, toVol ) guiSetText ( volume, "Current Volume: "..math.floor ( toVol * 100 ).."%" ) else outputChatBox ( "The volume cannot go any lower.", 255, 0, 0 ) end end elseif ( source == button["v+"] ) then if ( isSound ) then local toVol = math.round ( getSoundVolume ( speakerSound [ localPlayer ] ) + subTrackOnSoundUp, 2 ) if ( toVol < 1.1 ) then outputChatBox ( "Volume set to "..math.floor ( toVol * 100 ).."%!", 0, 255, 0 ) triggerServerEvent ( "onPlayerChangeSpeakerBoxVolume", localPlayer, toVol ) guiSetText ( volume, "Current Volume: "..math.floor ( toVol * 100 ).."%" ) else outputChatBox ( "The volume cannot go any higher.", 255, 0, 0 ) end end end end ) speakerSound = { } addEvent ( "onPlayerStartSpeakerBoxSound", true ) addEventHandler ( "onPlayerStartSpeakerBoxSound", root, function ( who, url, isCar ) if ( isElement ( speakerSound [ who ] ) ) then destroyElement ( speakerSound [ who ] ) end local x, y, z = getElementPosition ( who ) speakerSound [ who ] = playSound3D ( url, x, y, z, true ) setSoundVolume ( speakerSound [ who ], 1 ) setSoundMinDistance ( speakerSound [ who ], 13 ) setSoundMaxDistance ( speakerSound [ who ], reach ) local int = getElementInterior ( who ) setElementInterior ( speakerSound [ who ], int ) setElementDimension ( speakerSound [ who ], getElementDimension ( who ) ) if ( isCar ) then local car = getPedOccupiedVehicle ( who ) attachElements ( speakerSound [ who ], car, 0, 5, 1 ) end end ) addEvent ( "onPlayerDestroySpeakerBox", true ) addEventHandler ( "onPlayerDestroySpeakerBox", root, function ( who ) if ( isElement ( speakerSound [ who ] ) ) then destroyElement ( speakerSound [ who ] ) end end ) -------------------------- -- Volume -- -------------------------- addEvent ( "onPlayerChangeSpeakerBoxVolumeC", true ) addEventHandler ( "onPlayerChangeSpeakerBoxVolumeC", root, function ( who, vol ) if ( isElement ( speakerSound [ who ] ) ) then setSoundVolume ( speakerSound [ who ], tonumber ( vol ) ) end end ) function isURL ( ) if ( guiGetText ( url ) ~= "" ) then return true else return false end end function math.round(number, decimals, method) decimals = decimals or 0 local factor = 10 ^ decimals if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor else return tonumber(("%."..decimals.."f"):format(number)) end end And I changed some things in this part: addEvent ( "onPlayerStartSpeakerBoxSound", true ) addEventHandler ( "onPlayerStartSpeakerBoxSound", root, function ( who, url, isCar ) if ( isElement ( speakerSound [ who ] ) ) then destroyElement ( speakerSound [ who ] ) end local x, y, z = getElementPosition ( who ) speakerSound [ who ] = playSound3D ( url, x, y, z, true ) setSoundVolume ( speakerSound [ who ], 1 ) setSoundMinDistance ( speakerSound [ who ], 13 ) setSoundMaxDistance ( speakerSound [ who ], reach ) local int = getElementInterior ( who ) setElementInterior ( speakerSound [ who ], int ) setElementDimension ( speakerSound [ who ], getElementDimension ( who ) ) if ( isCar ) then local car = getPedOccupiedVehicle ( who ) attachElements ( speakerSound [ who ], car, 0, 5, 1 ) end end ) Link to comment
xXMADEXx Posted November 19, 2013 Share Posted November 19, 2013 All you need to do is create a new edit box, when the user clicks "Place Speaker" make a new argument in the triggerServerEvent with the sound level. In the server side, you need to place the sound argument in triggerClientEvent and then for setSoundMaxDistance, replace "reach" with the distance.. Sounds complicated, I know but it's very simple. 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