Jump to content

[Help] Login Panel Not Loading


Recommended Posts

Hey guys... I followed the Example of how to make a Login Panel on the Wiki... I literally did it word for word and when I loaded the server just got a black screen....
I downloaded to Login Systems in Community Files and used them and they both worked... So I edited the one I liked and used it in my Resource and once again got a black screen...

My FILE STRUCTURE is:

-client
     -gui.lua

-assets
     -ViroxRP.png

-server.lua
-meta.xml

My gui.lua is this:

 

function ViroxLoginWindow()
	-- define the X and Y positions of the window
	local X = 0.375
	local Y = 0.375
	-- define the width and height of the window
	local Width = 0.25
	local Height = 0.25
	-- create the window and save its element value into the variable 'wdwLogin'
	-- click on the function's name to read its documentation
	ViroxLogin = guiCreateStaticImage(X,Y,W,H,"assets/ViroxRP.png", true)

    -- define new X and Y positions for the first label
	X = 0.0825
	Y = 0.2
	-- define new Width and Height values for the first label
	Width = 0.25
	Height = 0.25
	-- create the first label, note the final argument passed is 'wdwLogin' meaning the window
	-- we created above is the parent of this label (so all the position and size values are now relative to the position of that window)
	User = guiCreateLabel(X, Y, Width, Height, "Username", true, ViroxLogin)
	-- alter the Y value, so the second label is slightly below the first
	Y = 0.5
	Pass = guiCreateLabel(X, Y, Width, Height, "Password", true, ViroxLogin)
	

	X = 0.415
	Y = 0.2
	Width = 0.5
	Height = 0.15
	UsernameEditBox = guiCreateEdit(X, Y, Width, Height, "", true, ViroxLogin)
	Y = 0.5
	PasswordEditBox = guiCreateEdit(X, Y, Width, Height, "", true, ViroxLogin)
	-- set the maximum character length for the username and password fields to 50
	guiEditSetMaxLength(edtUser, 50)
	guiEditSetMaxLength(edtPass, 50)
	
	X = 0.415
	Y = 0.7
	Width = 0.25
	Height = 0.2
	btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, ViroxLogin)
	
	-- make the  invisible
	guiSetVisible(ViroxLogin, false)
end

addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), 
	function()	    
		ViroxLoginWindow()
		-- if the GUI was successfully created, then show the GUI to the player
	    if (ViroxLogin ~= nil) then
			guiSetVisible(ViroxLogin, true)
			outputChatBox("Welcome to Virox Roleplay v.0.001, please log in.")
		else
			-- if the GUI hasn't been properly created, tell the player
			outputChatBox("An unexpected error has occurred and the login GUI has not been created.")
	    end 

		-- enable the player's cursor (so they can select and click on the components)
	    showCursor(true)
		-- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening
	    guiSetInputEnabled(true)
	end
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false)
)	

function clientSubmitLogin(button,state)
	if button == "left" and state == "up" then
		-- get the text entered in the 'username' field
		local username = guiGetText(UsernameEditBox)
		-- get the text entered in the 'password' field
		local password = guiGetText(PasswordEditBox)

		-- if the username and password both exist
		if username and username ~= "" and password and password ~= "" then
			-- trigger the server event 'submitLogin' and pass the username and password to it
			triggerServerEvent("submitLogin", getRootElement(), username, password)

			-- hide the gui, hide the cursor and return control to the player
			guiSetInputEnabled(false)
			guiSetVisible(ViroxLogin, false)
			showCursor(false)
		else
			-- otherwise, output a message to the player, do not trigger the server
			-- and do not hide the gui
			outputChatBox("Please enter a username and password.")
		end
	end
end

And my meta.xml is:
 

<meta>
    <info author="KryptonicJaze" type="gamemode" name="ViroxRP" description="RP Server in Developement" />
    <script src="server.lua" type="server" />
    	<script src="client/gui.lua" type="client" />
    	<file src="assets/ViroxRP.png" />
</meta>


Can someone help me and figure out what I am doing wrong?

Link to comment

I think that:
 


addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), 
	function()	    
		ViroxLoginWindow()
		-- if the GUI was successfully created, then show the GUI to the player
	    if (ViroxLogin ~= nil) then
			guiSetVisible(ViroxLogin, true)
			outputChatBox("Welcome to Virox Roleplay v.0.001, please log in.")
		else
			-- if the GUI hasn't been properly created, tell the player
			outputChatBox("An unexpected error has occurred and the login GUI has not been created.")
	    end 

^THIS^ (guiSetVisible) isn't being called and I don't know why...
I partly think it is because of how I am using meta.xml

I used the above meta.xml in the root of the Resource but I don't know if every new folder gets it's own meta.xml or if I declare it all in the Root.

Link to comment

From the wiki:

 

function ViroxLoginWindow()
	local X = 0.375
	local Y = 0.375
	local Width = 0.25
	local Height = 0.25
	wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true)
	
	-- define new X and Y positions for the first label
	X = 0.0825
	Y = 0.2
	-- define new Width and Height values for the first label
	Width = 0.25
	Height = 0.25
	-- create the first label, note the final argument passed is 'wdwLogin' meaning the window
	-- we created above is the parent of this label (so all the position and size values are now relative to the position of that window)
	guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin)
	-- alter the Y value, so the second label is slightly below the first
	Y = 0.5
	guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin)
	

	X = 0.415
	Y = 0.2
	Width = 0.5
	Height = 0.15
	edtUser = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)
	Y = 0.5
	edtPass = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)
	-- set the maximum character length for the username and password fields to 50
	guiEditSetMaxLength(edtUser, 50)
	guiEditSetMaxLength(edtPass, 50)
	
	X = 0.415
	Y = 0.7
	Width = 0.25
	Height = 0.2
	btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin)
	
	-- make the window invisible
	guiSetVisible(wdwLogin, false)
end

addEventHandler("onClientResourceStart", getResourceRootElement(), 
	function ()
		-- create the log in window and its components
		ViroxLoginWindow()

		-- output a brief welcome message to the player
                outputChatBox("Welcome to My MTA:SA Server, please log in.")

		-- if the GUI was successfully created, then show the GUI to the player
	        if (wdwLogin ~= nil) then
			guiSetVisible(wdwLogin, true)
		else
			-- if the GUI hasn't been properly created, tell the player
			outputChatBox("An unexpected error has occurred and the login GUI has not been created.")
	        end 

		-- enable the player's cursor (so they can select and click on the components)
	        showCursor(true)
		-- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening
	        guiSetInputEnabled(true)
	end
)

function clientSubmitLogin(button,state)
	if button == "left" and state == "up" then
		-- get the text entered in the 'username' field
		local username = guiGetText(edtUser)
		-- get the text entered in the 'password' field
		local password = guiGetText(edtPass)

		-- if the username and password both exist
		if username and username ~= "" and password and password ~= "" then
			-- trigger the server event 'submitLogin' and pass the username and password to it
			triggerServerEvent("submitLogin", getRootElement(), username, password)

			-- hide the gui, hide the cursor and return control to the player
			guiSetInputEnabled(false)
			guiSetVisible(wdwLogin, false)
			showCursor(false)
		else
			-- otherwise, output a message to the player, do not trigger the server
			-- and do not hide the gui
			outputChatBox("Please enter a username and password.")
		end
	end
end

 

Link to comment

I finally managed to get it working... In Resources you make a Folder for your GameMode for the Server... But when you seperate Admin_Commands or Vehicle_System, does this go in it's own Resource Folder or in a Folder of your original GameMode folder?

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