Jump to content

play Sound


Wei

Recommended Posts

  
local sTations = 
{ 
    { "Power 181", "http://www.181.fm/asx.php?station=181-uktop40&style=&a..scription=" }, 
} 
  
addEventHandler( "onClientResourceStart", getRootElement( ), 
function () 
    for i, n in pairs ( sTations ) do 
    local row = guiGridListAddRow ( stationGridList ) 
    guiGridListSetItemText ( stationGridList, row, column, n[1], false, false ) 
    end 
end 
) 
  
function test() 
    local statioN = guiGridListGetItemText ( stationGridList, guiGridListGetSelectedItem ( stationGridList ), 1 ) 
    if station == n[1] then 
    playSound( n[2] ) 
    end 
end 
addEventHandler("onClientGUIClick", player, test )  
  

how can I make this work ? I tryed but failed...

Link to comment

You should set the URL as item data.

local sTations = 
{ 
    { "Power 181", "http://www.181.fm/asx.php?station=181-uktop40&style=&a..scription=" }, 
} 
  
addEventHandler( "onClientResourceStart", getRootElement( ), 
    function ( ) 
        for i, n in pairs ( sTations ) do 
            local row = guiGridListAddRow ( stationGridList ) 
            guiGridListSetItemText ( stationGridList, row, column, n [ 1 ], false, false ) 
            guiGridListSetItemData ( stationGridList, row, column, n [ 2 ], false, false ) 
        end 
    end 
) 
  
function test ( ) 
    local statioURL = guiGridListGetItemData ( stationGridList, guiGridListGetSelectedItem ( stationGridList ), 1 ) 
    playSound ( stationURL ) 
end 
addEventHandler ( "onClientGUIClick", player, test ) 

Link to comment

Try this: (More simple and optimal code.)

local sTations ={ 
    ["Power 181"] = "http://www.181.fm/asx.php?station=181-uktop40&style=&a..scription="; 
} 
  
addEventHandler( "onClientResourceStart", getRootElement( ), 
function () 
    for StationName, StationAdress in pairs ( sTations ) do 
        local row = guiGridListAddRow ( stationGridList ) 
        guiGridListSetItemText ( stationGridList, row, 1, StationName, false, false ) 
    end 
end 
) 
  
function test() 
    if source == stationGridList then 
        local row, col = guiGridListGetSelectedItem ( stationGridList ) 
            if ( row and col and row ~= -1 and col ~= -1 ) then 
                local statioN = guiGridListGetItemText ( stationGridList, row, 1 ) 
                playSound( sTations[statioN] ) 
            end 
    end 
end 
addEventHandler("onClientGUIClick", getRootElement( ), test ) 

Edited by Guest
Link to comment
Guest Guest4401
How can I set 2 grid List item data ?

You can make a table and set multiple item datas as an encoded string, and retrieve as table using

toJSON 
fromJSON 

Link to comment
Guest Guest4401
You can save lua tables as item data as well, no need for JSONs.
Ok, then the wiki is wrong? Because it's saying
bool guiGridListSetItemData ( element gridList, int rowIndex, int columnIndex, string data ) 

Fourth argument is string and not var :?

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