Jump to content

Account Manager Script


megaman54

Recommended Posts

Hello! I'm trying to make a account manager with a ingame GUI but i'm stuck on the part where i must place the accounts to a gridlist. The error is: ERROR: Client triggered serverside event serverGetAccounts, but event is not added serverside

And the other problem is that it wont show the accounts in the list. So here is my code what i have created so far:

Serverside:

function getTheAccounts() 
    accountTable = getAccounts() 
    if(#accountTable == 0)then 
    outputDebugString("No accounts in database!") 
    else 
    triggerClientEvent("serverGivesAccounts", getResourceRootElement(getThisResource()), getRootElement(), accountTable) 
    end 
end 
addEvent("serverGetAccounts", true) 
addEventHandler("serverGetAccounts", getRootElement(), getTheAccounts) 

Clientside:

function createAccountWindow() 
mainWnd = guiCreateWindow(307, 256, 268, 361, "Account Manager", false) 
accountGrid = guiCreateGridList(9, 23, 249, 228, false, mainWnd) 
guiGridListSetSelectionMode(accountGrid, 2) 
refreshButton = guiCreateButton(12, 258, 91, 26, "Refresh", false, mainWnd) 
guiGridListAddColumn(accountGrid, "Account Name", 0.3) 
guiSetVisible(mainWnd, true) 
showCursor(true) 
end 
addCommandHandler("accountmanager", createAccountWindow) 
  
function refreshGridlist(accountTable) 
    guiGridListClear(accountGrid) 
    triggerServerEvent("serverGetAccounts", getRootElement()) 
    for index, accounts in ipairs(getElementsByType("account")) do 
        local row = guiGridListAddRow(accountGrid) 
        guiGridListSetItemText(accountGrid, row, 1, tostring(accountTable), false, false) 
    end 
end 
addEvent("serverGivesAccounts", true) 
addEventHandler("serverGivesAccounts", getRootElement(), refreshGridlist) 
addCommandHandler("refac", refreshGridlist) 

:?

Link to comment

Well, I can see that this is a total mess, first, getAccounts() doesn't return the account name, but the account himself, so you need to make a temp table and store the account name (I guess you want the account name), second, you trigger the event in the refresh? that's HIGHLY wrong as it will never trigger for the first time, and that would be useless, also, you send the accounts table but then you never use it? "getElementsByType("account")"? what is that?

-- client side:

function createAccountWindow() 
mainWnd = guiCreateWindow(307, 256, 268, 361, "Account Manager", false) 
accountGrid = guiCreateGridList(9, 23, 249, 228, false, mainWnd) 
guiGridListSetSelectionMode(accountGrid, 2) 
refreshButton = guiCreateButton(12, 258, 91, 26, "Refresh", false, mainWnd) 
guiGridListAddColumn(accountGrid, "Account Name", 0.3) 
guiSetVisible(mainWnd, true) 
showCursor(true) 
triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) 
end 
addCommandHandler("accountmanager", createAccountWindow) 
  
function refreshGridlist(accountTable) 
    guiGridListClear(accountGrid) 
    for index, account in ipairs(accountTable) do 
        local row = guiGridListAddRow(accountGrid) 
        guiGridListSetItemText(accountGrid, row, 1, tostring(account), false, false) 
    end 
end 
addEvent("serverGivesAccounts", true) 
addEventHandler("serverGivesAccounts", getRootElement(), refreshGridlist) 
  
addCommandHandler("refac", function () triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) end) 

-- server side:

function getTheAccounts(client) 
    accountTable = getAccounts() 
    local tempTable = {} 
    if(#accountTable == 0)then 
    outputDebugString("No accounts in database!") 
    else 
    for index, account in pairs(accountTable) do 
         table.insert(tempTable, getAccountName(account)) 
    end 
    triggerClientEvent(client, "serverGivesAccounts", client, tempTable) 
    end 
end 
addEvent("serverGetAccounts", true) 
addEventHandler("serverGetAccounts", getRootElement(), getTheAccounts) 

Link to comment

Ok, i made a delete button but now it gives this warning when i select account from the list and press delete: WARNING: accountManager\client.lua:21: Bad Argument @ 'triggerServerEvent' [Expected element at argument 2, got string 'testaccount']

Clientside code:

function buttonHandler() 
    if(source == refreshButton)then 
    triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) 
    elseif(source == deleteButton)then 
    local row,col = guiGridListGetSelectedItem(accountGrid) 
    if row and col and row ~= -1 and col ~= -1 then 
    local targetAccount = guiGridListGetItemText(accountGrid, row, 1) 
    triggerServerEvent("requestAccountDelete", targetAccount) 
    end 
    end 
end 
addEventHandler("onClientGUIClick", getResourceRootElement(getThisResource()), buttonHandler) 

(Only the button handling function)

Serverside:

function deleteAccount(targetAccount) 
    removeAccount(targetAccount) 
end 
addEvent("requestAccountDelete", true) 
addEventHandler("requestAccountDelete", getRootElement(), deleteAccount) 

Link to comment
function buttonHandler() 
    if(source == refreshButton)then 
    triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) 
    elseif(source == deleteButton)then 
    local row,col = guiGridListGetSelectedItem(accountGrid) 
    if row and col and row ~= -1 and col ~= -1 then 
    local targetAccount = guiGridListGetItemText(accountGrid, row, 1) 
    triggerServerEvent("requestAccountDelete", localPlayer, targetAccount) 
    end 
    end 
end 
addEventHandler("onClientGUIClick", getResourceRootElement(getThisResource()), buttonHandler) 

function deleteAccount(targetAccount) 
if getAccount(targetAccount) then 
    removeAccount(getAccount(targetAccount)) 
    end 
end 
addEvent("requestAccountDelete", true) 
addEventHandler("requestAccountDelete", getRootElement(), deleteAccount) 

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