Jokeℝ1472771893 Posted June 28, 2012 Share Posted June 28, 2012 ----client sx,sy = guiGetScreenSize () local volume = 0.3 local guiShowing = false local currentPlaying = nil local state = nil musicPlayerGUI = {} width,height = 200,350 function createGui () musicPlayerGUI.window = guiCreateWindow(sx-width,sy/2-height/2,width,height,"Radio player",false) musicPlayerGUI.grid = guiCreateGridList(5,25,width-10,height-95,false,musicPlayerGUI.window) addEventHandler ( "onClientGUIDoubleClick", musicPlayerGUI.grid, onGuiClick, true ) -- klikanie w grid odpala radio stacje musicPlayerGUI.column = guiGridListAddColumn(musicPlayerGUI.grid,"Radio stations",0.9) musicPlayerGUI.button1 = guiCreateButton(10,height-65,25,20,">",false,musicPlayerGUI.window) addEventHandler ( "onClientGUIClick", musicPlayerGUI.button1, onGuiClick,true) musicPlayerGUI.button2 = guiCreateButton (40, height-65,25,20,"||",false,musicPlayerGUI.window) addEventHandler ( "onClientGUIClick", musicPlayerGUI.button2, onGuiClick, true ) musicPlayerGUI.button3 = guiCreateButton(70,height-65,60,20,"Play 3D",false,musicPlayerGUI.window) addEventHandler ( "onClientGUIClick", musicPlayerGUI.button3, onGuiClick, true ) musicPlayerGUI.button4 = guiCreateButton (135, height-65,60,20,"Close",false,musicPlayerGUI.window) addEventHandler ( "onClientGUIClick", musicPlayerGUI.button4, onGuiClick, true ) musicPlayerGUI.label = guiCreateLabel (5,height-45,width-10,20,"Volume",false,musicPlayerGUI.window) guiSetFont (musicPlayerGUI.label, "default-bold-small") guiLabelSetHorizontalAlign (musicPlayerGUI.label, "center") musicPlayerGUI.volumeBar = guiCreateScrollBar(5,height-30,width-10,20,true,false,musicPlayerGUI.window) guiScrollBarSetScrollPosition (musicPlayerGUI.volumeBar, volume*100) guiWindowSetMovable (musicPlayerGUI.window, false) guiWindowSetSizable (musicPlayerGUI.window, false) guiSetVisible (musicPlayerGUI.window, false) end stationsNames = {} stations = {} function showGui () if guiShowing then guiShowing = false guiSetVisible (musicPlayerGUI.window, false) showCursor (false) else guiShowing = true guiSetVisible (musicPlayerGUI.window, true) showCursor (true) end end addCommandHandler("radio",showGui) function onGuiClick (button, state, x,y) if source == musicPlayerGUI.button1 and state == "up" then --play button local selected = guiGridListGetSelectedItem (musicPlayerGUI.grid) if selected then local stationName = guiGridListGetItemText (musicPlayerGUI.grid, selected, musicPlayerGUI.column) if stationName then if currentPlaying then stopSound (currentPlaying) end currentPlaying = playSound (stations[stationName]) setSoundVolume (currentPlaying, volume) state = "play" else outputChatBox ("unknown error") end elseif state == "pause" and isSoundPaused(currentPlaying) then setSoundPaused (currentPlaying, false) end end if source == musicPlayerGUI.button2 and state == "up" then --pause button if isSoundPaused (currentPlaying) == false then setSoundPaused (currentPlaying, true) end end if source == musicPlayerGUI.button3 and state == "up" then -- 3d local selected = guiGridListGetSelectedItem (musicPlayerGUI.grid) if selected then local stationName = guiGridListGetItemText (musicPlayerGUI.grid, selected, musicPlayerGUI.column) if stationName then triggerServerEvent ("onClientRadioCreate", getLocalPlayer(), getLocalPlayer(), stationName) end end end if source == musicPlayerGUI.button4 and state == "up" then -- close showGui () end if source == musicPlayerGUI.grid and state == "up" then -- grid list click local selected = guiGridListGetSelectedItem (musicPlayerGUI.grid) if selected then local stationName = guiGridListGetItemText (musicPlayerGUI.grid, selected, musicPlayerGUI.column) if stationName then if currentPlaying then stopSound (currentPlaying) end currentPlaying = playSound (stations[stationName]) setSoundVolume (currentPlaying, volume) else outputChatBox ("unknown error") end end end end function OnScroll(Scrolled) if source == musicPlayerGUI.volumeBar then volume = guiScrollBarGetScrollPosition (source) / 100 if currentPlaying then setSoundVolume (currentPlaying, volume) end end end addEventHandler("onClientGUIScroll",getRootElement(),OnScroll) function onRadioCreate (x,y,z,path) local playerveh = getPedOccupiedVehicle(source) local sound = playSound3D (path, x,y,z) setSoundVolume (sound, volume) setSoundMaxDistance (sound, 300) attachElements(sound,playerveh) end addEvent ("onNewRadioCreate", true) addEventHandler ("onNewRadioCreate", getRootElement(), onRadioCreate) function onStart () triggerServerEvent ("requestForRadios", getLocalPlayer(), getLocalPlayer()) end addEventHandler ("onClientResourceStart", getResourceRootElement(getThisResource()), onStart) function onJoin (radia, names, st) for k,v in ipairs(radia) do local sound = playSound3D (v[4], v[1], v[2], v[3]) setSoundVolume (sound, volume/100) setSoundMaxDistance (sound, 20) end stationsNames = names stations = st for k,v in ipairs(stationsNames) do local row = guiGridListAddRow ( musicPlayerGUI.grid ) guiGridListSetItemText ( musicPlayerGUI.grid, row, musicPlayerGUI.column, v, false, false ) end end addEvent ("sendAllRadios", true) addEventHandler ("sendAllRadios", getRootElement(), onJoin) createGui () ---server-- function getPointFromDistanceRotation(x, y, dist, angle) local a = math.rad(angle+90) local plusX = math.cos(a) * dist local plusY = math.sin(a) * dist return x+plusX, y+plusY end xmlFile = xmlLoadFile ("radios.xml") radios = {} stations = {} stationsNames = {} function loadStations () if xmlFile then local children = xmlNodeGetChildren (xmlFile) for k,v in ipairs(children) do local radioTable = xmlNodeGetAttributes (v) for name,value in pairs(radioTable) do --outputChatBox (tostring(value)) if name == "name" then stationName = value elseif name == "path" then stationPath = value end end --outputChatBox ("name = " .. tostring(stationName) .. ", path = " .. tostring(stationPath)) stations[stationName] = stationPath table.insert (stationsNames, 1, stationName) end table.sort (stationsNames) end end loadStations () --stacje["kwejk"] = "http://fm.kwejk.pl/kwejkfm_aac.m3u" --stacje["zet"] = "http://www.radiozet.pl/content/stream/radiozet.pls" --stacje["rmf"] = "http://www.miastomuzyki.pl/odbior/rmf_aacp.pls" --stacje["rmf fm"] = "http://www.miastomuzyki.pl/odbior/rmf_aacp.pls" --nazwyStacji = {"kwejk", "zet", "rmf fm"} function createRadio (player,station) if station then local stationPath = stations[station] local accName = getAccountName ( getPlayerAccount ( player ) ) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then if stationPath then local x,y,z = getElementPosition( player ) local rx,ry,rz = getElementRotation ( player ) local newX, newY = getPointFromDistanceRotation (x,y, 1.5, rz) local playerveh = getPedOccupiedVehicle(player) local newZ = z - 1 local obiekt = createObject (2229, newX, newY, newZ, rx,ry,rz) attachElements (obiekt, playerveh,1, 0, 0,90,0) triggerClientEvent ("onNewRadioCreate", getRootElement(), newX, newY, newZ, stationPath) -- wysyla informacje do clientow o nowym radiu outputChatBox ("New station: " .. station .. " created, path: " .. tostring(stationPath), 0,220,0) table.insert (radios, 1, {newX, newY, newZ, stationPath}) -- zapisuje informacje o radiu dla nowych graczy else outputChatBox ("error", player, 220, 0, 0) --outputChatBox ("You choose wrong station, avaible stations:", player, 220, 0, 0) --for k,v in ipairs(stationsNames) do --outputChatBox ("-" .. v, player) --end end else outputChatBox ("error", player, 220, 0, 0) --outputChatBox ("Choose radio to create, avaible stations:", player,220,0,0) --for k,v in ipairs(stationsNames) do -- outputChatBox ("-" .. v, player) --end end end end addEvent ("onClientRadioCreate", true) addEventHandler ("onClientRadioCreate", getRootElement(), createRadio) --addCommandHandler ("radio", createRadio) function onJoin (player) if radios then triggerClientEvent (player, "sendAllRadios", getRootElement(), radios, stationsNames, stations) end end addEvent ("requestForRadios", true) addEventHandler ("requestForRadios", getRootElement(), onJoin) how to attach the music in the radio? the music is playing in same place -.- Link to comment
Jokeℝ1472771893 Posted June 30, 2012 Author Share Posted June 30, 2012 no one can't help? Link to comment
Castillo Posted July 2, 2012 Share Posted July 2, 2012 I don't understand what do you mean by "attach music", do you mean attach it to the player or something? Link to comment
Jokeℝ1472771893 Posted July 2, 2012 Author Share Posted July 2, 2012 i mean how to attach music to car for EX speakers Link to comment
Jokeℝ1472771893 Posted July 2, 2012 Author Share Posted July 2, 2012 no dude i don't mean this i attach speekers to car but music comes from one place Link to comment
micheal1230 Posted July 3, 2012 Share Posted July 3, 2012 attachElements he wants when the player has the radio on the music that is playing on the radio, its going out of the car so people around the car can hear it Link to comment
albers14 Posted July 4, 2012 Share Posted July 4, 2012 playSound streams out to the local player.. Use playSound3D and then set min. distance and max. distance (Read wiki), and then use attachElements. Remember to stream it serversided as you already did with triggerClientEvent, else others arent able to hear it. Link to comment
Jokeℝ1472771893 Posted July 6, 2012 Author Share Posted July 6, 2012 playSound streams out to the local player.. Use playSound3D and then set min. distance and max. distance (Read wiki), and then use attachElements.Remember to stream it serversided as you already did with triggerClientEvent, else others arent able to hear it. but its not follow my car music comes from 1 place Link to comment
albers14 Posted July 6, 2012 Share Posted July 6, 2012 function onRadioCreate (x,y,z,path) local playerveh = getPedOccupiedVehicle(getLocalPlayer()) local sound = playSound3D (path, x,y,z) setSoundVolume (sound, volume) setSoundMaxDistance (sound, 300) attachElements(sound,playerveh) Link to comment
Jokeℝ1472771893 Posted July 6, 2012 Author Share Posted July 6, 2012 function onRadioCreate (x,y,z,path) local playerveh = getPedOccupiedVehicle(getLocalPlayer()) local sound = playSound3D (path, x,y,z) setSoundVolume (sound, volume) setSoundMaxDistance (sound, 300) attachElements(sound,playerveh) thnx i try now but how to make it atache on car by command and attache with speakers? Link to comment
albers14 Posted July 6, 2012 Share Posted July 6, 2012 Create the objects clientsided and use attachElements Link to comment
Jokeℝ1472771893 Posted July 7, 2012 Author Share Posted July 7, 2012 no no not that for exampl command ( /speaker) and its attach on car trunk? Link to comment
albers14 Posted July 7, 2012 Share Posted July 7, 2012 no no not that for exampl command ( /speaker) and its attach on car trunk? If you directly want it to be at the trunk you need still todo it with attachElements Read about it on wiki how you can set the position of something with attachElements (: Anyways This script is serversided function music() triggerClientEvent('onNewRadioCreate', getRootElement(), source) end addCommandHandler('speaker', music) Its the script I use to start my music at my friends server, try it out. Link to comment
micheal1230 Posted July 7, 2012 Share Posted July 7, 2012 no no not that for exampl command ( /speaker) and its attach on car trunk? If you directly want it to be at the trunk you need still todo it with attachElements Read about it on wiki how you can set the position of something with attachElements (: Anyways This script is serversided function music() triggerClientEvent('onNewRadioCreate', getRootElement(), source) end addCommandHandler('speaker', music) Its the script I use to start my music at my friends server, try it out. @albers14 dont do it for him (attaching speakers to car) tell him what functions he should use because joker is pretty lazy and does'nt often try. Also it is very easy and he cant even do it himself meaning he is not learning anything. @Joker Use attachElements createObject Link to comment
Tete omar Posted July 8, 2012 Share Posted July 8, 2012 Regardless of createObject and attachElements you can use this playSound3D setSoundMaxDistance setSoundMinDistance Link to comment
albers14 Posted July 8, 2012 Share Posted July 8, 2012 Regardless of createObject and attachElementsyou can use this playSound3D setSoundMaxDistance setSoundMinDistance No as he want the sound moving this is impossible since getElementPosition with a command dont go in and get the position of him 24/7, it only gives it once. He need to use attachelements if he wants the sound following him all the way. Link to comment
Tete omar Posted July 8, 2012 Share Posted July 8, 2012 Regardless of createObject and attachElementsyou can use this playSound3D setSoundMaxDistance setSoundMinDistance No as he want the sound moving this is impossible since getElementPosition with a command dont go in and get the position of him 24/7, it only gives it once. He need to use attachelements if he wants the sound following him all the way. you said sound moving ? .. so he can use this local gX, gY, gZ = getElementPosition ( localPlayer ) local myobject = createObject ( any object, floatX, floatY, floatZ ) etc.... local mysound = playSound ( "mysound.mp3", gX, gY, gZ ) etc ..... moveObject ( myobject , floatX, floatY, floatZ ) etc.... attachElements ( mysound , myobject ) that's enough i guess Link to comment
albers14 Posted July 8, 2012 Share Posted July 8, 2012 Regardless of createObject and attachElementsyou can use this playSound3D setSoundMaxDistance setSoundMinDistance No as he want the sound moving this is impossible since getElementPosition with a command dont go in and get the position of him 24/7, it only gives it once. He need to use attachelements if he wants the sound following him all the way. you said sound moving ? .. so he can use this local gX, gY, gZ = getElementPosition ( localPlayer ) local myobject = createObject ( any object, floatX, floatY, floatZ ) etc.... local mysound = playSound ( "mysound.mp3", gX, gY, gZ ) etc ..... moveObject ( myobject , floatX, floatY, floatZ ) etc.... attachElements ( mysound , myobject ) that's enough i guess playSound dont support XYZ, playSound3D does. Why using moveObject and all that other shit when you can do it easy for yourself and just only use attachElements ? As far as I know the speakers should be attached to the car and the car is already a moving object (ofcourse), so I dont see any reason to use moveObject ? Link to comment
denny199 Posted July 8, 2012 Share Posted July 8, 2012 What albers sayd, moving an object is usseles, you can attach an sound element on x,y,z location like this: attachElement ( mySound, car, -1, 0, 0 ) Link to comment
Jokeℝ1472771893 Posted July 8, 2012 Author Share Posted July 8, 2012 any one have links? where i can learn that parts? attach Music on Car Link to comment
Jokeℝ1472771893 Posted July 8, 2012 Author Share Posted July 8, 2012 its Glue System ? no no not this Link to comment
albers14 Posted July 9, 2012 Share Posted July 9, 2012 its Glue System ? no no not this The best thing you probaly can do is going inside MTA and try it out with runcodes when reading Wiki. Remember to use a small visible element. Link to comment
Jokeℝ1472771893 Posted July 9, 2012 Author Share Posted July 9, 2012 i search i find a lot of thinkgs attachElements and playSound3D but i can't bind them together 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