Jump to content

I need Help in my Login


Hero192

Recommended Posts

Hello everybody, I need help

I made a login system but faced a problem, When I restart the login resource the GUI shows to other players, I want When I restart the script only players who don't have accounts or still not logged in, who can see it and players who are in game can't see the login's GUI.

please give me a hand !

local loginGUI = {} 
loginGUI["window"] = {} 
loginGUI["label"] = {} 
loginGUI["edit"] = {} 
loginGUI["button"] = {} 
loginGUI["checkbox"] = {} 
loginGUI["tabpanel"] = {} 
  
  
function mainGUI() 
loginGUI["window"]["login"] = guiCreateWindow((sWidth - 518) / 2, (sHeight - 537) / 2, 518, 537, "Login Panel", false) 
guiWindowSetSizable(loginGUI["window"]["login"],false) 
guiSetVisible(loginGUI["window"]["login"],false) 
loginGUI["label"]["info"] = guiCreateLabel(12, 23, 499, 45, "Welcome", false, loginGUI["window"]["login"]) 
guiSetFont(loginGUI["label"]["info"], "default-bold-small") 
guiLabelSetColor(loginGUI["label"]["info"], 255, 0, 0) 
loginGUI["edit"]["user"] = guiCreateEdit(114, 85, 267, 30, "", false, loginGUI["window"]["login"]) 
loginGUI["label"]["user"] = guiCreateLabel(34, 91, 71, 24, "Username:", false, loginGUI["window"]["login"]) 
guiSetFont(loginGUI["label"]["user"], "default-bold-small") 
loginGUI["edit"]["pass"] = guiCreateEdit(115, 128, 267, 30, "", false, loginGUI["window"]["login"]) 
guiEditSetMasked(loginGUI["edit"]["pass"], true) 
loginGUI["label"]["pass"] = guiCreateLabel(34, 133, 71, 24, "Password:", false, loginGUI["window"]["login"]) 
guiSetFont(loginGUI["label"]["pass"], "default-bold-small") 
loginGUI["button"]["login"] = guiCreateButton(9, 256, 121, 27, "Login", false, loginGUI["window"]["login"]) 
loginGUI["label"]["info3"] = guiCreateLabel(16, 182, 314, 22, "Save username and password", false, loginGUI["window"]["login"]) 
guiSetFont(loginGUI["label"]["info3"], "default-bold-small") 
loginGUI["checkbox"]["save"] = guiCreateCheckBox(24, 214, 81, 15, "Save", false,false, loginGUI["window"]["login"]) 
guiSetFont(loginGUI["checkbox"]["save"], "default-bold-small") 
loginGUI["button"]["register"] = guiCreateButton(145, 256, 121, 27, "Register", false, loginGUI["window"]["login"]) 
  
end 

Link to comment

From wiki:

'A guest account is an account automatically created for a user when they join the server and deleted when they quit or login to another account'

  
function showGUI() 
    if isGuestAccount(getPlayerAccount(localPlayer)) then 
        guiSetVisible(loginGUI["window"], true) 
        showCursor (true) 
    else 
        guiSetVisible(loginGUI["window"], false) 
        showCursor(false) 
    end 
end 
addEventHandler ( "onClientResourceStart", getRootElement(), showGui ) 
  

Link to comment

I tried that but Doesn't works, Can anyone help me please?

--Client side:

function showLoginWindow() 
    guiSetVisible(loginGUI["window"]["login"], true ) 
end 
addEvent("showLogin", true) 
addEventHandler("showLogin", root, showLoginWindow) 
  
addEventHandler( "onClientResourceStart", getRootElement(), 
function () 
triggerServerEvent("isLoggedIn",localPlayer, localPlayer ) 
end) 

--Server side:

addEvent("isLoggedIn",true) 
addEventHandler("isLoggedIn",root, 
function (client) 
    if isGuestAccount(getPlayerAccount(client)) then  
   triggerClientEvent(client,"showLogin",client) 
    end 
end) 

Link to comment
I tried that but Doesn't works, Can anyone help me please?

--Client side:

function showLoginWindow() 
    guiSetVisible(loginGUI["window"]["login"], true ) 
end 
addEvent("showLogin", true) 
addEventHandler("showLogin", root, showLoginWindow) 
  
addEventHandler( "onClientResourceStart", getRootElement(), 
function () 
triggerServerEvent("isLoggedIn",localPlayer, localPlayer ) 
end) 

--Server side:

addEvent("isLoggedIn",true) 
addEventHandler("isLoggedIn",root, 
function (client) 
    if isGuestAccount(getPlayerAccount(client)) then  
   triggerClientEvent(client,"showLogin",client) 
    end 
end) 

I don't see why this code doesn't work for you. Are you sure you saved the file and restarted the resource etc?

Also, beware—you're calling isLoggedIn every time a resource starts. You should use resourceRoot (a predefined variable) instead of getRootElement(), otherwise the panel will appear everytime a new resource is started and someone isn't logged in.

Link to comment

This should fix it:

local loginGUI = {}; 
local loginGUI["window"] = {}; 
local loginGUI["label"] = {}; 
local loginGUI["edit"] = {}; 
local loginGUI["button"] = {}; 
local loginGUI["checkbox"] = {}; 
local loginGUI["tabpanel"] = {}; 
  
