Jump to content

A small script problem.


hahec

Recommended Posts

Hello Everybody. So this day i decided to really focus at Scripting Introduction and Indroduction to GUI

So here i am, stuck on a really noobish problem. I folowed the tutorial on scripting introduction and the spawn player worked well. Also the /createvehicle *** was also succesful. Then i wanted to make i login GUI. In the first introduction to the GUI. I made this client side. As it says.

Client:

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) 
  
    -- 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 
-- now add our onClientGUIClick event to the button we just created 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),  
    function () 
        -- create the log in window and its components 
        createLoginWindow() 
  
        -- 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 hasnt been properly created, tell the player 
            outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") 
            end  
  
        -- enable the players 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 
) 
  
-- create the function and define the 'button' and 'state' parameters 
-- (these are passed automatically by onClientGUIClick) 
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 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 

and server:

local spawnX, spawnY, spawnZ = 1959.55, -1714.46, 10 
function joinHandler() 
    spawnPlayer(source, spawnX, spawnY, spawnZ) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
    outputChatBox("Welcome to My Server", source) 
end 
addEventHandler("onPlayerJoin", getRootElement(), joinHandler)  
  
function createVehicleForPlayer(thePlayer, command, vehicleModel) 
    local x,y,z = getElementPosition(thePlayer) -- get the position of the player 
    x = x + 5 -- add 5 units to the x position 
    local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z) 
    -- check if the return value was ''false'' 
    if (createdVehicle == false) then 
        -- if so, output a message to the chatbox, but only to this player. 
        outputChatBox("Failed to create vehicle.",thePlayer) 
    end 
end 
addCommandHandler("createvehicle", createVehicleForPlayer) 
  
  
-- create our loginHandler function, with username and password parameters (passed from the client gui) 
function loginHandler(username,password) 
    -- check that the username and password are correct 
    if username == "user" and password == "apple" then 
        -- the player has successfully logged in, so spawn them 
        if (client) then 
            spawnPlayer(client, 1959.55, -1714.46, 10) 
            fadeCamera(client, true) 
                        setCameraTarget(client, client) 
            outputChatBox("Welcome to My Server.", client) 
        end 
    else 
        -- if the username or password are not correct, output a message to the player 
        outputChatBox("Invalid username and password. Please re-connect and try again.",client) 
        end          
end 
  
addEvent("submitLogin",true) 
addEventHandler("submitLogin",root,loginHandler) 

I'm hosting my private server via serverFFS. And it says that i have to create a folder in resources with a name Client. And inside that folder a gui.lua and meta.xml. I did exactly what it says. And for server i just puted the .zip file in resources. As it says. But when i do "refresh" in the console. The .zip i puted in resources/client doesn't show up. So basicly. The server-side script is working fine but i can't even start the client-side script. I hope someone could help me out. And sorry for so much words :P.

Ty.

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