Jump to content

guiGetSelectedItem data?


Recommended Posts

Posted

Hello guys, I decided to make a Staff Panel, and it's working very good, The thing that i don't know how to use is how to get Selected Player info like example health and armor etc.. Thanks for help.

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

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) 

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

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 ) 

Posted

I did not understand, I want to output player health into a label, i already looped players in the gridlist

GUIEditor.label[1]

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

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) 

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

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.

Posted

Can i use GUIEditor.label[5] = guiCreateLabel(196, 225, 269, 15, "Health"..health, false, GUIEditor.window[1]) instead of guiSetText?

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted (edited)

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

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

Posted

I'm trying to output the selected player health into a label

(like the Admin panel stuff)

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

')' expected to close '(' at line 85 near end

I will send you my full code in pm

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

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