Jump to content

Music scrtipt not working!


Xwad

Recommended Posts

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

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

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

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

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

OMG!! You are right #RooTs! The problem was with the path lol. Tanks a lot! Anyway there is one more problem xD The music does not stop when i spawn:/

  
function stopSound() 
    stopSound("sound") 
end 
addEventHandler("onClientPlayerSpawn", getLocalPlayer(), stopSound) --add the event handler 
  

Link to comment

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

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