Jump to content

[Help] Triggering Client Sided Event (Login Panel)


Om.

Recommended Posts

Debug Error: WARNING: [om]/ERPcore/server.lua:37: Bad argument @ 'triggerClientEvent' [Expected element at argument 2, got nil]

Client:

  
    -- Register Panel GUI 
    function registerGUI()  
        window = guiCreateWindow(500, 310, 329, 236, "MTA ERP - Login System", false) 
        guiWindowSetSizable(window, false) 
        guiSetVisible(window, false) 
        username = guiCreateLabel(9, 36, 63, 15, "Username", false, window) 
        guiSetFont(username, "default-bold-small") 
        password = guiCreateLabel(9, 90, 63, 15, "Password", false, window) 
        guiSetFont(password, "default-bold-small") 
        userInput = guiCreateEdit(87, 27, 218, 34, "", false, window) 
        passInput = guiCreateEdit(87, 80, 218, 34, "", false, window) 
        guiEditSetMasked(passInput, true) 
        email = guiCreateLabel(9, 142, 63, 15, "Email", false, window) 
        guiSetFont(email, "default-bold-small") 
        emailInput = guiCreateEdit(87, 133, 218, 34, "", false, window) 
        register = guiCreateButton(15, 189, 132, 37, "Register", false, window) 
        guiSetFont(register, "default-bold-small") 
        buttonCan = guiCreateButton(167, 189, 132, 37, "Close", false, window) 
        guiSetFont(buttonCan, "default-bold-small")     
    end 
    addEventHandler("onClientResourceStart", getRootElement(), registerGUI) 
     
    -- Login Panel GUI 
     
    function loginGUI() 
        loginwindow = guiCreateWindow(372, 180, 629, 519, "ERP:MTA - Login Panel", false) 
        guiWindowSetSizable(loginwindow, false) 
        guiSetVisible(loginwindow, false) 
        usernameLable = guiCreateLabel(24, 39, 181, 58, "Username", false, loginwindow) 
        guiSetFont(usernameLable, "sa-header") 
        passwordLable = guiCreateLabel(24, 120, 181, 58, "Password", false, loginwindow) 
        guiSetFont(passwordLable, "sa-header") 
        username = guiCreateEdit(235, 42, 366, 55, "", false, loginwindow) 
        password = guiCreateEdit(235, 123, 366, 55, "", false, loginwindow) 
        guiEditSetMasked(password, true) 
        clickOnlogin = guiCreateButton(442, 199, 149, 42, "Login", false, loginwindow) 
        clickOnRegister = guiCreateButton(245, 199, 149, 42, "Register", false, loginwindow) 
        clickOnGuide = guiCreateButton(46, 199, 149, 42, "Server Guide", false, loginwindow) 
        stats = guiCreateMemo(16, 254, 592, 248, "", false, loginwindow)     
    end 
    addEventHandler("onClientResourceStart", getRootElement(), loginGUI) 
  
  
  
    -- Show login panel when you connect to the server. 
    function openDemGui(thePlayer) 
    guiSetVisible(loginwindow, true) 
    showCursor(true) 
    showChat(false) 
    guiMemoSetReadOnly(stats, true) 
    end 
    addEvent("nobfokopenlogin", true) 
    addEventHandler("nobfokopenlogin", resourceRoot, openDemGui) 
     
    -- Logs into account 
    addEventHandler ( 'onClientGUIClick', root, 
    function () 
        if (source == clickOnlogin) then 
            if pass ~= nil or pass ~= "" or user ~= nil or user ~= "" then 
            user = guiGetText(username) 
            pass = guiGetText(password) 
            triggerServerEvent("loginPlayer", getRootElement(), user, pass) 
            else  
            outputChatBox("Please enter username & password") 
        end 
    end 
end 
) 
     
    -- Registers an account. 
        addEventHandler ( 'onClientGUIClick', root, 
    function () 
        if (source == register) then 
            if user ~= nil or user ~= "" or pass ~= nil or pass ~= "" then 
            user = guiGetText(userInput) 
            pass = guiGetText(passInput) 
            triggerServerEvent("registerPlayer", getRootElement(), user, pass) 
            else  
            outputChatBox("Please enter username & password") 
        end 
    end 
end 
) 
     
    -- Register Player Login GUI 
    addEventHandler ( 'onClientGUIClick', root, 
    function () 
        if (source == clickOnRegister) then 
        guiSetVisible(window, true) 
        closeLoginGUI() 
        showCursor(true)             
end 
    end 
) 
  
  
    function closeLoginGUI()  
    guiSetVisible(loginwindow, false) 
    end 
    addEvent("closeLoginGUI", true) 
    addEventHandler("closeLoginGUI", getRootElement(), closeLoginGUI) 
     
    function closeRegisterGUI()  
    guiSetVisible(window, false) 
    showCursor(false) 
    end 
    addEvent("closeRegisterGUI", true) 
    addEventHandler("closeRegisterGUI", getRootElement(), closeRegisterGUI) 
     
     
    -- Closing GUI from "Button Click" 
