Jump to content

GUI not showing on connect


Recommended Posts

Hello there!

I guess I've done something wrong, since I'm not familiar with server-side and client-side stuff. The GUIs that should show when a player connects, don't show. I've mostly done what the tutorial about GUIs said, only edited a bit. Also, /debugscript doesn't come up with any errors or warnings, not even info messages.

Here is the code:

(server-side)

function joinHandler()
fadeCamera(source, true)
outputChatBox("Welcome to the Wasteland Warzone Roleplay server.", source)
 
if(getAccount(getPlayerName(source)) == false) then
outputChatBox("Please proceed with registering.", source)
triggerClientEvent("Register", source)
else
outputChatBox("Please proceed with logging in.", source)
triggerClientEvent("Login", source)
end
addEventHandler("onPlayerJoin", getRootElement(), joinHandler)

(client-side)

-- Register --
 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), 
function ()
	createLogin()
	createRegister()
end
)
 
function createRegister()
guiRegister = guiCreateWindow(0.375, 0.375, 0.25, 0.25, "Please register to continue.", true)
guiCreateLabel(0.0825, 0.2, 0.25, 0.25, "Username: " ... getPlayerName() ... "", true, guiRegister)
guiCreateLabel(0.0825, 0.5, 0.25, 0.25, "Password:", true, guiRegister)
 
edtPass = guiCreateEdit(0.415, 0.5, 0.5, 0.15, "Enter a password", true, guiRegister)
guiEditSetMaxLength(edtPass, 50)
 
btnRegister = guiCreateButton(0.415, 0.7, 0.25, 0.2, "Register", true, guiRegister)
addEventHandler("onClientGUIClick", btnRegister, guiSubmitRegister, false)
btnDisconnect = guiCreateButton(0.415, 0.7, 0.25, 0.2, "Disconnect", true, guiRegister)
addEventHandler("onClientGUIClick", btnDisconnect, guiSubmitDisconnect, false)
requestRegister()
end	
 
function requestRegister()
guiSetVisible(guiRegister, true)
guiSetInputEnabled(true)
showCursor(true, true)
end
 
function guiSubmitRegister(button, state)
if button == "left" and state == "up" then
local password = guiGetText(edtPass)
 
if password then
triggerServerEvent("registerPlayer", getRootElement(), password)
 
guiSetInputEnabled(false)
guiSetVisible(guiRegister, false)
showCursor(false)
else
outputChatBox("Error: No password entered.")
end
end
end
 
function guiSubmitDisconnect(button, state)
if button == "left" and state == "up" then
outputChatBox("You have been disconnected.")
kickPlayer()
end
end
 
-- Login --
 
function createLogin()
guiLogin = guiCreateWindow(0.375, 0.375, 0.25, 0.25, "Please register to continue.", true)
guiCreateLabel(0.0825, 0.2, 0.25, 0.25, "Username: " ... getPlayerName() ... "", true, guiLogin)
guiCreateLabel(0.0825, 0.5, 0.25, 0.25, "Password:", true, guiLogin)
 
edtPass = guiCreateEdit(0.415, 0.5, 0.5, 0.15, "Enter a password", true, guiLogin)
guiEditSetMaxLength(edtPass, 50)
 
btnLogin = guiCreateButton(0.415, 0.7, 0.25, 0.2, "Register", true, guiLogin)
addEventHandler("onClientGUIClick", btnLogin, guiSubmitLogin, false)
btnDisconnect = guiCreateButton(0.415, 0.7, 0.25, 0.2, "Disconnect", true, guiLogin)
addEventHandler("onClientGUIClick", btnDisconnect, guiSubmitDisconnect, false)
requestLogin()
end	
 
function requestLogin()
guiSetVisible(guiLogin, true)
guiSetInputEnabled(true)
showCursor(true, true)
end
 
function guiSubmitLogin(button, state)
if button == "left" and state == "up" then
local password = guiGetText(edtPass)
 
if password
if(logIn(getPlayerUserName(), password)
else
outputChatBox("Error: Invalid password.", thePlayer, 255, 255, 0)
end
 
triggerServerEvent("loginPlayer", getRootElement(), password)
guiSetInputEnabled(false)
guiSetVisible(guiLogin, false)
showCursor(false)
else
outputChatBox("Error: No password entered.")
end
end
end
 
function guiSubmitDisconnect(button, state)
if button == "left" and state == "up" then
outputChatBox("You have been disconnected.")
kickPlayer()
end
end
 
-- Events --
 
addEvent("Login", true)
addEventHandler("Login", getRootElement(), createLogin)
 
addEvent("Register", true)
addEventHandler("Register", getRootElement(), createRegister)

I'll also accept critism about my identation, optimisation etc. Everything is helpful to a beginner, I guess :roll::lol: ...

Link to comment
any errors in console?

and this is .. weird:

if(getAccount(getPlayerName(source)) == false) then
--bla
end

(in join handler)

HOW anybody can be logged in while joining? :P

According to the wiki, it returns false if the specified account can't be found in the database:

An account value or false if an account matching the username specified (and password, if specified) could not be found.

---------------------------

hmm i know the answer :D called wiki

https://wiki.multitheftauto.com/wiki/Int ... ng_the_GUI

its shows u exactly how and where to put stuff :wink:

I found this:

If you have used the Introduction to Scripting, you will need to remove or comment the spawnPlayer line in the "joinHandler" function in your code, as we will be replacing it with a gui alternative in this tutorial).

Though I can't find anything else about showing it on join in the tutorial. Or am I missing something?

Link to comment

the problem could be that onPlayerJoin is triggered before the client is even able to download and start the resource client side, resulting in an event being triggered which the client wasn't able to add yet. let the client trigger a server event onClientResourceStart which asks for the information you need (if he is logged in already) on a note here, getPlayerAccount (getAccount does what you want but needs a user name and password!) will not tell you if that person created an account on your server yet but will return the account he is currently logged into, if he is not logged in a guest account will be returned. your client side code also uses some server side only functions (see the orange color) which need to be replaced.

however to check if the person has created an account on your server before you can use a client side xml file filled with information when registering (could for example store your account name, so you don't need to retype it every time), this would also kill the need of the server triggering a client event on join.

i hope i got your intention right

Link to comment
Sorry for double post, but I've got another question.

Is it possible to disable the native /register and /login?

You can try to disable them with ACL but I'm not 100% sure if it'll work.

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