nikitafloy Posted April 17, 2014 Share Posted April 17, 2014 (edited) Hi, sorry for the use of an interpreter. Q: How can I transfer the user information between server-client? Example: function prov(thePlayer) triggerClientEvent(thePlayer, 'Hello', getRootElement ( ), thePlayer ) end addCommandHandler('pr', prov) function HelloEnable(source) guiSetVisible(hello.window[1],true) guiSetInputEnabled(true) showCursor(true) end addEvent( "Hello", true ) addEventHandler( "Hello", getRootElement(), HelloEnable ) ... -- Opens GUI - user agreed - opens another GUI user group 'Helper' - a user group 'Helper' agrees - it will teleport to the first player who agreed in the first GUI. function sentBoxHelperBar(thePlayer) guiSetVisible(helphim.window[1],true) guiSetInputEnabled(true) showCursor(true) end addEvent( "sentBoxHelperBar", true ) addEventHandler( "sentBoxHelperBar", getRootElement(), sentBoxHelperBar ) helphim = { button = {}, window = {} } helphim.window[1] = guiCreateWindow(gx/2-310, gy/2-140, 532, 103, 'This player ' ..tostring(getElementData( thePlayer, 'nickNamePom' )).. ' - need help!!!', false) guiWindowSetSizable(helphim.window[1], false) guiSetVisible(helphim.window[1],false) guiSetInputEnabled(false) showCursor(false) helphim.button[1] = guiCreateButton(45, 34, 188, 45, "Ok", false, helphim.window[1]) guiSetProperty(helphim.button[1], "NormalTextColour", "FFAAAAAA") helphim.button[2] = guiCreateButton(296, 34, 188, 45, "Later", false, helphim.window[1]) guiSetProperty(helphim.button[2], "NormalTextColour", "FFAAAAAA") Edited April 17, 2014 by Guest Link to comment
Castillo Posted April 17, 2014 Share Posted April 17, 2014 You can pass arguments to triggerClientEvent/triggerServerEvent Link to comment
nikitafloy Posted April 17, 2014 Author Share Posted April 17, 2014 I get false You can pass arguments to triggerClientEvent/triggerServerEvent triggerClientEvent(source, 'Hello', root, source ) -- pass source to client addEventHandler( "Hello", getRootElement(), HelloEnable ) -- Open GUI -- next i send a request 'Helper' function sentBox() triggerServerEvent( 'sentBoxHelper', root, thePlayer ) disable() end function sentBox(thePlayer) local players = getElementsByType ( "player" ) -- get a table of all the players in the server for theKey,thePlayer in ipairs(players) do -- use a generic for loop to step through each player if ( isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( thePlayer )), aclGetGroup ( "Helper" ) ) ) then triggerClientEvent(thePlayer, 'sentBoxHelperBar', root, thePlayer) end end end -- i filter players and open new GUI helphim.window[1] = guiCreateWindow(gx/2-310, gy/2-140, 532, 103, 'This player' ..tostring(source).. ' - need help!!!', false) -- 'source' -> 'false' Link to comment
Castillo Posted April 17, 2014 Share Posted April 17, 2014 I can't really find out the problem if you post the client side and server side mixed up on a single code. Link to comment
nikitafloy Posted April 17, 2014 Author Share Posted April 17, 2014 I can't really find out the problem if you post the client side and server side mixed up on a single code. Can you give me an example of an argument passed? In the wiki there is no such example, here and do what comes to mind. Link to comment
Castillo Posted April 17, 2014 Share Posted April 17, 2014 There is one for triggerClientEvent. https://wiki.multitheftauto.com/wiki/TriggerClientEvent Link to comment
nikitafloy Posted April 17, 2014 Author Share Posted April 17, 2014 Another question, if I may. Music does not play for everyone. Need trigger server-client. How can I implement it in the code? Hard to imagine a sequence. function onClickPlay(button) for _, n in ipairs (radSpis) do if button == "left" then if ( guiGetText( Radio.combobox[1] ) ~= tostring('Click to open') ) and ( guiGetText( Radio.edit[1] ) ~= "" ) then outputChatBox( 'Choose one thing!' ) return end stopSound(sound3DSound) if ( guiGetText( Radio.edit[1] ) ~= "" ) and ( guiGetText( Radio.combobox[1] ) == tostring('Click to open') ) then sound3DSound = playSound3D ( guiGetText( Radio.edit[1] ), x,y,z, true ) break else local dimensionPlayer = getElementDimension ( getLocalPlayer ( ) ) if ( guiGetText( Radio.combobox[1] ) == 'Dubstep #1' ) then sound3DSound = playSound3D ( "http://radiorecord.fm/m3u/trap320-32kbps.m3u", x,y,z, true ) setElementDimension( sound3DSound, dimensionPlayer ) elseif ( guiGetText( Radio.combobox[1] ) == 'Club Society' ) then sound3DSound = playSound3D ( "http://radio.freshclub.net:9000/8094", x,y,z, true ) setElementDimension( sound3DSound, dimensionPlayer ) elseif ( guiGetText( Radio.combobox[1] ) == 'Trap' ) then sound3DSound = playSound3D ( "http://www.radiorecord.fm/m3u/trap320-32kbps.m3u", x,y,z, true ) setElementDimension( sound3DSound, dimensionPlayer ) elseif ( guiGetText( Radio.combobox[1] ) == 'Mfm' ) then sound3DSound = playSound3D ( "http://radio.mfm.ua/online128.m3u", x,y,z, true ) setElementDimension( sound3DSound, dimensionPlayer ) elseif ( guiGetText( Radio.combobox[1] ) == 'Click to open' ) then return end end attachElements( sound3DSound, getLocalPlayer ( ) ) end end end Link to comment
Castillo Posted April 18, 2014 Share Posted April 18, 2014 That's because playSound3D only plays for the local player, you must make a client-server synchronization. Link to comment
nikitafloy Posted April 18, 2014 Author Share Posted April 18, 2014 That's because playSound3D only plays for the local player, you must make a client-server synchronization. Yes, I read the forum. Here, everything is more difficult for me. I do not know where to use the trigger on the client from the server. Nothing happens. Turned out only without using GUI. If you need the full code, I strip off in HP. I need to solve this problem. I still have 3 of my script that you want to finish. ( Link to comment
Castillo Posted April 18, 2014 Share Posted April 18, 2014 I would do this: Make a function which will play a sound from a URL sent by the server, then attach an event handler to it. Where you currently do "playSound3D" you use triggerServerEvent and pass the URL and dimension to the server side, then from the server side, you trigger the client side event you previously created, passing the URL and dimension received. Link to comment
nikitafloy Posted April 18, 2014 Author Share Posted April 18, 2014 I would do this:Make a function which will play a sound from a URL sent by the server, then attach an event handler to it. Where you currently do "playSound3D" you use triggerServerEvent and pass the URL and dimension to the server side, then from the server side, you trigger the client side event you previously created, passing the URL and dimension received. How i can sent URL by the server? Only elements. Check me, please. Send link to client. --Server function link() link = "http://radiorecord.fm/m3u/trap320-32kbps.m3u" triggerClientEvent( 'linkplaySound', link ) end addEvent('urlDim', true) addEventHandler( 'urlDim', root, link ) Take link from client. --Client function playSound() sound3DSound = playSound3D ( ''..link..'', 0,0,0, true ) end addEvent('linkplaySound', true) addEventHandler( 'linkplaySound', root, playSound ) function onClickPlay(button) ... local dimensionPlayer = getElementDimension ( getLocalPlayer ( ) ) if ( guiGetText( Radio.combobox[1] ) == 'Dubstep #1' ) then sound3DSound = "http://radiorecord.fm/m3u/trap320-32kbps.m3u" triggerServerEvent( 'urlDim', sound3DSound, dimensionPlayer ) -- when i start play sound, then link and dimension send to server.(Server need only link. I feel a lot of mistakes.) setElementDimension( sound3DSound, dimensionPlayer ) ... end end attachElements( sound3DSound, getLocalPlayer ( ) ) end end end Link to comment
Castillo Posted April 18, 2014 Share Posted April 18, 2014 You are wrong, you can't send just elements. The triggerServerEvent is wrong, put localPlayer after the event name. Also, you named a function "playSound", that is not good, naming functions the same way as a native function shouldn't be done, unless you want to replace it. Link to comment
nikitafloy Posted April 18, 2014 Author Share Posted April 18, 2014 (edited) You are wrong, you can't send just elements.The triggerServerEvent is wrong, put localPlayer after the event name. Also, you named a function "playSound", that is not good, naming functions the same way as a native function shouldn't be done, unless you want to replace it. Thx for u remarks. But now every player hears music. Need to hear it was only from the source. And now playing some URL, if I change the station. Edited April 18, 2014 by Guest Link to comment
nikitafloy Posted April 18, 2014 Author Share Posted April 18, 2014 What do you mean? PlaySound - Whoever chose the station and turned. Right then, what happens - one included, hears each. Must be that the source is only 1. Link to comment
Castillo Posted April 18, 2014 Share Posted April 18, 2014 Post the client and server side scripts. Link to comment
nikitafloy Posted April 18, 2014 Author Share Posted April 18, 2014 Post the client and server side scripts. Client. function playSoundNow() local x,y,z = getElementPosition(localPlayer) sound3DSound = playSound3D ( ''..link..'', x,y,z, true ) end addEvent('linkplaySound', true) addEventHandler( 'linkplaySound', root, playSound ) function onClickPlay(button) local x,y,z = getElementPosition ( localPlayer ) for _, n in ipairs (radSpis) do if button == "left" then if ( guiGetText( Radio.combobox[1] ) ~= tostring('Кликните, чтобы раскрыть') ) and ( guiGetText( Radio.edit[1] ) ~= "" ) then outputChatBox( 'Выберите что-то одно!' ) return end stopSound(sound3DSound) if ( guiGetText( Radio.edit[1] ) ~= "" ) and ( guiGetText( Radio.combobox[1] ) == tostring('Кликните, чтобы раскрыть') ) then sound3DSound = playSound3D ( guiGetText( Radio.edit[1] ), x,y,z, true ) triggerServerEvent( 'urlDim', localPlayer ) break else local dimensionPlayer = getElementDimension ( localPlayer ) if ( guiGetText( Radio.combobox[1] ) == 'Dubstep #1' ) then sound3DSound = "http://radiorecord.fm/m3u/trap320-32kbps.m3u" triggerServerEvent( 'urlDim', localPlayer ) setElementDimension( sound3DSound, dimensionPlayer ) elseif ( guiGetText( Radio.combobox[1] ) == 'Club Society' ) then sound3DSound = playSound3D ( "http://radio.freshclub.net:9000/8094", x,y,z, true ) triggerServerEvent( 'urlDim', localPlayer ) setElementDimension( sound3DSound, dimensionPlayer ) elseif ( guiGetText( Radio.combobox[1] ) == 'Trap' ) then sound3DSound = playSound3D ( "http://www.radiorecord.fm/m3u/trap320-32kbps.m3u", x,y,z, true ) triggerServerEvent( 'urlDim', localPlayer ) setElementDimension( sound3DSound, dimensionPlayer ) elseif ( guiGetText( Radio.combobox[1] ) == 'Mfm' ) then sound3DSound = playSound3D ( "http://radio.mfm.ua/online128.m3u", x,y,z, true ) triggerServerEvent( 'urlDim', localPlayer ) setElementDimension( sound3DSound, dimensionPlayer ) elseif ( guiGetText( Radio.combobox[1] ) == 'Кликните, чтобы раскрыть' ) then return end end attachElements( sound3DSound, localPlayer ) end end end Server. function link() link = "http://radiorecord.fm/m3u/trap320-32kbps.m3u" triggerClientEvent( 'linkplaySound', root, link ) end addEvent('urlDim', true) addEventHandler( 'urlDim', root, link ) Link to comment
Castillo Posted April 18, 2014 Share Posted April 18, 2014 -- server side: function link ( link, dimension ) triggerClientEvent ( 'linkplaySound', root, client, link, dimension ) end addEvent ( 'urlDim', true ) addEventHandler ( 'urlDim', root, link ) -- client side: function playSoundNow ( player, link, dimension ) local x, y, z = getElementPosition ( player ) sound3DSound = playSound3D ( link, x,y,z, true ) setElementDimension ( sound3DSound, dimension ) attachElements ( sound3DSound, player ) end addEvent ( 'linkplaySound', true ) addEventHandler ( 'linkplaySound', root, playSound ) Then you make your triggerServerEvent like this: triggerServerEvent ( 'urlDim', localPlayer, "http://radio.mfm.ua/online128.m3u", dimensionPlayer ) 1 Link to comment
nikitafloy Posted April 19, 2014 Author Share Posted April 19, 2014 -- server side: function link ( link, dimension ) triggerClientEvent ( 'linkplaySound', root, client, link, dimension ) end addEvent ( 'urlDim', true ) addEventHandler ( 'urlDim', root, link ) -- client side: function playSoundNow ( player, link, dimension ) local x, y, z = getElementPosition ( player ) sound3DSound = playSound3D ( link, x,y,z, true ) setElementDimension ( sound3DSound, dimension ) attachElements ( sound3DSound, player ) end addEvent ( 'linkplaySound', true ) addEventHandler ( 'linkplaySound', root, playSound ) Then you make your triggerServerEvent like this: triggerServerEvent ( 'urlDim', localPlayer, "http://radio.mfm.ua/online128.m3u", dimensionPlayer ) THX U! 'Special thanks - Castillo' 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