Sasu Posted March 3, 2014 Posted March 3, 2014 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.
xXMADEXx Posted March 3, 2014 Posted March 3, 2014 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
Castillo Posted March 3, 2014 Posted March 3, 2014 When are you executing "guiCreateGangPanel"? maybe you are binding it twice.
Sasu Posted March 3, 2014 Author Posted March 3, 2014 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)
Castillo Posted March 3, 2014 Posted March 3, 2014 addEvent ( "onLogin", true ) addEventHandler ( "onLogin", root, function ( state, haveGang, gangName, isOwner ) if ( state ) then guiCreateGangPanel ( ) end end ) Maybe you wanted that?
Castillo Posted March 3, 2014 Posted March 3, 2014 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.
Castillo Posted March 4, 2014 Posted March 4, 2014 That's what I thought, "onLogin" is being triggered twice, that makes it bind the key twice.
Sasu Posted March 4, 2014 Author Posted March 4, 2014 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now