Jump to content

bindKey bug?


Sasu

Recommended Posts

My problem is that for some reason the function trigger twice with one bindKey. Here is a part of my code:

function guiCreateGangPanel() 
        bindKey("F6", "down", bindPanel) 
end 
  
function bindPanel() 
    local bool = guiGetVisible(gangPanel.window[1]) 
    outputChatBox(tostring(bool)) 
    guiSetVisible(gangPanel.window[1], not bool) 
    showCursor(not bool) 
    if bool then 
        guiSetVisible(gangList.window[1], false) 
        guiSetVisible(gangInvitations.window[1], false) 
    else 
        refreshInfoGang() 
    end 
end 

I tried it with the outputChatBox, it output:

false

true

Thanks.

Link to comment

Try this:

function guiCreateGangPanel() 
        bindKey("F6", "down", bindPanel) 
end 
  
function bindPanel( _, s ) 
    if ( s ~= "down" ) then return end 
    local bool = guiGetVisible(gangPanel.window[1]) 
    outputChatBox(tostring(bool)) 
    guiSetVisible(gangPanel.window[1], not bool) 
    showCursor(not bool) 
    if bool then 
        guiSetVisible(gangList.window[1], false) 
        guiSetVisible(gangInvitations.window[1], false) 
    else 
        refreshInfoGang() 
    end 
end 
  

Link to comment
When are you executing "guiCreateGangPanel"? maybe you are binding it twice.

Server:

addEventHandler("onPlayerLogin", root, 
function(_,accPlayer) 
    local accName = getAccountName(accPlayer) 
    local qh = dbQuery(connection, "SELECT MemberGang,MemberRank,MemberSubLeader FROM GangMembers WHERE MemberAccount=?", accName) 
    local result = dbPoll(qh, -1) 
    if result and type(result) == "table" then 
        if #result ~= 0 then 
            if result[1].MemberGang ~= "" then 
                local isOwner = tostring(result2[1].GangOwner) == accName or false 
            local isSubLeader = tonumber(result[1].MemberSubLeader) == 1 or false 
                triggerClientEvent(source, "onLogin", source, true, result[1].MemberGang, isOwner, isSubLeader) 
            else 
                triggerClientEvent(source, "onLogin", source, false) 
            end 
        else 
            triggerClientEvent(source, "onLogin", source, false) 
        end 
    else 
        triggerClientEvent(source, "onLogin", source, false) 
    end 
end) 

Client:

addEvent("onLogin", true) 
addEventHandler("onLogin", root, 
function(haveGang, gangName, isOwner) 
    guiCreateGangPanel() 
end) 

Link to comment
addEvent ( "onLogin", true ) 
addEventHandler ( "onLogin", root, 
    function ( state, haveGang, gangName, isOwner ) 
        if ( state ) then 
            guiCreateGangPanel ( ) 
        end 
    end 
) 

Maybe you wanted that?

Link to comment
addEvent ( "onLogin", true ) 
addEventHandler ( "onLogin", root, 
    function ( haveGang, gangName, isOwner ) 
        guiCreateGangPanel ( ) 
        outputChatBox ( "guiCreateGangPanel" ) 
    end 
) 

Put that and see how many times does it output "guiCreateGangPanel" to the chat box.

Link to comment
That's what I thought, "onLogin" is being triggered twice, that makes it bind the key twice.

Yes, I remember that I have other resource with that event name but I didn't know that triggerClientEvent trigger all resources started that have the same event name. Thank you.

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