Hero192 Posted January 17, 2016 Posted January 17, 2016 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
Army@1 Posted January 17, 2016 Posted January 17, 2016 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 )
Hero192 Posted January 17, 2016 Author Posted January 17, 2016 Dude but "isGuestAccount" is only works in server side not client side. Can anyone give me an example
Addlibs Posted January 17, 2016 Posted January 17, 2016 Check it serverside and trigger RPC (via server-to-client event) to show GUI.
Hero192 Posted January 17, 2016 Author Posted January 17, 2016 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)
Addlibs Posted January 17, 2016 Posted January 17, 2016 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.
Hero192 Posted January 17, 2016 Author Posted January 17, 2016 Can you do what you said in the code? because I am afraid to fails and thanks for your time <3
Hero192 Posted January 17, 2016 Author Posted January 17, 2016 Please help me and don't ignore this I really need to solve this
Tekken Posted January 17, 2016 Posted January 17, 2016 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);
Hero192 Posted January 17, 2016 Author Posted January 17, 2016 Hey, thanks for your try but you understood me by wrong, I want when i start the resource only guest players who are not logged In who can see the GUI others who are in game can't see the GUI !
Tekken Posted January 17, 2016 Posted January 17, 2016 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);
TAPL Posted January 18, 2016 Posted January 18, 2016 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.
Hero192 Posted January 18, 2016 Author Posted January 18, 2016 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
Addlibs Posted January 18, 2016 Posted January 18, 2016 You should at least try. We're not here to take requests but to either help with wrongly coded scripts, or help get onto the right track with regards to concept scripts.
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