Jump to content

[HELP]Gui Opens for everybody


Mann56

Recommended Posts

Hello guys,

I was making a group system where i encountered this error. Whenever i open the gui, it shows for everybody even on my pressing the bound key... I am not able to figure out the reason of this thing.

Here's da code

SERVER

function checkIfMember(thePlayer) 
    local inGroup = dbPoll(dbQuery(connection,"SELECT Name FROM Members WHERE Name = ?",getAccountName(getPlayerAccount(thePlayer))),-1) 
    if #inGroup > 0 then 
        if state == false then 
            state = true 
            triggerClientEvent("showTheGui",thePlayer,thePlayer,state) 
        else 
            state = false 
            triggerClientEvent("showTheGui",thePlayer,thePlayer,state) 
        end 
    end 
end 
  
addEvent("memberCheck",true) 
addEventHandler("memberCheck",root,checkIfMember) 
  
function bindPanelKey() 
    bindKey(source,panelOpenKey,"up",checkIfMember) 
end 
  
addEventHandler("onPlayerLogin",root,bindPanelKey) 

CLIENT

  
  
function triggerGui(player,state) 
        guiSetVisible(mainWindow,state) 
        showCursor(state) 
        state = false 
end 
  
addEvent("showTheGui",true) 
addEventHandler("showTheGui",root,triggerGui) 
  

Hope someone can help me in this...

( I hope this extract of the code is enough, if not please inform me, i'll give the gui part)

Mann.

Link to comment

try not tested.

function triggerGui(player,state) 
if (player == localPlayer ) then 
        guiSetVisible(mainWindow,state) 
        showCursor(state) 
        state = false 
end 
  
addEvent("showTheGui",true) 
addEventHandler("showTheGui",resourceRoot,triggerGui) 

Link to comment
try not tested.
function triggerGui(player,state) 
if (player == localPlayer ) then 
        guiSetVisible(mainWindow,state) 
        showCursor(state) 
        state = false 
end 
  
addEvent("showTheGui",true) 
addEventHandler("showTheGui",resourceRoot,triggerGui) 

Why you're checking if the player is a localPlayer ? it's just a waste of time and waste of memory

the function triggerClientEvent has an argument named sendTo.

@Mann56, you left this argument empty which that means: root ( everyone )

server side:

function checkIfMember(thePlayer) 
    local inGroup = dbPoll ( dbQuery ( connection, "SELECT Name FROM Members WHERE Name = ?", getAccountName ( getPlayerAccount ( thePlayer ) ) ), -1 ) 
    if ( #inGroup > 0 ) then 
        if ( not state )  then 
            state = true 
            triggerClientEvent ( thePlayer, "showTheGui", thePlayer, thePlayer, state ) 
        else 
            state = false 
            triggerClientEvent ( thePlayer, "showTheGui", thePlayer, thePlayer, state ) 
        end 
    end 
end 
  
addEvent ( "memberCheck", true ) 
addEventHandler ( "memberCheck", root, checkIfMember ) 

Link to comment

Why you're checking if the player is a localPlayer ? it's just a waste of time and waste of memory

the function triggerClientEvent has an argument named sendTo.

@Mann56, you left this argument empty which that means: root ( everyone )

server side:

function checkIfMember(thePlayer) 
    local inGroup = dbPoll ( dbQuery ( connection, "SELECT Name FROM Members WHERE Name = ?", getAccountName ( getPlayerAccount ( thePlayer ) ) ), -1 ) 
    if ( #inGroup > 0 ) then 
        if ( not state )  then 
            state = true 
            triggerClientEvent ( thePlayer, "showTheGui", thePlayer, thePlayer, state ) 
        else 
            state = false 
            triggerClientEvent ( thePlayer, "showTheGui", thePlayer, thePlayer, state ) 
        end 
    end 
end 
  
addEvent ( "memberCheck", true ) 
addEventHandler ( "memberCheck", root, checkIfMember ) 

Ah got it, thanks!!

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