Jump to content

1st GUI tutorial script problem


battlefield

Recommended Posts

Hi! I have problem whith downloading client data. I start my server with MTA server.exe and go online to set resource. Then I go in MTA San Andreas and try to play on my own server but when it starts to download client data id says HTTP said error or something and throws me out of my server in main MTA menu. As the title says the script that I'm trying to download is login window. This is the script

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) 
       guiEditSetMaxLenght(edtUser, 50) 
       guiEditSetMaxLenght(edtPass, 50) 
  
       X = 0.415 
       Y = 0.7 
       Width = 0.025 
       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 ocurred. Please visit funflightserver.webs.com and report this error.") 
                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 wanted username and password.") 
        end 
    end 
end 
  
  

Any ideas ? :?::?:

Link to comment

 

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) 
       guiEditSetMaxLenght(edtUser, 50) 
       guiEditSetMaxLenght(edtPass, 50) 
  
       X = 0.415 
       Y = 0.7 
       Width = 0.025 
       Height = 0.2 
       btnLogin = guiCreateButton(X, Y, Width, Height, "Log in.", true, wdwLogin) 
  
       guiSetVisible(wdwLogin, false) 
       guiSetInputEnabled(true) 
end 
  
                createLoginWindow() 
                outputChatBox("Welcome to Fun Flight Server. Please log in.") 
  
                if (wdwLogin ~= nil)  then 
                        guiSetVisible(wdwLogin, true) 
                else 
                        outputChatBox("An unexpected error has ocurred. Please visit funflightserver.webs.com and report this error.") 
                end 
  
                showCursor(true) 
                 
  
         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 wanted username and password.") 
        end 
    end 
end 
  
  
  

Now use those lines in your script. Maybe it will fix the "t" problem.

Link to comment

Thanks but i cant get to login window because i have accept rules button problem if i click it nothing happens and server doesnt say any errors.Here is the script

function createRulesWindow() 
    local sWidth, sHeight = guiGetScreenSize() 
  
    local Width,Height = 445,445 
    local X = (sWidth/2) - (Width/2) 
    local Y = (sHeight/2) - (Height/2) 
  
    rulesWindow = guiCreateWindow(X,Y,Width,Height,"Rules",false) 
  
    guiWindowSetMovable(rulesWindow,false) 
  
    guiWindowSetSizable(rulesWindow,false) 
  
    rulesButton = guiCreateButton(137,394,158,37,"Accept",false,rulesWindow) 
  
    rulesLabel = guiCreateLabel(10,25,425,359,[[ 
    Welcome to Fun Flight Server! 
  
    Please carefully read the rules before accepting. 
  
    By accepting the rules, you are agreeing to play by them. 
    Anyone caught breaking these rules will be kicked and/or banned from this server. 
  
    If you do not accept the rules within 90 seconds, you will be kicked. 
  
    1: No cheating. 
  
    2: No bug abuse. 
  
    3: No mods to your game. 
  
    4: No flaming. 
  
    5: Respect other players. 
  
    6: Be nice!]],false,rulesWindow) 
  
    guiLabelSetHorizontalAlign(rulesLabel,"center",true)     
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),  
    function () 
        createRulesWindow() 
  
        showCursor(true,true) 
    end 
) 
function acceptRules(button,state) 
    if button == "left" and state == "up" then 
        guiSetVisible(rulesWindow, false) 
  
        showCursor(false,false) 
  
        outputChatBox("Thank you for accepting our rules. Have fun!") 
  
  
        if rulesWarningTimer then 
            killTimer(rulesWarningTimer) 
            rulesWarningTimer = nil 
        end 
    end 
end 
function inactivePlayer(status) 
    if status == 1 then 
        outputChatBox("Please accept our rules or be kicked.") 
  
        rulesWarningTimer = setTimer(inactivePlayer,30000,1,2) 
  
    elseif status == 2 then 
        outputChatBox("FINAL WARNING: Please accept our rules or be kicked.") 
  
        rulesWarningTimer = setTimer(inactivePlayer,30000,1,3)   
    elseif status == 3 then 
        triggerServerEvent("clientKickInactivePlayer",getLocalPlayer()) 
    end 
end 
addEvent("clientKickInactivePlayer",true) 
function kickInactivePlayer() 
    kickPlayer(client,"Please accept our rules.") 
end 
addEventHandler("clientKickInactivePlayer",root,kickInactivePlayer) 

EDIT:Few secs ago I removed rules window and try to login but cursor didnt show and login buton didnt show too.

Link to comment

now it works.

function createRulesWindow() 
    local sWidth, sHeight = guiGetScreenSize() 
  
    local Width,Height = 445,445 
    local X = (sWidth/2) - (Width/2) 
    local Y = (sHeight/2) - (Height/2) 
  
    rulesWindow = guiCreateWindow(X,Y,Width,Height,"Rules",false) 
  
    guiWindowSetMovable(rulesWindow,false) 
  
    guiWindowSetSizable(rulesWindow,false) 
  
    rulesButton = guiCreateButton(137,394,158,37,"Accept",false,rulesWindow) 
  
    rulesLabel = guiCreateLabel(10,25,425,359,[[ 
    Welcome to Fun Flight Server! 
  
    Please carefully read the rules before accepting. 
  
    By accepting the rules, you are agreeing to play by them. 
    Anyone caught breaking these rules will be kicked and/or banned from this server. 
  
    If you do not accept the rules within 90 seconds, you will be kicked. 
  
    1: No cheating. 
  
    2: No bug abuse. 
  
    3: No mods to your game. 
  
    4: No flaming. 
  
    5: Respect other players. 
  
    6: Be nice!]],false,rulesWindow) 
  
    guiLabelSetHorizontalAlign(rulesLabel,"center",true)    
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), 
    function () 
        createRulesWindow() 
        addEventHandler("onClientGUIClick",rulesButton,acceptRules,false) 
        showCursor(true,true) 
    end 
) 
function acceptRules(button,state) 
    if button == "left" and state == "up" then 
        guiSetVisible(rulesWindow, false) 
  
        showCursor(false,false) 
  
        outputChatBox("Thank you for accepting our rules. Have fun!") 
  
  
        if rulesWarningTimer then 
            killTimer(rulesWarningTimer) 
            rulesWarningTimer = nil 
        end 
    end 
end 
function inactivePlayer(status) 
    if status == 1 then 
        outputChatBox("Please accept our rules or be kicked.") 
  
        rulesWarningTimer = setTimer(inactivePlayer,30000,1,2) 
  
    elseif status == 2 then 
        outputChatBox("FINAL WARNING: Please accept our rules or be kicked.") 
  
        rulesWarningTimer = setTimer(inactivePlayer,30000,1,3)  
    elseif status == 3 then 
        triggerServerEvent("clientKickInactivePlayer",getLocalPlayer()) 
    end 
end 
addEvent("clientKickInactivePlayer",true) 
function kickInactivePlayer() 
    kickPlayer(client,"Please accept our rules.") 
end 
addEventHandler("clientKickInactivePlayer",root,kickInactivePlayer) 

your error:

your didn't added the event handler for gui-button.

Link to comment
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.025 
       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 ocurred. Please visit funflightserver.webs.com and report this error.") 
                end 
  
                showCursor(true) 
                guiSetInputEnabled(true) 
         addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false)                 
        end 
) 
  
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 wanted username and password.") 
        end 
    end 
end 

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