Jump to content

guiComboBoxGetSelected fix


iPanda

Recommended Posts

I am having problems with the combo box.

I do not know how to make the function is activated. I would like to understand.

EXAMPLE! Meaning: if the player selects the combobox regeneration, it receives button from the health regeneration, otherwise something else. . .

Example.lua:

 -- Here, everything works, it's just an example. 
_wndw = guiCreateWindow(0.00, 0.00, 1.00, 1.00, "", true) 
regHP = guiCreateButton(0.93, 0.40, 0.07, 0.03, "Regeneration HP", true, _wndw) 
guiSetVisible( regHP , false ) 
  
-- Here is a problem: does not work. Help me. 
_cmbbx = guiCreateComboBox(0.01, 0.47, 0.99, 0.12, "", true, _wndw) 
hp = guiComboBoxAddItem(_cmbbx, "Regeneration" ) 
  
function hpFunc() 
    if guiComboBoxGetSelected( hp ) then 
        guiSetVisible( regHP , true) 
    end 
end 
  
function bttn() 
    setElementHealth( localPlayer, 100 ) 
end 
addEventHandler( "onClientGUIClick", regHP , bttn, false ) 

Link to comment

You can use this event for when you select something from the combo box:

https://wiki.multitheftauto.com/wiki/On ... oxAccepted

Also, guiComboBoxGetSelected requires a combo box element to get the selected item, like this:

function hpFunc ( ) 
    local item = guiComboBoxGetSelected ( _cmbbx ) 
    local text = guiComboBoxGetItemText ( _cmbbx, item ) 
    if ( text == "Regeneration" ) then 
        guiSetVisible ( regHP, true ) 
    end 
end 

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