Jump to content

[HELP]Gui Opens for everybody


Mann56

Recommended Posts

Posted

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.

"When i'll grow older, i'll be stronger, they'll call me freedom, just like a waving flag"

"Have confidence in yourself, no problem is impossible in life"

Posted

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) 

Aftermath

Posted

It works now, thank you very much...

"When i'll grow older, i'll be stronger, they'll call me freedom, just like a waving flag"

"Have confidence in yourself, no problem is impossible in life"

Posted
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 ) 

Posted

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

"When i'll grow older, i'll be stronger, they'll call me freedom, just like a waving flag"

"Have confidence in yourself, no problem is impossible in life"

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