SjoerdPSV Posted December 5, 2013 Share Posted December 5, 2013 (edited) Hello, I've got this speaker script: (Client:) ------------------------------------------ -- 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, 253, "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) -------------------------- -- 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 ) 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 function maxdistanceFunc(command, param) setSoundMaxDistance( speakerSound, tonumber(param)) end addCommandHandler("distance", maxdistanceFunc) (Didn't add the server script, because it's not necessary.) I want to set the MaxDistance with a command, so I added this at the bottom of the script: function maxdistanceFunc(command, param) setSoundMaxDistance( speakerSound, tonumber(param)) end addCommandHandler("distance", maxdistanceFunc) But it gives an error when I'm using /distance . I also tested it on an other script (with an other command) and in that script it works fine. SS of the error: Edited December 5, 2013 by Guest Link to comment
Enargy, Posted December 5, 2013 Share Posted December 5, 2013 ------------------------------------------ -- 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, 253, "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) -------------------------- -- 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 ) 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 function maxdistanceFunc(command, param) setSoundMaxDistance( speakerSound [ who ], tonumber(param)) end addCommandHandler("distance", maxdistanceFunc) Link to comment
SjoerdPSV Posted December 5, 2013 Author Share Posted December 5, 2013 ------------------------------------------ -- 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, 253, "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) -------------------------- -- 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 ) 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 function maxdistanceFunc(command, param) setSoundMaxDistance( speakerSound [ who ], tonumber(param)) end addCommandHandler("distance", maxdistanceFunc) Thanks for the quick response, but I still have the same error. Link to comment
SjoerdPSV Posted December 5, 2013 Author Share Posted December 5, 2013 I want to thank everyone for the help, I already fixed it. 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