Hero192 Posted September 7, 2015 Posted September 7, 2015 Hi Guys,i tried to get the arguments of this table named "Music" but it doesn't works i sent the table by trigger in a function but in another function it didn't works here's the table server sided: --server side: local Music = { { "Hip Hop Radio", "http://mp3uplink.duplexfx.com:8054/listen.pls" }, { "Electo", "http://stream.electroradio.ch:26630/" }, { "Reggae", "http://184.107.197.154:8002" }, { "Rap", "http://173.245.71.186:80" }, } --client side: function () local row,col = guiGridListGetSelectedItem( grid ) if Music [row+1][2] then sound = playSound3D (Music [row+1][2], x,y,z,true) setSoundVolume ( sound , 1 ) end end
Moderators IIYAMA Posted September 7, 2015 Moderators Posted September 7, 2015 Something like this should do the job. Now memorize it, because I am not for requesting. Server local Music = { { "Hip Hop Radio", "http://mp3uplink.duplexfx.com:8054/listen.pls" }, { "Electo", "http://stream.electroradio.ch:26630/" }, { "Reggae", "http://184.107.197.154:8002" }, { "Rap", "http://173.245.71.186:80" }, } addEvent("onPlayerRequestingMusicData",true) addEventHandler("onPlayerRequestingMusicData",resourceRoot, function () if isElement(client) then triggerClientEvent(client,"onClientPlayerReceiveMusicData",resourceRoot,Music) end end) Client addEvent("onClientPlayerReceiveMusicData",true) addEventHandler("onClientPlayerReceiveMusicData",resourceRoot, function (Music) local row,col = guiGridListGetSelectedItem( grid ) if Music[row+1] and Music[row+1][2] then local sound = playSound3D (Music [row+1][2], x,y,z,true) if sound then setSoundVolume ( sound , 1 ) end end end) addEventHandler("onClientResourceStart",resourceRoot, function () triggerServerEvent("onPlayerRequestingMusicData",resourceRoot) end)
Hero192 Posted September 8, 2015 Author Posted September 8, 2015 EDIT: thanks about the idea i made it QUESTIONS: Why you used resourceRoot and not root or getElementRoot() ? and why we need to create an empty table like that ? Sound = {} Sound [source]
Moderators IIYAMA Posted September 8, 2015 Moderators Posted September 8, 2015 The root element, which is the result of the function getRootElement() (root = getRootElement()), is a dynamic element. Which can be anything and everything. While resourceRoot can't. If I pass down resourceRoot through my triggerEvent, it will be the source of next the eventHandler which is attached to that event. And now coming back to your question. When I define root in an addEventHandler, it will trigger at any element I am passing down. Which can be a player, a marker, a ped, a vehicle. But when I define the element I am passing down from the triggerEvent to the eventHandler, it can only be that element. The reason why I am using resourceRoot, is because I don't want to have conflicts with custom triggerEvents. Yet, it is not very important since that doesn't happen very often. Normally people write longer and complexer event names(like I did in this code). When you take a close look at your code now: Client triggerServerEvent([color=#0000FF]"onPlayerRequestingMusicData"[/color],[color=#FF0000]resourceRoot[/color]) Server addEvent([color=#0000FF]"onPlayerRequestingMusicData"[/color],true) addEventHandler([color=#0000FF]"onPlayerRequestingMusicData"[/color],[color=#FF0000]resourceRoot[/color], function () [color=#FF0000] -- source [/color] if isElement(client) then triggerClientEvent(client,[color=#00FF00]"onClientPlayerReceiveMusicData"[/color],[color=#FF0000]resourceRoot[/color],Music) end end) Client addEvent([color=#00FF00]"onClientPlayerReceiveMusicData"[/color],true) addEventHandler([color=#00FF00]"onClientPlayerReceiveMusicData"[/color],[color=#FF0000]resourceRoot[/color], function (Music) [color=#FF0000] -- source [/color] local row,col = guiGridListGetSelectedItem( grid ) if Music[row+1] and Music[row+1][2] then local sound = playSound3D (Music [row+1][2], x,y,z,true) if sound then setSoundVolume ( sound , 1 ) end end end)
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