External Posted December 2, 2016 Share Posted December 2, 2016 GUIEditor = { gridlist = {}, button = {}, edit = {} } local GUItext = {} local Admin = {} function PGUI() local screenW, screenH = guiGetScreenSize() bla = guiCreateWindow((screenW - 371) / 2, (screenH - 557) / 2, 371, 557, "bla bla ", false) guiWindowSetMovable(bla, false) guiWindowSetSizable(bla, false) GUIEditor.gridlist[1] = guiCreateGridList(12, 40, 349, 463, false, bla) local column = guiGridListAddColumn(GUIEditor.gridlist[1], "Player Name", 0.5) local column2 = guiGridListAddColumn(GUIEditor.gridlist[1], "Admin Name", 0.5) GUIEditor.edit[1] = guiCreateEdit(10, 513, 171, 34, "", false, bla) GUIEditor.button[1] = guiCreateButton(191, 532, 80, 15, "Add", false, bla) GUIEditor.button[2] = guiCreateButton(281, 532, 80, 15, "Remove", false, bla) GUIEditor.button[3] = guiCreateButton(281, 19, 80, 15, "Close", false, bla) showCursor(true) addEventHandler( "onClientGUIClick", GUIEditor.button[3], Close, false ) addEventHandler( "onClientGUIClick", GUIEditor.button[1], AddIntoGridList, false ) addEventHandler( "onClientGUIClick", GUIEditor.button[2], RemoveFromGridList, false ) guiGridListAddRow( GUIEditor.gridlist[1] ) end addCommandHandler("bla", PGUI) function Close() guiSetVisible( bla, false) showCursor(false) end function AddIntoGridList() local row = guiGridListAddRow( GUIEditor.gridlist[1] ) if guiGetText(GUIEditor.edit[1]) == "" then outputChatBox("You have to fill the TextBox", 255, 0, 0) else local text = guiGetText( GUIEditor.edit[1] ) guiGridListSetItemText( GUIEditor.gridlist[1], row, 1, text, false, false ) guiGridListSetItemText( GUIEditor.gridlist[1], row, 2, getPlayerName(getLocalPlayer()), false, false ) table.insert(GUItext, text) local AdminName = getPlayerName(getLocalPlayer()) table.insert(Admin, AdminName) outputChatBox("The row was added successfully!", 0, 220, 0) end end function RemoveFromGridList() local selected = guiGridListGetSelectedItem( GUIEditor.gridlist[1] ) guiGridListRemoveRow( GUIEditor.gridlist[1], selected ) table.remove(GUItext, selected) table.remove(Admin, selected) outputChatBox("The row was removed successfully!", 255, 0 , 0) end function cmd() for i=1, #GUItext do outputChatBox("GUItext: " .. GUItext[i], 255, 20, 147, true) end for i=1, #Admin do outputChatBox("Admin: " .. Admin[i], 255, 20, 147, true) end end addCommandHandler("bls", cmd) Here is my code. I want to load the data in the tables once I open the GUI (Each name in a separate row) I save the text in the textbox by pressing on 'add' button Link to comment
shaio Posted December 2, 2016 Share Posted December 2, 2016 (edited) Try this instead, it will list ALL admins and ALL players and it updates when a player joins or leaves. Maybe there is a better way to do this, but this is what I got off of the top of my head. If you want I'll make a command so that you can add players to tables as well and display them that way.. Good luck m8. GUIEditor = { gridlist = {}, button = {}, edit = {} } local GUItext = {} local Admin = {} local root = getRootElement() local admins = {} local regularPlayers = {} for i,v in pairs(getElementsByType("player")) do local acc = getAccountName(getPlayerAccount(v)) if isObjectInAclGroup("user."..acc,aclGetGroup("Moderator")) or isObjectInAclGroup("user."..acc,aclGetGroup("SuperModerator")) or isObjectInAclGroup("user."..acc,aclGetGroup("Admin")) or isObjectInAclGroup("user."..acc,aclGetGroup("Console")) then table.insert(admins,{name = getPlayerName(v)}) else table.insert(regularPlayers,{name = getPlayerName(v)}) end end addEventHandler("onClientPlayerJoin",root,function() local acc = getAccountName(getPlayerAccount(source)) if isObjectInAclGroup("user."..acc,aclGetGroup("Moderator")) or isObjectInAclGroup("user."..acc,aclGetGroup("SuperModerator")) or isObjectInAclGroup("user."..acc,aclGetGroup("Admin")) or isObjectInAclGroup("user."..acc,aclGetGroup("Console")) then table.insert(admins,{name = getPlayerName(source)}) else table.insert(regularPlayers,{name = getPlayerName(source)}) end end) addEventHandler("onClientPlayerQuit",root,function() admins = {} regularPlayers = {} for i,plr in pairs(getElementsByType("player")) do local acc = getAccountName(getPlayerAccount(plr)) if isObjectInAclGroup("user."..acc,aclGetGroup("Moderator")) or isObjectInAclGroup("user."..acc,aclGetGroup("SuperModerator")) or isObjectInAclGroup("user."..acc,aclGetGroup("Admin")) or isObjectInAclGroup("user."..acc,aclGetGroup("Console")) then table.insert(admins,{name = getPlayerName(plr)}) else table.insert(regularPlayers,{name = getPlayerName(plr)}) end end end) function PGUI() local screenW, screenH = guiGetScreenSize() bla = guiCreateWindow((screenW - 371) / 2, (screenH - 557) / 2, 371, 557, "bla bla ", false) guiWindowSetMovable(bla, false) guiWindowSetSizable(bla, false) GUIEditor.gridlist[1] = guiCreateGridList(12, 40, 349, 463, false, bla) local column = guiGridListAddColumn(GUIEditor.gridlist[1], "Player Name", 0.5) local column2 = guiGridListAddColumn(GUIEditor.gridlist[1], "Admin Name", 0.5) for i,plr in pairs(regularPlayers) do guiGridListAddRow(column1,plr.name) end for i,admin in pairs(admins) do guiGridListAddRow(column1,admin.name) end GUIEditor.edit[1] = guiCreateEdit(10, 513, 171, 34, "", false, bla) GUIEditor.button[1] = guiCreateButton(191, 532, 80, 15, "Add", false, bla) GUIEditor.button[2] = guiCreateButton(281, 532, 80, 15, "Remove", false, bla) GUIEditor.button[3] = guiCreateButton(281, 19, 80, 15, "Close", false, bla) showCursor(true) addEventHandler( "onClientGUIClick", GUIEditor.button[3], Close, false ) addEventHandler( "onClientGUIClick", GUIEditor.button[1], AddIntoGridList, false ) addEventHandler( "onClientGUIClick", GUIEditor.button[2], RemoveFromGridList, false ) guiGridListAddRow( GUIEditor.gridlist[1] ) end addCommandHandler("bla", PGUI) Just tested that code, it wont work, but It would if you were to run some server side events. Edited December 2, 2016 by shaio Link to comment
pa3ck Posted December 2, 2016 Share Posted December 2, 2016 If I understand correctly, you want to keep the text when closing - reopening the GUI? If so, this will do exactly that, put this inside the PGUI function: if #GUItext > 0 then for i = 1, #GUItext do local row = guiGridListAddRow( GUIEditor.gridlist[1] ) guiGridListSetItemText( GUIEditor.gridlist[1], row, 1, GUItext[i], false, false ) guiGridListSetItemText( GUIEditor.gridlist[1], row, 2, Admin[i], false, false ) end end Just so you know, only the local player will see the text. 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