Jump to content

play Sound


Wei

Recommended Posts

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

Diet with russian vodka, lose 3 days in one week !

Posted

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 ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted (edited)

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
Posted

You're welcome.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Guest Guest4401
Posted
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 

Posted

You can save lua tables as item data as well, no need for JSONs.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Guest Guest4401
Posted
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 :?

Posted

Has to be, I've saved Lua tables before without problems.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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