addEventHandler("onClientResourceStart", resourceRoot, function() 
    loginGUI["window"]["login"] = guiCreateWindow((sWidth - 518) / 2, (sHeight - 537) / 2, 518, 537, "Login Panel", false) 
    guiWindowSetSizable(loginGUI["window"]["login"],false) 
    guiSetVisible(loginGUI["window"]["login"],false) 
    loginGUI["label"]["info"] = guiCreateLabel(12, 23, 499, 45, "Welcome", false, loginGUI["window"]["login"]) 
    guiSetFont(loginGUI["label"]["info"], "default-bold-small") 
    guiLabelSetColor(loginGUI["label"]["info"], 255, 0, 0) 
    loginGUI["edit"]["user"] = guiCreateEdit(114, 85, 267, 30, "", false, loginGUI["window"]["login"]) 
    loginGUI["label"]["user"] = guiCreateLabel(34, 91, 71, 24, "Username:", false, loginGUI["window"]["login"]) 
    guiSetFont(loginGUI["label"]["user"], "default-bold-small") 
    loginGUI["edit"]["pass"] = guiCreateEdit(115, 128, 267, 30, "", false, loginGUI["window"]["login"]) 
    guiEditSetMasked(loginGUI["edit"]["pass"], true) 
    loginGUI["label"]["pass"] = guiCreateLabel(34, 133, 71, 24, "Password:", false, loginGUI["window"]["login"]) 
    guiSetFont(loginGUI["label"]["pass"], "default-bold-small") 
    loginGUI["button"]["login"] = guiCreateButton(9, 256, 121, 27, "Login", false, loginGUI["window"]["login"]) 
    loginGUI["label"]["info3"] = guiCreateLabel(16, 182, 314, 22, "Save username and password", false, loginGUI["window"]["login"]) 
    guiSetFont(loginGUI["label"]["info3"], "default-bold-small") 
    loginGUI["checkbox"]["save"] = guiCreateCheckBox(24, 214, 81, 15, "Save", false,false, loginGUI["window"]["login"]) 
    guiSetFont(loginGUI["checkbox"]["save"], "default-bold-small") 
    loginGUI["button"]["register"] = guiCreateButton(145, 256, 121, 27, "Register", false, loginGUI["window"]["login"])  
end); 

Link to comment

Client:

local loginGUI = {}; 
local loginGUI["window"] = {}; 
local loginGUI["label"] = {}; 
local loginGUI["edit"] = {}; 
local loginGUI["button"] = {}; 
local loginGUI["checkbox"] = {}; 
local loginGUI["tabpanel"] = {}; 
  
addEvent("showLoginPanel", true); 
  
addEventHandler("onClientResourceStart", resourceRoot, function() 
    loginGUI["window"]["login"] = guiCreateWindow((sWidth - 518) / 2, (sHeight - 537) / 2, 518, 537, "Login Panel", false) 
    guiWindowSetSizable(loginGUI["window"]["login"],false) 
    guiSetVisible(loginGUI["window"]["login"],false) 
    loginGUI["label"]["info"] = guiCreateLabel(12, 23, 499, 45, "Welcome", false, loginGUI["window"]["login"]) 
    guiSetFont(loginGUI["label"]["info"], "default-bold-small") 
    guiLabelSetColor(loginGUI["label"]["info"], 255, 0, 0) 
    loginGUI["edit"]["user"] = guiCreateEdit(114, 85, 267, 30, "", false, loginGUI["window"]["login"]) 
    loginGUI["label"]["user"] = guiCreateLabel(34, 91, 71, 24, "Username:", false, loginGUI["window"]["login"]) 
    guiSetFont(loginGUI["label"]["user"], "default-bold-small") 
    loginGUI["edit"]["pass"] = guiCreateEdit(115, 128, 267, 30, "", false, loginGUI["window"]["login"]) 
    guiEditSetMasked(loginGUI["edit"]["pass"], true) 
    loginGUI["label"]["pass"] = guiCreateLabel(34, 133, 71, 24, "Password:", false, loginGUI["window"]["login"]) 
    guiSetFont(loginGUI["label"]["pass"], "default-bold-small") 
    loginGUI["button"]["login"] = guiCreateButton(9, 256, 121, 27, "Login", false, loginGUI["window"]["login"]) 
    loginGUI["label"]["info3"] = guiCreateLabel(16, 182, 314, 22, "Save username and password", false, loginGUI["window"]["login"]) 
    guiSetFont(loginGUI["label"]["info3"], "default-bold-small") 
    loginGUI["checkbox"]["save"] = guiCreateCheckBox(24, 214, 81, 15, "Save", false,false, loginGUI["window"]["login"]) 
    guiSetFont(loginGUI["checkbox"]["save"], "default-bold-small") 
    loginGUI["button"]["register"] = guiCreateButton(145, 256, 121, 27, "Register", false, loginGUI["window"]["login"]) 
    guiSetVisible(loginGUI["window"]["login"], false); 
end); 
  
addEventHandler("showLoginPanel", root, function(bool) 
    guiSetVisible(loginGUI["window"]["login"], bool);  
end); 

Server:

addEventHandler("onResourceStart", resourceRoot, function() 
    for _,v in ipairs(getElementsByType("player")) do 
        if isGuestAccount(getPlayerAccount(v)) then 
            triggerClientEvent(v, "showLoginPanel", v, true); 
        end 
    end 
end); 

Link to comment

When the resource start make trigger from client side to server side and get the player account and use isGuestAccount to check if it gust or not, if it guest then make trigger from server side to client side and use guiSetVisible to show the window, if not guest then do nothing.

onClientResourceStart -> triggerServerEvent -> [ getPlayerAccount isGuestAccount ] -> triggerClientEvent -> guiSetVisible.

Link to comment
When the resource start make trigger from client side to server side and get the player account and use isGuestAccount to check if it gust or not, if it guest then make trigger from server side to client side and use guiSetVisible to show the window, if not guest then do nothing.

onClientResourceStart -> triggerServerEvent -> [ getPlayerAccount isGuestAccount ] -> triggerClientEvent -> guiSetVisible.

Can you or anyone do that for me please

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