Jump to content

bindKey problem


Lucario

Recommended Posts

Hi i have a problem to bind a weapon shop, when i press the key nothing happen, and doesnt output any errors in the debugscript, im new with the bindKey function.

addEventHandler("onClientResourceStart",resourceRoot, 
function() 
    bindKey ( "F1", "down", closeShop ) 
end ) 
  
function closeShop() 
    if guiGetVisible(shopWindow) then  
        guiSetVisible(shopWindow,false) 
        showCursor(false) 
    end 
end 
addEventHandler ("onClientGUIClick", closeButton, closeShop) 
  
addEventHandler("onClientResourceStart",resourceRoot, 
function() 
    bindKey ( "F1", "down", viewGUI ) 
end ) 
  
addEvent ("viewGUI", true) 
function viewGUI () 
  if (getLocalPlayer() == source) then 
    guiSetVisible (shopWindow, true) 
    showCursor (true) 
  end 
end 
addEventHandler ("viewGUI", getRootElement(), viewGUI) 

It is for Zombie Roleplay, the freeroam is OFF.

Link to comment

Because you are executing two functions with f1 at the same time, one function is showing the gui and one is hiding the gui.

Try this:

function opencloseGUI() 
    local state = not guiGetVisible(shopWindow) 
        guiSetVisible(shopWindow,state) 
    showCursor(state) 
end 
bindKey ( "F1", "down", opencloseGUI ) 

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