Jump to content

Gridlists.


Xeno

Recommended Posts

Posted

So yeah, I've never done GUI gridlists, so I would like some help...

Here is a wiki example of a guiGridList with a table of players on it (Edited abit)

function createPlayerList () 
    --Create the grid list element 
    local playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) 
    button = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Do", true ) 
--Create a players column in the list 
    local column = guiGridListAddColumn( playerList, "Player", 0.85 ) 
    if ( column ) then --If the column has been created, fill it with players 
        for id, player in ipairs(getElementsByType("player")) do 
            local row = guiGridListAddRow ( playerList ) 
            guiGridListSetItemText ( playerList, row, column, getPlayerName ( player ), false, false ) 
        end 
    end 
end 

What I'm trying to achieve is, when the player presses "button" it outputs into the chat box "hi"

I'm guessing you gotta use GuiGridListGetSelectedItems but i have no idea where to use it..

I would appreciate if you guys could help me,

Xeno.

Posted
function createPlayerList () 
    --Create the grid list element 
    playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) 
    button = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Do", true ) 
    addEventHandler("onClientGUIClick",button,onButtonClick,false) 
    --Create a players column in the list 
    local column = guiGridListAddColumn( playerList, "Player", 0.85 ) 
    if ( column ) then --If the column has been created, fill it with players 
        for id, player in ipairs(getElementsByType("player")) do 
            local row = guiGridListAddRow ( playerList ) 
            guiGridListSetItemText ( playerList, row, column, getPlayerName ( player ), false, false ) 
        end 
    end 
end 
  
function onButtonClick() 
    local row,col = guiGridListGetSelectedItem(playerList) 
    if (row and col and row ~= -1 and col ~= -1) then 
        local playerName = guiGridListGetItemText(playerList, row, 1) 
        outputChatBox("Hi ".. playerName) 
    end 
end 

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

Thank you,

Could I replace

outputChatBox("Hi ".. playerName) 

with

setPlayerTeam(playerName, team1) -- I know I would have to do a triggerServerEvent 

?

Posted

You'll need to use getPlayerFromName to get the player element from the name.

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

You can do:

triggerServerEvent("setTeam",localPlayer,getPlayerFromName(playerName)) 

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

Sorry to bring back an old topic, but this does not work... It won't output "hi" into the chat box when I select my name, here is the code:

function createPlayerList (player) 
    --Create the grid list element 
    local playerList = guiCreateGridList ( 0.60, 0.10, 0.15, 0.60, true ) 
    button = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Do", true ) 
    --Create a players column in the list 
    local column = guiGridListAddColumn( playerList, "Player", 0.85 ) 
    if ( column ) then --If the column has been created, fill it with players 
        for id, player in ipairs(getElementsByType("player")) do 
            local row = guiGridListAddRow ( playerList ) 
            guiGridListSetItemText ( playerList, row, column, getPlayerName ( player ), false, false ) 
        end 
    end 
end 
addCommandHandler("show",createPlayerList) 
  
addEventHandler("onClientGUIClick",button, 
function () 
    local row,col = guiGridListGetSelectedItem(playerList) 
    if (row and col and row ~= -1 and col ~= -1) then 
        local playerName = guiGridListGetItemText(playerList, row, 1) 
        outputChatBox("Hi ") 
    end 
end, false) 

Posted
function createPlayerList (player) 
    --Create the grid list element 
    playerList = guiCreateGridList ( 0.60, 0.10, 0.15, 0.60, true ) 
    button = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Do", true ) 
    addEventHandler("onClientGUIClick",button,onButtonClick,false) 
    --Create a players column in the list 
    local column = guiGridListAddColumn( playerList, "Player", 0.85 ) 
    if ( column ) then --If the column has been created, fill it with players 
        for id, player in ipairs(getElementsByType("player")) do 
            local row = guiGridListAddRow ( playerList ) 
            guiGridListSetItemText ( playerList, row, column, getPlayerName ( player ), false, false ) 
        end 
    end 
end 
addCommandHandler("show",createPlayerList) 
  
  
function onButtonClick() 
    local row,col = guiGridListGetSelectedItem(playerList) 
    if (row and col and row ~= -1 and col ~= -1) then 
        local playerName = guiGridListGetItemText(playerList, row, 1) 
        outputChatBox("Hi ") 
    end 
end 

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

Copy it again, I forgot to remove the "local" in front of "playerList".

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