Jump to content

[Help] Table & GUI


External

Recommended Posts

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
1 hour ago, External said:

What?

That's not even related to tables

ty :
 

    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] )
			
			    if #GUItext > 0 then -- by pa3ck
    	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	

        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] .."\nAdmin: " .. Admin[i], 255, 20, 147, true)
          end
         end
    addCommandHandler("bls", cmd)

 

Link to comment
51 minutes ago, medo7 said:

ty :
 


    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] )
			
			    if #GUItext > 0 then -- by pa3ck
    	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	

        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] .."\nAdmin: " .. Admin[i], 255, 20, 147, true)
          end
         end
    addCommandHandler("bls", cmd)

 

aww thanks mate

  • Like 1
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...