~Gangsta~ Posted September 28, 2013 Share Posted September 28, 2013 I do not understand why the music does not stop please help me, I wanted to do this radio for cars client gMe = getLocalPlayer(); gRoot = getRootElement(); gResRoot = getResourceRootElement( getThisResource () ); btn = {}; ipodCoor = { moving={}, pos={} }; addEvent( "clientReceiveMusicTable", true ); local sound = {} addEventHandler( "onClientResourceStart", gResRoot, function () outputChatBox( "Press 'i' to open your iPod", 0, 255, 0 ); ipod = guiCreateStaticImage( 1.0, 0.2279, 0.1916, 0.4036, "ipod.png", true ); --0.7744 ipodCoor.moving[ipod] = false; ipodCoor.pos[ipod] = "out"; songDisplay = guiCreateGridList( 0.0671, 0.0245, 0.8504, 0.4663, true, ipod ); btn[1] = guiCreateButton( 0.64, 0.67, 0.15, 0.05, "Abspielen", true, ipod ); btn[2] = guiCreateButton( 0.185, 0.67, 0.15, 0.05, "Stop", true, ipod ); btn[3] = guiCreateButton( 0.42, 0.825, 0.15, 0.05, "vD", true, ipod ); btn[4] = guiCreateButton( 0.42, 0.525, 0.15, 0.05, "vU", true, ipod ); for i=1,4 do guiSetAlpha( btn[i], 1.0 ); guiSetFont( btn[i], "default-small" ); end; songList = guiGridListAddColumn( songDisplay, "My Songs", 0.85 ); triggerServerEvent( "serverLoadMusicTable", gMe ); addEventHandler( "onClientGUIClick", gRoot, function () local theVehicle = getPedOccupiedVehicle ( gMe ) if source == btn[1] then local selSong = guiGridListGetItemData( songDisplay, guiGridListGetSelectedItem( songDisplay ) ); if selSong then if not sound then triggerServerEvent ( "createSound", root, selSong, theVehicle) else stopSound( sound); triggerServerEvent ( "createSound", root, selSong, theVehicle) end; end; elseif source == btn[2] then if sound then stopSound( sound); sound = nil; end; elseif source == btn[4] then if music then setSoundVolume( music, getSoundVolume( music ) + 0.25 ); if getSoundVolume( music ) > 1 then setSoundVolume( music, 1 ); end; end; elseif source == btn[3] then if music then setSoundVolume( music, getSoundVolume( music ) - 0.25 ); if getSoundVolume( music ) < 0 then setSoundVolume( music, 0 ); end; end; end; end ) bindKey( "i", "down", function () if ipodCoor.moving[ipod] == false then if ipodCoor.pos[ipod] == "out" then showCursor( true, false ); ipodCoor.moving[ipod] = true; addEventHandler( "onClientRender", gRoot, openIPod ); toggleControl( "fire", false ); else showCursor( false, false ); ipodCoor.moving[ipod] = true; addEventHandler( "onClientRender", gRoot, closeIPod ); toggleControl( "fire", true ); end; end; end ) end ) function openIPod() local x, y = guiGetPosition( ipod, true ); guiSetPosition( ipod, x - 0.01, y, true ); if x < 0.775 then ipodCoor.moving[ipod] = false; ipodCoor.pos[ipod] = "in"; removeEventHandler( "onClientRender", gRoot, openIPod ); end; end; function closeIPod() local x, y = guiGetPosition( ipod, true ); guiSetPosition( ipod, x + 0.01, y, true ); if x > 1.0 then guiSetPosition( ipod, 1.0, y, true ); ipodCoor.moving[ipod] = false; ipodCoor.pos[ipod] = "out"; removeEventHandler( "onClientRender", gRoot, closeIPod ); end; end; addEventHandler( "clientReceiveMusicTable", gRoot, function ( mTable ) if mTable == nil then triggerServerEvent( "serverLoadMusicTable", gMe ); else for _, v in ipairs ( mTable ) do local row = guiGridListAddRow( songDisplay ); local streamtable = split(v, ';') guiGridListSetItemText( songDisplay, row, 1, streamtable[2], false, false ); guiGridListSetItemData ( songDisplay, row, 1, streamtable[1]); outputChatBox(streamtable[2].." has ben added to your ipod", getLocalPlayer()); end; guiGridListAutoSizeColumn( songDisplay, 1 ); guiBringToFront( songDisplay ); end; end ) addEvent ( "createSoundClient", true ) addEventHandler ( "createSoundClient", root, function ( id, theVehicle ) local x, y, z = getElementPosition(theVehicle) local sound = playSound3D(id, x, y, z ) attachElements ( sound, theVehicle ) end ) server local gRoot = getRootElement(); addEvent( "serverLoadMusicTable", true ); addEventHandler( "serverLoadMusicTable", gRoot, function () local res, mTable, xml = getThisResource(), {}, xmlLoadFile( "meta.xml", res ); local nameTable = {} if xml then local i = 0; while ( xmlFindChild( xml, "stream", i ) ) do local dir = xmlNodeGetAttribute( xmlFindChild( xml, "stream", i ), "url" ); local streamname = xmlNodeGetAttribute( xmlFindChild( xml, "stream", i ), "name" ); table.insert( mTable, dir..";"..streamname ); i = i + 1; end; end; triggerClientEvent( source, "clientReceiveMusicTable", gRoot, mTable ); end ) addEvent ( "createSound", true ) addEventHandler ( "createSound", root, function ( id, theVehicle) if ( theVehicle ) then triggerClientEvent(root, "createSoundClient", root, id, theVehicle) end end ) Link to comment
Castillo Posted September 28, 2013 Share Posted September 28, 2013 That's because you made your 'sound' variable local, so it won't exist outside of that function. local sound = playSound3D(id, x, y, z ) All you have to do is remove the 'local' infront of it. Link to comment
~Gangsta~ Posted September 29, 2013 Author Share Posted September 29, 2013 not work gMe = getLocalPlayer(); gRoot = getRootElement(); gResRoot = getResourceRootElement( getThisResource () ); btn = {}; ipodCoor = { moving={}, pos={} }; addEvent( "clientReceiveMusicTable", true ); local sound = {} addEventHandler( "onClientResourceStart", gResRoot, function () outputChatBox( "Press 'i' to open your iPod", 0, 255, 0 ); ipod = guiCreateStaticImage( 1.0, 0.2279, 0.1916, 0.4036, "ipod.png", true ); --0.7744 ipodCoor.moving[ipod] = false; ipodCoor.pos[ipod] = "out"; songDisplay = guiCreateGridList( 0.0671, 0.0245, 0.8504, 0.4663, true, ipod ); btn[1] = guiCreateButton( 0.64, 0.67, 0.15, 0.05, "Abspielen", true, ipod ); btn[2] = guiCreateButton( 0.185, 0.67, 0.15, 0.05, "Stop", true, ipod ); btn[3] = guiCreateButton( 0.42, 0.825, 0.15, 0.05, "vD", true, ipod ); btn[4] = guiCreateButton( 0.42, 0.525, 0.15, 0.05, "vU", true, ipod ); for i=1,4 do guiSetAlpha( btn[i], 1.0 ); guiSetFont( btn[i], "default-small" ); end; songList = guiGridListAddColumn( songDisplay, "My Songs", 0.85 ); triggerServerEvent( "serverLoadMusicTable", gMe ); addEventHandler( "onClientGUIClick", gRoot, function () local theVehicle = getPedOccupiedVehicle ( gMe ) if source == btn[1] then local selSong = guiGridListGetItemData( songDisplay, guiGridListGetSelectedItem( songDisplay ) ); if selSong then if not sound then triggerServerEvent ( "createSound", root, selSong, theVehicle) else stopSound(sound); triggerServerEvent ( "createSound", root, selSong, theVehicle) end; end; elseif source == btn[2] then if sound then stopSound(sound); sound = nil; end; elseif source == btn[4] then if music then setSoundVolume( music, getSoundVolume( music ) + 0.25 ); if getSoundVolume( music ) > 1 then setSoundVolume( music, 1 ); end; end; elseif source == btn[3] then if music then setSoundVolume( music, getSoundVolume( music ) - 0.25 ); if getSoundVolume( music ) < 0 then setSoundVolume( music, 0 ); end; end; end; end ) bindKey( "i", "down", function () if ipodCoor.moving[ipod] == false then if ipodCoor.pos[ipod] == "out" then showCursor( true, false ); ipodCoor.moving[ipod] = true; addEventHandler( "onClientRender", gRoot, openIPod ); toggleControl( "fire", false ); else showCursor( false, false ); ipodCoor.moving[ipod] = true; addEventHandler( "onClientRender", gRoot, closeIPod ); toggleControl( "fire", true ); end; end; end ) end ) function openIPod() local x, y = guiGetPosition( ipod, true ); guiSetPosition( ipod, x - 0.01, y, true ); if x < 0.775 then ipodCoor.moving[ipod] = false; ipodCoor.pos[ipod] = "in"; removeEventHandler( "onClientRender", gRoot, openIPod ); end; end; function closeIPod() local x, y = guiGetPosition( ipod, true ); guiSetPosition( ipod, x + 0.01, y, true ); if x > 1.0 then guiSetPosition( ipod, 1.0, y, true ); ipodCoor.moving[ipod] = false; ipodCoor.pos[ipod] = "out"; removeEventHandler( "onClientRender", gRoot, closeIPod ); end; end; addEventHandler( "clientReceiveMusicTable", gRoot, function ( mTable ) if mTable == nil then triggerServerEvent( "serverLoadMusicTable", gMe ); else for _, v in ipairs ( mTable ) do local row = guiGridListAddRow( songDisplay ); local streamtable = split(v, ';') guiGridListSetItemText( songDisplay, row, 1, streamtable[2], false, false ); guiGridListSetItemData ( songDisplay, row, 1, streamtable[1]); outputChatBox(streamtable[2].." has ben added to your ipod", getLocalPlayer()); end; guiGridListAutoSizeColumn( songDisplay, 1 ); guiBringToFront( songDisplay ); end; end ) addEvent ( "createSoundClient", true ) addEventHandler ( "createSoundClient", root, function ( id, theVehicle ) local x, y, z = getElementPosition(theVehicle) sound = playSound3D(id, x, y, z ) attachElements ( sound, theVehicle ) end ) WARNING:ipod\ipod_c.lua:43:Bad argument @ 'stopSound' [Expected sound at argument 1, got table] Link to comment
K4stic Posted September 29, 2013 Share Posted September 29, 2013 try use destroyElement(sound) [some times work better than stopSound] Link to comment
~Gangsta~ Posted September 29, 2013 Author Share Posted September 29, 2013 And why when the player presses the stop and I still hear the music and he did not Link to comment
K4stic Posted September 29, 2013 Share Posted September 29, 2013 Try This: gMe = getLocalPlayer(); gRoot = getRootElement(); gResRoot = getResourceRootElement( getThisResource () ); btn = {}; ipodCoor = { moving={}, pos={} }; addEvent( "clientReceiveMusicTable", true ); local sound = {} addEventHandler( "onClientResourceStart", gResRoot, function () outputChatBox( "Press 'i' to open your iPod", 0, 255, 0 ); ipod = guiCreateStaticImage( 1.0, 0.2279, 0.1916, 0.4036, "ipod.png", true ); --0.7744 ipodCoor.moving[ipod] = false; ipodCoor.pos[ipod] = "out"; songDisplay = guiCreateGridList( 0.0671, 0.0245, 0.8504, 0.4663, true, ipod ); btn[1] = guiCreateButton( 0.64, 0.67, 0.15, 0.05, "Abspielen", true, ipod ); btn[2] = guiCreateButton( 0.185, 0.67, 0.15, 0.05, "Stop", true, ipod ); btn[3] = guiCreateButton( 0.42, 0.825, 0.15, 0.05, "vD", true, ipod ); btn[4] = guiCreateButton( 0.42, 0.525, 0.15, 0.05, "vU", true, ipod ); for i=1,4 do guiSetAlpha( btn[i], 1.0 ); guiSetFont( btn[i], "default-small" ); end; songList = guiGridListAddColumn( songDisplay, "My Songs", 0.85 ); triggerServerEvent( "serverLoadMusicTable", gMe ); addEventHandler( "onClientGUIClick", gRoot, function () local theVehicle = getPedOccupiedVehicle ( gMe ) if source == btn[1] then local selSong = guiGridListGetItemData( songDisplay, guiGridListGetSelectedItem( songDisplay ) ); if selSong then if not sound then triggerServerEvent ( "createSound", root, selSong, theVehicle) else stopSound(sound[source]); triggerServerEvent ( "createSound", root, selSong, theVehicle) end; end; elseif source == btn[2] then if sound then stopSound(sound[source]); sound = nil; end; elseif source == btn[4] then if music then setSoundVolume( music, getSoundVolume( music ) + 0.25 ); if getSoundVolume( music ) > 1 then setSoundVolume( music, 1 ); end; end; elseif source == btn[3] then if music then setSoundVolume( music, getSoundVolume( music ) - 0.25 ); if getSoundVolume( music ) < 0 then setSoundVolume( music, 0 ); end; end; end; end ) bindKey( "i", "down", function () if ipodCoor.moving[ipod] == false then if ipodCoor.pos[ipod] == "out" then showCursor( true, false ); ipodCoor.moving[ipod] = true; addEventHandler( "onClientRender", gRoot, openIPod ); toggleControl( "fire", false ); else showCursor( false, false ); ipodCoor.moving[ipod] = true; addEventHandler( "onClientRender", gRoot, closeIPod ); toggleControl( "fire", true ); end; end; end ) end ) function openIPod() local x, y = guiGetPosition( ipod, true ); guiSetPosition( ipod, x - 0.01, y, true ); if x < 0.775 then ipodCoor.moving[ipod] = false; ipodCoor.pos[ipod] = "in"; removeEventHandler( "onClientRender", gRoot, openIPod ); end; end; function closeIPod() local x, y = guiGetPosition( ipod, true ); guiSetPosition( ipod, x + 0.01, y, true ); if x > 1.0 then guiSetPosition( ipod, 1.0, y, true ); ipodCoor.moving[ipod] = false; ipodCoor.pos[ipod] = "out"; removeEventHandler( "onClientRender", gRoot, closeIPod ); end; end; addEventHandler( "clientReceiveMusicTable", gRoot, function ( mTable ) if mTable == nil then triggerServerEvent( "serverLoadMusicTable", gMe ); else for _, v in ipairs ( mTable ) do local row = guiGridListAddRow( songDisplay ); local streamtable = split(v, ';') guiGridListSetItemText( songDisplay, row, 1, streamtable[2], false, false ); guiGridListSetItemData ( songDisplay, row, 1, streamtable[1]); outputChatBox(streamtable[2].." has ben added to your ipod", getLocalPlayer()); end; guiGridListAutoSizeColumn( songDisplay, 1 ); guiBringToFront( songDisplay ); end; end ) addEvent ( "createSoundClient", true ) addEventHandler ( "createSoundClient", root, function ( id, theVehicle ) local x, y, z = getElementPosition(theVehicle) sound[source] = playSound3D(id, x, y, z ) attachElements ( sound[source], theVehicle ) end ) Link to comment
~Gangsta~ Posted September 29, 2013 Author Share Posted September 29, 2013 gMe = getLocalPlayer(); gRoot = getRootElement(); gResRoot = getResourceRootElement( getThisResource () ); btn = {}; ipodCoor = { moving={}, pos={} }; addEvent( "clientReceiveMusicTable", true ); local sound = {} addEventHandler( "onClientResourceStart", gResRoot, function () outputChatBox( "Press 'i' to open your iPod", 0, 255, 0 ); ipod = guiCreateStaticImage( 1.0, 0.2279, 0.1916, 0.4036, "ipod.png", true ); --0.7744 ipodCoor.moving[ipod] = false; ipodCoor.pos[ipod] = "out"; songDisplay = guiCreateGridList( 0.0671, 0.0245, 0.8504, 0.4663, true, ipod ); btn[1] = guiCreateButton( 0.64, 0.67, 0.15, 0.05, "Abspielen", true, ipod ); btn[2] = guiCreateButton( 0.185, 0.67, 0.15, 0.05, "Stop", true, ipod ); btn[3] = guiCreateButton( 0.42, 0.825, 0.15, 0.05, "vD", true, ipod ); btn[4] = guiCreateButton( 0.42, 0.525, 0.15, 0.05, "vU", true, ipod ); for i=1,4 do guiSetAlpha( btn[i], 1.0 ); guiSetFont( btn[i], "default-small" ); end; songList = guiGridListAddColumn( songDisplay, "My Songs", 0.85 ); triggerServerEvent( "serverLoadMusicTable", gMe ); addEventHandler( "onClientGUIClick", gRoot, function () local theVehicle = getPedOccupiedVehicle ( gMe ) if theVehicle then if source == btn[1] then local selSong = guiGridListGetItemData( songDisplay, guiGridListGetSelectedItem( songDisplay ) ); if selSong then if ( not isElement (sound[source])) then triggerServerEvent ( "createSound", root, selSong, theVehicle) else destroyElement(sound[source]) triggerServerEvent ( "createSound", root, selSong, theVehicle) end; end; elseif source == btn[2] then if sound[source] then destroyElement(sound[source]) sound[source] = nil; end; elseif source == btn[4] then if music then setSoundVolume( music, getSoundVolume( music ) + 0.25 ); if getSoundVolume( music ) > 1 then setSoundVolume( music, 1 ); end; end; elseif source == btn[3] then if music then setSoundVolume( music, getSoundVolume( music ) - 0.25 ); if getSoundVolume( music ) < 0 then setSoundVolume( music, 0 ); end; end; end; end end ) bindKey( "i", "down", function () if ipodCoor.moving[ipod] == false then if ipodCoor.pos[ipod] == "out" then showCursor( true, false ); ipodCoor.moving[ipod] = true; addEventHandler( "onClientRender", gRoot, openIPod ); toggleControl( "fire", false ); else showCursor( false, false ); ipodCoor.moving[ipod] = true; addEventHandler( "onClientRender", gRoot, closeIPod ); toggleControl( "fire", true ); end; end; end ) end ) function openIPod() local x, y = guiGetPosition( ipod, true ); guiSetPosition( ipod, x - 0.01, y, true ); if x < 0.775 then ipodCoor.moving[ipod] = false; ipodCoor.pos[ipod] = "in"; removeEventHandler( "onClientRender", gRoot, openIPod ); end; end; function closeIPod() local x, y = guiGetPosition( ipod, true ); guiSetPosition( ipod, x + 0.01, y, true ); if x > 1.0 then guiSetPosition( ipod, 1.0, y, true ); ipodCoor.moving[ipod] = false; ipodCoor.pos[ipod] = "out"; removeEventHandler( "onClientRender", gRoot, closeIPod ); end; end; addEventHandler( "clientReceiveMusicTable", gRoot, function ( mTable ) if mTable == nil then triggerServerEvent( "serverLoadMusicTable", gMe ); else for _, v in ipairs ( mTable ) do local row = guiGridListAddRow( songDisplay ); local streamtable = split(v, ';') guiGridListSetItemText( songDisplay, row, 1, streamtable[2], false, false ); guiGridListSetItemData ( songDisplay, row, 1, streamtable[1]); outputChatBox(streamtable[2].." has ben added to your ipod", getLocalPlayer()); end; guiGridListAutoSizeColumn( songDisplay, 1 ); guiBringToFront( songDisplay ); end; end ) addEvent ( "createSoundClient", true ) addEventHandler ( "createSoundClient", root, function ( id, theVehicle ) local x, y, z = getElementPosition(theVehicle) sound[source] = playSound3D(id, x, y, z ) attachElements ( sound[source], theVehicle ) end ) When pressed again, the music is copied Link to comment
Castillo Posted September 29, 2013 Share Posted September 29, 2013 gMe = getLocalPlayer(); gRoot = getRootElement(); gResRoot = getResourceRootElement( getThisResource () ); btn = {}; ipodCoor = { moving={}, pos={} }; addEvent( "clientReceiveMusicTable", true ); local sound = { } addEventHandler( "onClientResourceStart", gResRoot, function () outputChatBox( "Press 'i' to open your iPod", 0, 255, 0 ); ipod = guiCreateStaticImage( 1.0, 0.2279, 0.1916, 0.4036, "ipod.png", true ); --0.7744 ipodCoor.moving[ipod] = false; ipodCoor.pos[ipod] = "out"; songDisplay = guiCreateGridList( 0.0671, 0.0245, 0.8504, 0.4663, true, ipod ); btn[1] = guiCreateButton( 0.64, 0.67, 0.15, 0.05, "Abspielen", true, ipod ); btn[2] = guiCreateButton( 0.185, 0.67, 0.15, 0.05, "Stop", true, ipod ); btn[3] = guiCreateButton( 0.42, 0.825, 0.15, 0.05, "vD", true, ipod ); btn[4] = guiCreateButton( 0.42, 0.525, 0.15, 0.05, "vU", true, ipod ); for i=1,4 do guiSetAlpha( btn[i], 1.0 ); guiSetFont( btn[i], "default-small" ); end; songList = guiGridListAddColumn( songDisplay, "My Songs", 0.85 ); triggerServerEvent( "serverLoadMusicTable", gMe ); addEventHandler( "onClientGUIClick", gRoot, function () local theVehicle = getPedOccupiedVehicle ( gMe ) if source == btn[1] then local selSong = guiGridListGetItemData( songDisplay, guiGridListGetSelectedItem( songDisplay ) ); if selSong then if isElement ( sound [ theVehicle ] ) then stopSound ( sound [ theVehicle ] ); end triggerServerEvent ( "createSound", root, selSong, theVehicle) end; elseif source == btn[2] then if isElement ( sound [ theVehicle ] ) then stopSound ( sound [ theVehicle ] ); end sound [ theVehicle ] = nil elseif source == btn[4] then if sound [ theVehicle ] then setSoundVolume( sound [ theVehicle ], getSoundVolume( sound [ theVehicle ] ) + 0.25 ); if getSoundVolume( sound [ theVehicle ] ) > 1 then setSoundVolume( sound [ theVehicle ], 1 ); end; end; elseif source == btn[3] then if sound [ theVehicle ] then setSoundVolume( sound [ theVehicle ], getSoundVolume( sound [ theVehicle ] ) - 0.25 ); if getSoundVolume( sound [ theVehicle ] ) < 0 then setSoundVolume( sound [ theVehicle ], 0 ); end; end; end; end ) bindKey( "i", "down", function () if ipodCoor.moving[ipod] == false then if ipodCoor.pos[ipod] == "out" then showCursor( true, false ); ipodCoor.moving[ipod] = true; addEventHandler( "onClientRender", gRoot, openIPod ); toggleControl( "fire", false ); else showCursor( false, false ); ipodCoor.moving[ipod] = true; addEventHandler( "onClientRender", gRoot, closeIPod ); toggleControl( "fire", true ); end; end; end ) end ) function openIPod() local x, y = guiGetPosition( ipod, true ); guiSetPosition( ipod, x - 0.01, y, true ); if x < 0.775 then ipodCoor.moving[ipod] = false; ipodCoor.pos[ipod] = "in"; removeEventHandler( "onClientRender", gRoot, openIPod ); end; end; function closeIPod() local x, y = guiGetPosition( ipod, true ); guiSetPosition( ipod, x + 0.01, y, true ); if x > 1.0 then guiSetPosition( ipod, 1.0, y, true ); ipodCoor.moving[ipod] = false; ipodCoor.pos[ipod] = "out"; removeEventHandler( "onClientRender", gRoot, closeIPod ); end; end; addEventHandler( "clientReceiveMusicTable", gRoot, function ( mTable ) if mTable == nil then triggerServerEvent( "serverLoadMusicTable", gMe ); else for _, v in ipairs ( mTable ) do local row = guiGridListAddRow( songDisplay ); local streamtable = split(v, ';') guiGridListSetItemText( songDisplay, row, 1, streamtable[2], false, false ); guiGridListSetItemData ( songDisplay, row, 1, streamtable[1]); outputChatBox(streamtable[2].." has ben added to your ipod", getLocalPlayer()); end; guiGridListAutoSizeColumn( songDisplay, 1 ); guiBringToFront( songDisplay ); end; end ) addEvent ( "createSoundClient", true ) addEventHandler ( "createSoundClient", root, function ( id, theVehicle ) local x, y, z = getElementPosition ( theVehicle ) sound [ theVehicle ] = playSound3D ( id, x, y, z ) attachElements ( sound [ theVehicle ], theVehicle ) end ) Try that. Link to comment
~Gangsta~ Posted September 29, 2013 Author Share Posted September 29, 2013 and how to synchronize stopSound? Link to comment
Castillo Posted September 29, 2013 Share Posted September 29, 2013 You can do it same way as you created it. Link to comment
~Gangsta~ Posted September 29, 2013 Author Share Posted September 29, 2013 You can show how????? Link to comment
Castillo Posted September 29, 2013 Share Posted September 29, 2013 -- client side: gMe = getLocalPlayer(); gRoot = getRootElement(); gResRoot = getResourceRootElement( getThisResource () ); btn = {}; ipodCoor = { moving={}, pos={} }; addEvent( "clientReceiveMusicTable", true ); local sound = { } addEventHandler( "onClientResourceStart", gResRoot, function () outputChatBox( "Press 'i' to open your iPod", 0, 255, 0 ); ipod = guiCreateStaticImage( 1.0, 0.2279, 0.1916, 0.4036, "ipod.png", true ); --0.7744 ipodCoor.moving[ipod] = false; ipodCoor.pos[ipod] = "out"; songDisplay = guiCreateGridList( 0.0671, 0.0245, 0.8504, 0.4663, true, ipod ); btn[1] = guiCreateButton( 0.64, 0.67, 0.15, 0.05, "Abspielen", true, ipod ); btn[2] = guiCreateButton( 0.185, 0.67, 0.15, 0.05, "Stop", true, ipod ); btn[3] = guiCreateButton( 0.42, 0.825, 0.15, 0.05, "vD", true, ipod ); btn[4] = guiCreateButton( 0.42, 0.525, 0.15, 0.05, "vU", true, ipod ); for i=1,4 do guiSetAlpha( btn[i], 1.0 ); guiSetFont( btn[i], "default-small" ); end; songList = guiGridListAddColumn( songDisplay, "My Songs", 0.85 ); triggerServerEvent( "serverLoadMusicTable", gMe ); addEventHandler( "onClientGUIClick", gRoot, function () local theVehicle = getPedOccupiedVehicle ( gMe ) if source == btn[1] then local selSong = guiGridListGetItemData( songDisplay, guiGridListGetSelectedItem( songDisplay ) ); if selSong then triggerServerEvent ( "createSound", root, selSong, theVehicle) end; elseif source == btn[2] then triggerServerEvent ( "destroySound", localPlayer, theVehicle ) elseif source == btn[4] then if sound [ theVehicle ] then setSoundVolume( sound [ theVehicle ], getSoundVolume( sound [ theVehicle ] ) + 0.25 ); if getSoundVolume( sound [ theVehicle ] ) > 1 then setSoundVolume( sound [ theVehicle ], 1 ); end; end; elseif source == btn[3] then if sound [ theVehicle ] then setSoundVolume( sound [ theVehicle ], getSoundVolume( sound [ theVehicle ] ) - 0.25 ); if getSoundVolume( sound [ theVehicle ] ) < 0 then setSoundVolume( sound [ theVehicle ], 0 ); end; end; end; end ) bindKey( "i", "down", function () if ipodCoor.moving[ipod] == false then if ipodCoor.pos[ipod] == "out" then showCursor( true, false ); ipodCoor.moving[ipod] = true; addEventHandler( "onClientRender", gRoot, openIPod ); toggleControl( "fire", false ); else showCursor( false, false ); ipodCoor.moving[ipod] = true; addEventHandler( "onClientRender", gRoot, closeIPod ); toggleControl( "fire", true ); end; end; end ) end ) function openIPod() local x, y = guiGetPosition( ipod, true ); guiSetPosition( ipod, x - 0.01, y, true ); if x < 0.775 then ipodCoor.moving[ipod] = false; ipodCoor.pos[ipod] = "in"; removeEventHandler( "onClientRender", gRoot, openIPod ); end; end; function closeIPod() local x, y = guiGetPosition( ipod, true ); guiSetPosition( ipod, x + 0.01, y, true ); if x > 1.0 then guiSetPosition( ipod, 1.0, y, true ); ipodCoor.moving[ipod] = false; ipodCoor.pos[ipod] = "out"; removeEventHandler( "onClientRender", gRoot, closeIPod ); end; end; addEventHandler( "clientReceiveMusicTable", gRoot, function ( mTable ) if mTable == nil then triggerServerEvent( "serverLoadMusicTable", gMe ); else for _, v in ipairs ( mTable ) do local row = guiGridListAddRow( songDisplay ); local streamtable = split(v, ';') guiGridListSetItemText( songDisplay, row, 1, streamtable[2], false, false ); guiGridListSetItemData ( songDisplay, row, 1, streamtable[1]); outputChatBox(streamtable[2].." has ben added to your ipod", getLocalPlayer()); end; guiGridListAutoSizeColumn( songDisplay, 1 ); guiBringToFront( songDisplay ); end; end ) addEvent ( "createSoundClient", true ) addEventHandler ( "createSoundClient", root, function ( id, theVehicle ) if isElement ( sound [ theVehicle ] ) then stopSound ( sound [ theVehicle ] ); end local x, y, z = getElementPosition ( theVehicle ) sound [ theVehicle ] = playSound3D ( id, x, y, z ) attachElements ( sound [ theVehicle ], theVehicle ) end ) addEvent ( "destroySoundClient", true ) addEventHandler ( "destroySoundClient", root, function ( theVehicle ) if isElement ( sound [ theVehicle ] ) then stopSound ( sound [ theVehicle ] ); end sound [ theVehicle ] = nil end ) -- server side: local gRoot = getRootElement(); addEvent( "serverLoadMusicTable", true ); addEventHandler( "serverLoadMusicTable", gRoot, function () local res, mTable, xml = getThisResource(), {}, xmlLoadFile( "meta.xml", res ); local nameTable = {} if xml then local i = 0; while ( xmlFindChild( xml, "stream", i ) ) do local dir = xmlNodeGetAttribute( xmlFindChild( xml, "stream", i ), "url" ); local streamname = xmlNodeGetAttribute( xmlFindChild( xml, "stream", i ), "name" ); table.insert( mTable, dir..";"..streamname ); i = i + 1; end; end; triggerClientEvent( source, "clientReceiveMusicTable", gRoot, mTable ); end ) addEvent ( "createSound", true ) addEventHandler ( "createSound", root, function ( id, theVehicle) if ( theVehicle ) then triggerClientEvent(root, "createSoundClient", root, id, theVehicle) end end ) addEvent ( "destroySound", true ) addEventHandler ( "destroySound", root, function ( theVehicle ) if ( theVehicle ) then triggerClientEvent(root, "destroySoundClient", root, theVehicle) end end ) Link to comment
~Gangsta~ Posted September 30, 2013 Author Share Posted September 30, 2013 Thank you very much but there is a problem When I go out I go to the server and back then the music fades Link to comment
Castillo Posted September 30, 2013 Share Posted September 30, 2013 You mean that the music is no longer playing after you reconnect? Link to comment
~Gangsta~ Posted September 30, 2013 Author Share Posted September 30, 2013 yes) pls help Link to comment
Castillo Posted September 30, 2013 Share Posted September 30, 2013 You'll have to make some system to store in a table the vehicles that have music playing, and the URL, so when a new player joins, you trigger an event to request them. Link to comment
~Gangsta~ Posted September 30, 2013 Author Share Posted September 30, 2013 have to forget about this Idea I can not do it thanks for the help Link to comment
~Gangsta~ Posted September 30, 2013 Author Share Posted September 30, 2013 Solidsnake14, you can explain the details Link to comment
~Gangsta~ Posted October 1, 2013 Author Share Posted October 1, 2013 can it be done with the help of setElementData and getElementData? Link to comment
manve1 Posted October 1, 2013 Share Posted October 1, 2013 can it be done with the help of setElementData and getElementData? It Can, but it's not recommended as everything will be lost over server restart, or a specific object gets destroyed ( player elements gets destroyed when they quit [any time of disconnect] ) The Recommended ways by me to you would be SQLite or MySql. P.S. Don't Triple-Post. Edit Old Ones then posting more than once. Link to comment
Castillo Posted October 1, 2013 Share Posted October 1, 2013 -- server side: local gRoot = getRootElement(); local sounds = { } addEvent( "serverLoadMusicTable", true ); addEventHandler( "serverLoadMusicTable", gRoot, function () local res, mTable, xml = getThisResource(), {}, xmlLoadFile( "meta.xml", res ); local nameTable = {} if xml then local i = 0; while ( xmlFindChild( xml, "stream", i ) ) do local dir = xmlNodeGetAttribute( xmlFindChild( xml, "stream", i ), "url" ); local streamname = xmlNodeGetAttribute( xmlFindChild( xml, "stream", i ), "name" ); table.insert( mTable, dir..";"..streamname ); i = i + 1; end; end; triggerClientEvent( source, "clientReceiveMusicTable", gRoot, mTable ); end ) addEvent ( "createSound", true ) addEventHandler ( "createSound", root, function ( id, theVehicle ) if ( theVehicle ) then triggerClientEvent(root, "createSoundClient", root, id, theVehicle) sounds [ theVehicle ] = id -- Store in the table the music ID using theVehicle as table index. end end ) addEvent ( "destroySound", true ) addEventHandler ( "destroySound", root, function ( theVehicle ) if ( theVehicle ) then triggerClientEvent(root, "destroySoundClient", root, theVehicle) sounds [ theVehicle ] = nil -- Remove the entry from the table. end end ) Like that, now you have to trigger a event from the client side to request the content of 'sounds' table, then in the client side, loop that table and create the sounds. Link to comment
~Gangsta~ Posted October 2, 2013 Author Share Posted October 2, 2013 nothing has changed Link to comment
manve1 Posted October 2, 2013 Share Posted October 2, 2013 That will be because you haven't done what SolidSnake14 has told you too. Link to comment
Castillo Posted October 2, 2013 Share Posted October 2, 2013 nothing has changed I made half of the work, now you have to do what I said. 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