Xwad Posted July 26, 2015 Share Posted July 26, 2015 Hi i want to add a music to my spawn. I set that the music will start when i die and stop when i spawn but its not working:/ debugscript: WARNING: WW2/spawn/client.lua:98: Bad 'sound/player' pointer @ 'setSoundVolume'(1) part of the script: CLIENT.LUA --music function startSound (killer, weapon, bodypart) local sound = playSound("music/music.mp3") --Play wasted.mp3 from the sounds folder setSoundVolume(sound, 0.5) -- set the sound volume to 50% end addEventHandler("onClientPlayerWasted", getLocalPlayer(), startSound) --add the event handler function stopSound() stopSound("music.mp3") end addEventHandler("onClientPlayerSpawn", getLocalPlayer(), stopSound) --add the event handler Link to comment
vx89 Posted July 26, 2015 Share Posted July 26, 2015 (edited) you should use stopSound(sound) and make sound non local variable then (and your music/music.mp3 might not been added to meta.xml as client side file) Edited July 26, 2015 by Guest Link to comment
#RooTs Posted July 26, 2015 Share Posted July 26, 2015 use setTimer example setTimer(function() stopSound("music.mp3")................... Link to comment
#RooTs Posted July 26, 2015 Share Posted July 26, 2015 try this function wasted (killer, weapon, bodypart) -- Input the name of the function local sound = playSound("wasted.mp3") -- Play wasted.mp3 from the sounds folder setSoundVolume(sound, 1.0) -- set the sound volume to 50% end addEventHandler("onClientPlayerWasted", getLocalPlayer(), wasted) or addEventHandler( "onClientPlayerWasted", getLocalPlayer(), function() playSound("wasted.mp3") end) Link to comment
#RooTs Posted July 26, 2015 Share Posted July 26, 2015 Your code --music function startSound (killer, weapon, bodypart) local sound = playSound("music/music.mp3") --Play wasted.mp3 from the sounds folder setSoundVolume(sound, 0.5) -- set the sound volume to 50% end addEventHandler("onClientPlayerWasted", getLocalPlayer(), startSound) --add the event handler function stopSound() stopSound(sound) end addEventHandler("onClientPlayerSpawn", getLocalPlayer(), stopSound) --add the event handler Link to comment
GTX Posted July 27, 2015 Share Posted July 27, 2015 local sound function startSound (killer, weapon, bodypart) sound = playSound("music/music.mp3") setSoundVolume(sound, 0.5) end addEventHandler("onClientPlayerWasted", getLocalPlayer(), startSound) function destroySound() if isElement(sound) then stopSound(sound) end end addEventHandler("onClientPlayerSpawn", getLocalPlayer(), destroySound) Link to comment
Xwad Posted July 27, 2015 Author Share Posted July 27, 2015 still not working with the same debug:/ Maybe the problem is becaouse i have another background music? Link to comment
Miika Posted July 27, 2015 Share Posted July 27, 2015 local sound function startSound (killer, weapon, bodypart) sound = playSound("music/music.mp3", true) setSoundVolume(sound, 0.5) end addEventHandler("onClientPlayerWasted", getResourceRootElement(getThisResource()), startSound) function destroySound() if isElement(sound) then destroyElement(sound) end end addEventHandler("onClientPlayerSpawn", getResourceRootElement(getThisResource(), destroySound) Test it. Link to comment
Xwad Posted July 27, 2015 Author Share Posted July 27, 2015 wtf its the same debug again!!why is it not working? WARNING: WW2/spawn/client.lua:98: Bad 'sound/player' pointer @ 'setSoundVolume'(1) this is the full script maybe i did something wrong:// CLIENT.LUA classWnd = guiCreateWindow(185, 129, 479, 407, "Spawn Panel", false) guiWindowSetSizable(classWnd, false) guiSetVisible(classWnd, false) spawnG = guiCreateGridList(5, 27, 167, 160, false, classWnd) guiGridListAddColumn(spawnG, "Allies", 0.9) skins = { {"M4 Sherman", 287}, {"M26 Pershing (not available)", 171}, } for i,skins in ipairs(skins) do row = guiGridListAddRow(spawnG) guiGridListSetItemText(spawnG, row, 1, tostring(skins[1]), false, false) guiGridListSetItemData(spawnG, row, 1, tostring(skins[2])) end guiGridListAddRow(spawnG) spawnbtn = guiCreateButton(35, 200, 102, 44, "To battle!", false, classWnd) desc = guiCreateMemo(10, 260, 459, 140, "Welcome to World of Tanks MTA server! Choose your team!", false, classWnd) guiMemoSetReadOnly(desc, true) guiCreateLabel(166, 242, 136, 13, "Spawn Panel By Shaman", false, classWnd) function joinAllies() if ( source == spawnbtn ) then local row, col = guiGridListGetSelectedItem( spawnG ) local name = guiGridListGetItemText( spawnG, row, col ) if name == "M4 Sherman" then local id = 287 triggerServerEvent("spawn_sherman", getLocalPlayer(), id) guiSetVisible(classWnd, false) showCursor(false) elseif name == "M26 Pershing" then local id = 171 triggerServerEvent("spawn_pershing", getLocalPlayer(), id) guiSetVisible(classWnd, false) showCursor(false) end end end addEventHandler("onClientGUIClick",root,joinAllies) addEventHandler("onClientGUIClick",root,joinSurvivor) spawnG2 = guiCreateGridList(302, 27, 167, 160, false, classWnd) guiGridListAddColumn(spawnG2, "Axis", 0.9) skins = { {"Tiger I Ausf E", 270}, {"King Tiger II (not available)", 127}, } for i,skins in ipairs(skins) do row = guiGridListAddRow(spawnG2) guiGridListSetItemText(spawnG2, row, 1, tostring(skins[1]), false, false) guiGridListSetItemData(spawnG2, row, 1, tostring(skins[2])) end guiGridListAddRow(spawnG2) spawnbtn2 = guiCreateButton(330, 200, 102, 44, "To battle!", false, classWnd) function joinAxis() if ( source == spawnbtn2 ) then local row, col = guiGridListGetSelectedItem( spawnG2 ) local name = guiGridListGetItemText( spawnG2, row, col ) if name == "Tiger I Ausf E" then local id = 270 triggerServerEvent("spawn_tiger", getLocalPlayer(), id) guiSetVisible(classWnd, false) showCursor(false) elseif name == "King Tiger II" then local id = 127 triggerServerEvent("spawn_tiger2", getLocalPlayer(), id) guiSetVisible(classWnd, false) showCursor(false) end end end addEventHandler("onClientGUIClick",root,joinAxis) addEventHandler("onClientGUIClick",root,joinSwag) addEvent("showGUI", true) function guishow(player) guiSetVisible(classWnd, true) showCursor(true) sound = playSound("music/music.mp3") setSoundVolume(sound, 0.5) end addEventHandler("showGUI",getRootElement(),guishow) --music local sound function startSound (killer, weapon, bodypart) sound = playSound("music/music.mp3", true) setSoundVolume(sound, 0.5) end addEventHandler("onClientPlayerWasted", getResourceRootElement(getThisResource()), startSound) function destroySound() if isElement(sound) then destroyElement(sound) end end addEventHandler("onClientPlayerSpawn", getResourceRootElement(getThisResource(), destroySound) META.XML "WW2" author="Xwad" version="1.0" type="gamemode" /> Link to comment
KariiiM Posted July 27, 2015 Share Posted July 27, 2015 Check if the folder/file of the sounds is the same as in meta.xml Link to comment
KariiiM Posted July 27, 2015 Share Posted July 27, 2015 Well,try that i think i got your problem classWnd = guiCreateWindow(185, 129, 479, 407, "Spawn Panel", false) guiWindowSetSizable(classWnd, false) guiSetVisible(classWnd, false) spawnG = guiCreateGridList(5, 27, 167, 160, false, classWnd) guiGridListAddColumn(spawnG, "Allies", 0.9) skins = { {"M4 Sherman", 287}, {"M26 Pershing (not available)", 171}, } for i,skins in ipairs(skins) do row = guiGridListAddRow(spawnG) guiGridListSetItemText(spawnG, row, 1, tostring(skins[1]), false, false) guiGridListSetItemData(spawnG, row, 1, tostring(skins[2])) end guiGridListAddRow(spawnG) spawnbtn = guiCreateButton(35, 200, 102, 44, "To battle!", false, classWnd) desc = guiCreateMemo(10, 260, 459, 140, "Welcome to World of Tanks MTA server! Choose your team!", false, classWnd) guiMemoSetReadOnly(desc, true) guiCreateLabel(166, 242, 136, 13, "Spawn Panel By Shaman", false, classWnd) function joinAllies() if ( source == spawnbtn ) then local row, col = guiGridListGetSelectedItem( spawnG ) local name = guiGridListGetItemText( spawnG, row, col ) if name == "M4 Sherman" then local id = 287 triggerServerEvent("spawn_sherman", getLocalPlayer(), id) guiSetVisible(classWnd, false) showCursor(false) elseif name == "M26 Pershing" then local id = 171 triggerServerEvent("spawn_pershing", getLocalPlayer(), id) guiSetVisible(classWnd, false) showCursor(false) end end end addEventHandler("onClientGUIClick",root,joinAllies) addEventHandler("onClientGUIClick",root,joinSurvivor) spawnG2 = guiCreateGridList(302, 27, 167, 160, false, classWnd) guiGridListAddColumn(spawnG2, "Axis", 0.9) skins = { {"Tiger I Ausf E", 270}, {"King Tiger II (not available)", 127}, } for i,skins in ipairs(skins) do row = guiGridListAddRow(spawnG2) guiGridListSetItemText(spawnG2, row, 1, tostring(skins[1]), false, false) guiGridListSetItemData(spawnG2, row, 1, tostring(skins[2])) end guiGridListAddRow(spawnG2) spawnbtn2 = guiCreateButton(330, 200, 102, 44, "To battle!", false, classWnd) function joinAxis() if ( source == spawnbtn2 ) then local row, col = guiGridListGetSelectedItem( spawnG2 ) local name = guiGridListGetItemText( spawnG2, row, col ) if name == "Tiger I Ausf E" then local id = 270 triggerServerEvent("spawn_tiger", getLocalPlayer(), id) guiSetVisible(classWnd, false) showCursor(false) elseif name == "King Tiger II" then local id = 127 triggerServerEvent("spawn_tiger2", getLocalPlayer(), id) guiSetVisible(classWnd, false) showCursor(false) end end end addEventHandler("onClientGUIClick",root,joinAxis) addEventHandler("onClientGUIClick",root,joinSwag) addEvent("showGUI", true) function guishow(player) guiSetVisible(classWnd, true) showCursor(true) sound = playSound("music/music.mp3") setSoundVolume(sound, 0.5) end addEventHandler("showGUI",getRootElement(),guishow) --music function startSound (killer, weapon, bodypart) sound = playSound("music/music.mp3", true) setSoundVolume(sound, 0.5) end addEventHandler("onClientPlayerWasted", getResourceRootElement(getThisResource()), startSound) function destroySound() if isElement(sound) then destroyElement(sound) end end addEventHandler("onClientPlayerSpawn", getResourceRootElement(getThisResource(), destroySound) Link to comment
Xwad Posted July 27, 2015 Author Share Posted July 27, 2015 now the spawn scrpit is also not working ERROR? Server triggered clientside event showGUI, but event is not added toclientside Link to comment
KariiiM Posted July 27, 2015 Share Posted July 27, 2015 now the spawn scrpit is also not working ERROR? Server triggered clientside event showGUI, but event is not added toclientside Aw i just changed one line and its far of triggering..etc Link to comment
#RooTs Posted July 27, 2015 Share Posted July 27, 2015 In meta "Spawn/music/music.mp3" /> In LUA sound = playSound("Spawn/music/music.mp3", true) Your code in lua sound = playSound("music/music.mp3", true) add all folder as a path Link to comment
Xwad Posted July 27, 2015 Author Share Posted July 27, 2015 OMG!! You are right #RooTs! The problem was with the path lol. Tanks a lot! Anyway there is one more problem The music does not stop when i spawn:/ function stopSound() stopSound("sound") end addEventHandler("onClientPlayerSpawn", getLocalPlayer(), stopSound) --add the event handler Link to comment
#RooTs Posted July 27, 2015 Share Posted July 27, 2015 try this function stopSound() stopSound(sound) end addEventHandler("onClientPlayerSpawn", getLocalPlayer(), stopSound ) Link to comment
GTX Posted July 27, 2015 Share Posted July 27, 2015 That is stack overflow, can be seen from far. Set sound as global variable. function destroySound() stopSound(sound) end addEventHandler("onClientPlayerSpawn", getLocalPlayer(), destroySound ) Link to comment
#RooTs Posted July 27, 2015 Share Posted July 27, 2015 nope not working:( try this client.lua addEvent ("StopSound", true) addEventHandler ("StopSound", root,function() stopSound(sound) end) server.lua function SoundStoped () triggerClientEvent (source, "StopSound", source) end addEventHandler('onPlayerSpawn', root, SoundStoped) Link to comment
Xwad Posted July 27, 2015 Author Share Posted July 27, 2015 i tryd both but dont want to sop my god Link to comment
GTX Posted July 27, 2015 Share Posted July 27, 2015 local sound function startSound (killer, weapon, bodypart) sound = playSound("Spawn/music/music.mp3") setSoundVolume(sound, 0.5) end addEventHandler("onClientPlayerWasted", getLocalPlayer(), startSound) function destroySound() if isElement(sound) then stopSound(sound) end end addEventHandler("onClientPlayerSpawn", getLocalPlayer(), destroySound) Link to comment
#RooTs Posted July 27, 2015 Share Posted July 27, 2015 i tryd both but dont want to sop my god give-me your code, please Link to comment
Xwad Posted July 27, 2015 Author Share Posted July 27, 2015 Not working omg maybe i did something wrong? 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