Jump to content

Using arguments of an Table from server side to client side


Hero192

Recommended Posts

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 

Link to comment
  • Moderators

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) 

Link to comment
  • Moderators

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) 

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