Jump to content

newbie needs help


battlefield

Recommended Posts

Hello I'm new on these forums and in scripting. I have problem whith that 1st GUI tutorial when you make Login window. My code is

function createLoginWindow() 
    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) 
  
    X = 0.0825 
    Y = 0.2 
    Width = 0.25 
    Height = 0.25 
    guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin) 
    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) 
    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) 
  
    guiSetVisible(wdwLogin, false) 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),  
    function () 
        createLoginWindow() 
  
                outputChatBox("Welcome to Fun Flight Server, please log in.") 
  
            if (wdwLogin ~= nil) then 
            guiSetVisible(wdwLogin, true) 
        else 
            outputChatBox("An unexpected error has occurred please report this error in bugs article on funflightserver.webs.com .") 
            end  
  
            showCursor(true) 
            guiSetInputEnabled(true) 
    end 
) 
addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
function clientSubmitLogin(button,state) 
    if button == "left" and state == "up" then 
        local username = guiGetText(edtUser) 
        local password = guiGetText(edtPass) 
  
        if username and password then 
            triggerServerEvent("submitLogin", getRootElement(), username, password) 
  
            guiSetInputEnabled(false) 
            guiSetVisible(wdwLogin, false) 
            showCursor(false) 
        else 
            outputChatBox("Please enter username and password.") 
        end 
    end 
end 

I admit i copied it from that GUI tutorial but I don't know what is wrong when i start the server i go online and it does everything okay i enter my admin name and pass, but when I click on login button nothing happens. here is script.lua and meta too if it's nedded

meta

<meta> 
     <info author="Battlefield" type="aviation" name="Fun Fly" description="Fun Fly" /> 
     <script src="script.lua" /> 
     <map src="kr nek.map" /> 
     <script src="client/login window.lua" type="client" /> 
</meta> 

script.lua

function loginHandler(username,password) 
    if username == "user" and password == "apple" then 
        if (client) then 
            spawnPlayer(client, 1315,848, 1278,391, 10,520) 
            fadeCamera(client, true) 
            outputChatBox("Welcome to Fun Flight server.", client) 
        end 
    else 
        outputChatBox("Invalid username and password. Please re-connect and try again choosing other username and password.",client) 
        end             
end 
  
addEvent("submitLogin",true) 
addEventHandler("submitLogin",root,loginHandler) 

the spawn cords are to spawn near Las Venturas Flight school on LVAP. I would ask you for some help whith mooving doors at LVAP where in single player AT-400 is in. I would wan't to make a script to open that doors. And there is another question is there any chace of making vechile private so noone can drive them only the person who "owns"them.

Link to comment

Debugging can help you much faster that us.

You said

when I click on login button nothing happens
so I assume that problem is in client side.

So now comes debugging:

  
addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
function clientSubmitLogin(button,state) 
    outputDebugString("button: "..button.." state: "..state) 
    if button == "left" and state == "up" then 
        local username = guiGetText(edtUser) 
        local password = guiGetText(edtPass) 
        outputDebugString(username.." --- "..password) 
        if username and password then 
        outputDebugString("if passed") 
            triggerServerEvent("submitLogin", getRootElement(), username, password) 
             
            guiSetInputEnabled(false) 
            guiSetVisible(wdwLogin, false) 
            showCursor(false) 
            outputDebugString("all above didnt make script stop, becouse this is showing in debug window") 
        else 
            outputDebugString("if failed") 
            outputChatBox("Please enter username and password.") 
        end 
    end 
end 
  

you need to input in console "debugscript 3" to open debug window, but well, you need to be admin to make that.

also you can use simple outputChatBox instead of outputDebugString, but be sure to remove them all before putting this in public.

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