addEventHandler ( 'onClientGUIClick', root, 
    function () 
        if (source == buttonCan) then 
            guiSetVisible (window, false) 
            showCursor(true) 
            guiSetVisible(loginwindow, true) 
        end 
    end 
) 
  
  
  
  

Server:

function loginPlayer(username, password) 
    local account = getAccount(username, password) 
    if user ~= nil or user ~= "" or pass ~= nil or pass ~= "" then 
    if (account ~= false) then 
    logIn(client, account, password) 
    triggerClientEvent("closeLoginGUI", client) 
    showCursor(client, false) 
    showChat(client, true) 
    else 
        outputChatBox("Invalid username & password!", client, 255, 0, 0) 
        end 
    else 
        outputChatBox("Please enter username and password.", client) 
    end 
end 
    addEvent("loginPlayer", true) 
    addEventHandler("loginPlayer", getRootElement(), loginPlayer) 
  
 function createAccount(username, password) 
    if (password ~= "" and password ~= nil and username ~= "" and username ~= nil) then 
    local addedAccount = addAccount(username, password) 
    if (addedAccount) then 
    outputChatBox("You have been successfully registered and logged in!", client) 
    loginPlayer(username, password) 
    triggerClientEvent("closeRegisterGUI", client) 
    else 
    outputChatBox("An account with your username is already registered.", client) 
    end 
        else 
    outputChatBox("Please enter username and password.", client) 
    end 
end 
addEvent("registerPlayer", true) 
addEventHandler("registerPlayer", getRootElement(), createAccount)  
  
function showGUI()  
triggerClientEvent("nobfokopenlogin", client) 
fadeCamera(source, true, 5) 
setCameraMatrix(source, 1468.8785400391, -919.25317382813, 100.153465271, 1468.388671875, -918.42474365234, 99.881813049316) 
end 
addEventHandler("onPlayerJoin", getRootElement(), showGUI) 
  
addEventHandler("onResourceStart", resourceRoot, 
    function() 
        setGameType ("FTA: v1.0.0") 
        resetMapInfo() 
        for _, player in ipairs (getElementsByType("player")) do 
        kickPlayer(player, client) 
     end 
    end 
) 
  
    function createTeams() 
    admin = createTeam("Admin", 0, 255, 0) 
    noteam = createTeam("Unemployed", 255, 255, 0) 
    end 
    addEventHandler("onResourceStart", resourceRoot, createTeams) 
     
exports.scoreboard:addScoreboardColumn('Country')  
function showcountry() 
local flag = exports.admin:getPlayerCountry ( source ) 
if flag then 
setElementData(source,"Country",flag) 
    end 
end 
addEventHandler("onPlayerJoin",getRootElement(),showcountry) 
  
function showPos(thePlayer) 
x,y,z = getElementPosition(thePlayer) 
outputChatBox("X, Y, Z: " .. x .. "," .. y .. "," .. z, client) 
end 
addCommandHandler("pos", showPos) 
  
function onLogout () 
cancelEvent() 
outputChatBox("Logout command has been disabled due to abuse.", client, 255, 0, 0) 
end 
addEventHandler ("onPlayerLogout", getRootElement(), onLogout) 
  
function chatbox(text, msgtype) 
if (msgtype == 0) then 
cancelEvent() 
local name = getPlayerName(source) 
local r, g, b = getPlayerNametagColor(source) 
local country = exports.admin:getPlayerCountry(source) 
outputChatBox("["..country.."] " .. name .. ": "..text, client, r, g, b) 
end 
end 
addEventHandler("onPlayerChat", root, chatbox) 

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