Jump to content

Close gui in bindKey


Matevsz

Recommended Posts

Hello, I am trying to close the gridlist using the "backspace" when pressed nothing happens

  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
gridlist = guiCreateGridList(1350, 383, 236, 293, false) 
guiSetVisible(gridlist, false) 
end) 
  
function CloseGUI(keyState) 
if keyState == "down" then 
showCursor(false) 
guiSetVisible(gridlist, false) 
setCameraTarget(getLocalPlayer(), getLocalPlayer()) 
end 
end 
bindKey("backspace", "down", CloseGUI) 
  

It is part of the code.

Link to comment
  
  
gridlist = guiCreateGridList(1350, 383, 236, 293, false) 
guiSetVisible(gridlist,true) 
  
function CloseGUI(keyState) 
if keyState == "down" then 
showCursor(false) 
guiSetVisible(gridlist, false) 
setCameraTarget(getLocalPlayer(), getLocalPlayer()) 
end 
end 
bindKey("backspace", "down", CloseGUI) 
  

Link to comment
  • Moderators
  
  
gridlist = guiCreateGridList(1350, 383, 236, 293, false) 
guiSetVisible(gridlist,true) 
  
function CloseGUI(keyState) 
if keyState == "down" then 
showCursor(false) 
guiSetVisible(gridlist, false) 
setCameraTarget(getLocalPlayer(), getLocalPlayer()) 
end 
end 
bindKey("backspace", "down", CloseGUI) 
  

This code has the exact same behavior, you changed nothing ...

____________________________________________________________________________________

@Matevsz: The 1st argument your bound function receive is not the keyState but the name of the key you pressed (here your "keyState" value will be "backspace"). Naming the 1st argument keyState won't make it get the keyState value, only the position matters.

Fixed code (I only modified line 7):

addEventHandler("onClientResourceStart", resourceRoot, 
function() 
    gridlist = guiCreateGridList(1350, 383, 236, 293, false) 
    guiSetVisible(gridlist, false) 
end) 
  
function CloseGUI(key, keyState) 
    if keyState == "down" then 
        showCursor(false) 
        guiSetVisible(gridlist, false) 
        setCameraTarget(getLocalPlayer(), getLocalPlayer()) 
    end 
end 
bindKey("backspace", "down", CloseGUI) 

PS: Also please indent your code correctly so it's easier for us to read your code (and especially for you if you need to read that code later).

Regards,

Citizen

Link to comment
  
local ped = createPed(0, 0,0,0, 87.9990844) 
setElementInterior(ped, 18) 
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
gridlist = guiCreateGridList(1350, 383, 236, 293, false) 
guiSetVisible(gridlist, false) 
end)  
  
function ShowGUI(hitPlayer) 
    if hitPlayer == localPlayer then 
        showCursor(true) 
        guiSetVisible(gridlist, true) 
        setElementPosition(ped, 180.10000610352, -88.199996948242, 1002) 
        setCameraMatrix(174.46969604492, -88.212097167969, 1003.6256713867, 175.40690612793, -88.209663391113, 1003.2769165039) 
    end 
end 
addEventHandler("onClientMarkerHit", markerKupnaSkina2, ShowGUI) 
  
function CloseGUI(key, keyState) 
    if keyState == "down" then 
        showCursor(false) 
        guiSetVisible(gridlist, false) 
        setCameraTarget(getLocalPlayer(), getLocalPlayer()) 
        destroyElement(ped) 
    end 
end 
bindKey("backspace", "down", CloseGUI) 
  

How Depress the "backspace" and I go back to that marker (ped) is no longer

I used the wrong "destroyElement (ped)"?

Link to comment
  • Moderators

Your english doesn't let me understand what you are trying to do with the ped.

Maybe you should ask your question into your regional sub-forum: Poland / Polski

Calling destroyElement on the ped will make it disapear for ever. You should probably do this ?:

setElementPosition(ped, 0, 0, 0) 

Link to comment

Sorry, for my English :(

Thanks, now the last thing buying a skin.

  
function ChangeSkin(state) 
    if state == "left" then 
        local skin = guiGridListGetItemText(gridlist, guiGridListGetSelectedItem(gridlist), 2) 
        setElementModel(ped, skin)   
    end 
end 
addEventHandler("onClientGUIClick", getRootElement(getThisResource), ChangeSkin) 
  
  
function BuySkin(key, keyState) 
if keyState == "down" then 
showCursor(false) 
guiSetVisible(gridlist, false) 
setCameraTarget(getLocalPlayer(), getLocalPlayer()) 
setElementPosition(ped, 0, 0, 0) 
setElementModel(localPlayer, skin) 
end 
end 
bindKey("enter", "down", BuySkin) 
  

something like this?

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