Jump to content

guiGetSelectedItem data?


Recommended Posts

Like this? But i think i need to create manually a row every player, can you see what's wrong with it please

addEventHandler("onClientGUIClick", guiRoot, 
function(player) 
thePlayer = getPlayerFromName(source) 
if thePlayer then 
    if source == GUIEditor.label[1] then 
        local row = guiGridListGetSelectedItem(GUIEditor.gridlist[1]) 
        if row == 0 then 
            getElementHealth(thePlayer) 
        end 
    end 
end) 

Link to comment

Lol, no.

For example

gridlist = guiCreateGridList ( .. ) 
column = guiGridListAddColumn ( .. ) 
  
for _, player in ipairs ( getElementsByType ( "player" ) ) do 
    local row = guiGridListAddRow ( gridlist ) 
    guiGridListSetItemText ( gridlist, row, column, getPlayerName ( player ), false, false ) 
end 

And then get it by using

local itemtext = guiGridListGetItemText ( gridlist, guiGridListGetSelectedItem ( gridlist ), column ) 
local player = getPlayerFromName ( itemtext ) 

Link to comment

Here is my code, and sorry i still don't know how to use it

I want it to output the (Selected Gridlist player) health in this format

GUIEditor.label[5] = guiCreateLabel(196, 225, 269, 15, "Health"..health, false, GUIEditor.window[1])

Can you help me if it's possible?

function toggleStaff( source ) 
    -- Show the panel 
    if not guiGetVisible( GUIEditor.window[1] ) then 
        showCursor ( true ) 
        guiSetVisible( GUIEditor.window[1], true ) 
         
        -- Update player list 
        guiGridListClear ( GUIEditor.gridlist[1] ) 
        if ( column ) then 
            for id, player in ipairs(getElementsByType("player")) do 
                local row = guiGridListAddRow ( GUIEditor.gridlist[1] ) 
                guiGridListSetItemText ( GUIEditor.gridlist[1], row, column, getPlayerName ( player ), false, false ) 
                guiGridListSetItemText(GUIEditor.gridlist[1], row, 2,GUIEditor.label[5]  ~= "" and getElementHealth(localPlayer) or "", false, false) 
                local itemtext = guiGridListGetItemText ( gridlist, guiGridListGetSelectedItem ( gridlist ), column ) 
                local player = getPlayerFromName ( itemtext ) 
            end 
        end 
    else 
        showCursor ( false ) 
        guiSetVisible( GUIEditor.window[1], false ) 
    end 
end  
bindKey( "M", "down", toggleStaff )  
addCommandHandler("staff", toggleStaff) 

Link to comment

Your code is a mess.

local itemtext = guiGridListGetItemText ( gridlist, guiGridListGetSelectedItem ( gridlist ), column ) 
local player = getPlayerFromName ( itemtext ) 
local health = getElementHealth ( player ) 
guiSetText ( some_label, health ) 

It should looks like it. And it should be executed when player clicks on gridlist.

Link to comment

Try this:

for _,v in ipairs(getElementsByType("player"))do 
    local row = guiGridListAddRow(GUIEditor.gridlist[1]) 
    local playerName = getPlayerName(v) 
    guiGridListSetItemText(GUIEditor.gridlist[1],row,1,playerName,false,false) 
end 
  
addEventHandler("onClientGUIClick",GUIEditor.gridlist[1], 
    function(b) 
        if b ~= "left" then return end 
        local row,column = guiGridListGetSelectedItem(source) 
        if row == -1 then return end 
        local playerName = guiGridListGetItemText(GUIEditor.gridlist[1],row,column) 
        local player = getPlayerFromName(playerName) 
        if not playerName then 
            guiGridListRemoveRow(row) 
            return 
        end 
        local playerHealth = getElementHealth(player) 
        local playerArmour = getPedArmor(player) 
    end 
end,false) 

Edited by Guest
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...