megaman54 Posted October 16, 2011 Share Posted October 16, 2011 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
Castillo Posted October 16, 2011 Share Posted October 16, 2011 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
megaman54 Posted October 16, 2011 Author Share Posted October 16, 2011 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
Castillo Posted October 16, 2011 Share Posted October 16, 2011 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
megaman54 Posted October 16, 2011 Author Share Posted October 16, 2011 Yes, thanks man, it works perfectly now! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now