Jump to content

Need help in GUI


Price.

Recommended Posts

Well this is just simple gui, I'am trying to add All players in Team "Police" to appear in the grid list but still don't know how so far, help ?

local GUIEditor = { 
    gridlist = {}, 
    window = {}, 
    scrollbar = {}, 
    button = {} 
} 
  
addEventHandler("onClientResourceStart", resourceRoot, 
        function () 
        GUIEditor.window[1] = guiCreateWindow(283, 263, 282, 352, "", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
  
        GUIEditor.button[1] = guiCreateButton(193, 36, 79, 44, "/gochief", false, GUIEditor.window[1]) 
        GUIEditor.button[2] = guiCreateButton(192, 100, 80, 36, "Sack", false, GUIEditor.window[1]) 
        GUIEditor.button[3] = guiCreateButton(191, 159, 81, 41, "UnSack", false, GUIEditor.window[1]) 
        GUIEditor.button[4] = guiCreateButton(192, 228, 80, 39, "Place APB", false, GUIEditor.window[1]) 
        GUIEditor.button[5] = guiCreateButton(188, 294, 84, 36, "Close Window", false, GUIEditor.window[1]) 
        GUIEditor.gridlist[1] = guiCreateGridList(9, 23, 172, 319, false, GUIEditor.window[1]) 
        edit = guiCreateEdit(9,406,182,40,"",false,GUIEditor.window[1]) 
        guiGridListSetSelectionMode(GUIEditor.gridlist[1],1) 
        column = guiGridListAddColumn(GUIEditor.gridlist[1],"Players",0.-- s8) -->
        GUIEditor.scrollbar[1] = guiCreateScrollBar(158, 4, 14, 315, false, false, GUIEditor.gridlist[1]) 
        
        guiSetVisible(GUIEditor.window[1], false) 
        showCursor(false) 
        end 
) 
  
function togglePCPanel()        
        if (guiGetVisible(GUIEditor.window[1])) then 
                guiSetVisible(GUIEditor.window[1], false) 
                showCursor(false) 
        else   
                guiSetVisible(GUIEditor.window[1], true) 
                showCursor(true) 
        end 
end 
addCommandHandler("pcpanel",togglePCPanel) 
  
addEventHandler("onClientGUIClick", root, 
        function () 
                if (source == GUIEditor.button[2]) then 
                         triggerServerEvent ("sackbutton", getRootElement(), localPlayer) 
                elseif (source == GUIEditor.button[3]) then 
                        triggerServerEvent("Unsackbutton", getRootElement(), localPlayer) 
                end 
        end 
) 
  
  
addEventHandler("onClientGUIClick", root, 
  function () 
                if (source == GUIEditor.button[5]) then 
                        if (guiGetVisible(GUIEditor.window[1])) then 
                guiSetVisible(GUIEditor.window[1], false) 
                showCursor(false) 
                end 
                end 
        end 
) 
  
addEventHandler("onClientGUIClick", root, 
        function () 
                if (source == GUIEditor.button[1]) then 
                         triggerServerEvent ("gochief", getRootElement(), localPlayer) 
                end 
        end 
) 
  
function text() 
 for id, player in ipairs (getElementsByType("player")) do 
    guiGridListSetItemText(GUIEditor.gridlist[1], guiGridListAddRow(GUIEditor.gridlist[1]), column, getPlayerName(player), false, false) 
    end 
 end 

Look at the last function i tried to make them appear in gridlist but not working, remember i need people who are in Team "Police" Names to appear in gridlist,

Link to comment

Actually I've tried doing this and changed a bit in the code

------>> 
-- GUI 
------->> 
  
--Window 
local sWidth,sHeight = guiGetScreenSize() 
local Width,Height = 600,500 
local X = (sWidth/2) - (Width/2) 
local Y = (sHeight/2) - (Height/2) 
      
 function theGUI() 
        GUIEditor.window[1] = guiCreateWindow(283, 263, 282, 352, "", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
  
        gochiefbtton = guiCreateButton(193, 36, 79, 44, "/gochief", false, GUIEditor.window[1]) 
        sackbutton = guiCreateButton(192, 100, 80, 36, "Sack", false, GUIEditor.window[1]) 
        unsackbutton = guiCreateButton(191, 159, 81, 41, "UnSack", false, GUIEditor.window[1]) 
        placeAPBbutton  = guiCreateButton(192, 228, 80, 39, "Place APB", false, GUIEditor.window[1]) 
        closebutton  = guiCreateButton(188, 294, 84, 36, "Close Window", false, GUIEditor.window[1]) 
        grid  = guiCreateGridList(9, 23, 172, 319, false, GUIEditor.window[1]) 
        edit = guiCreateEdit(9,406,182,40,"",false,GUIEditor.window[1]) 
        guiGridListSetSelectionMode(grid,1) 
        column = guiGridListAddColumn(grid,"Players",0.-- s8) -->
        GUIEditor.scrollbar[1] = guiCreateScrollBar(158, 4, 14, 315, false, false, grid) 
        
        guiSetVisible(GUIEditor.window[1], false) 
        showCursor(false) 
        end 
         
      
      
--[[ Create a function to handle toggling of PC GUI ]]-- 
function toggleGUI( source ) 
        if not guiGetVisible( GUIEditor.window[1] ) then 
                showCursor( true ) 
                guiSetVisible( GUIEditor.window[1], true ) 
                guiSetInputEnabled( true ) 
                putAllPlayersInList() 
        else 
                showCursor( false ) 
                guiSetVisible( GUIEditor.window[1], false ) 
                guiSetInputEnabled( false ) 
        end 
end  
addCommandHandler( "gochief", toggleGUI ) 
bindKey( "F7", "down", "pchief" ) 
  
function putAllPlayersInList() 
    guiGridListClear(grid) 
    for i,v in ipairs(getElementsByType("player")) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid,row,1,getPlayerName(v),false,false) 
        guiGridListSetItemColor(grid,row,1,0,255,0) 
    end 
end 
  
function closeGUI( button, state ) 
        if source ~=  GUIEditor.window[1] then 
                if button == "left" and state == "up" then 
                        guiSetVisible(  GUIEditor.window[1], false ) 
                        showCursor( false ) 
                end 
        end 
end 
addEventHandler( "onClientGUIClick", closebutton, closeGUI ) 
  
addEventHandler("onClientGUIClick",root, 
    function () 
        local sel = guiGridListGetSelectedItem(grid) 
        local text = guiGridListGetItemText(grid,sel,1) 
        if ( source == sackbutton ) then                                     -- sack 
            if ( sel ~= -1 ) then 
                triggerServerEvent("sackplr",localPlayer,text) 
            end 
        elseif ( source == unsackbutton ) then                                     -- Unsack 
            if ( sel ~= -1 ) then 
                triggerServerEvent("unsackplr",localPlayer,text) 
            end 
        elseif ( source == placeAPBbutton ) then                             --- APB 
            if ( sel ~= -1 ) then 
                                triggerServerEvent("onDes",localPlayer,text) 
                        end 
        elseif ( source == gochiefbtton ) then                              -- chief 
            if ( sel ~= -1 ) then 
                                triggerServerEvent("setteam",localPlayer,text) 
                        end 
        end 
    end 
) 
  

Still got 1 error @ line 65 , Bad argument @ 'addEventHandler'[Expected element at argument 2, got nil]

Link to comment
Actually I've tried doing this and changed a bit in the code
------>> 
-- GUI 
------->> 
  
--Window 
local sWidth,sHeight = guiGetScreenSize() 
local Width,Height = 600,500 
local X = (sWidth/2) - (Width/2) 
local Y = (sHeight/2) - (Height/2) 
      
 function theGUI() 
        GUIEditor.window[1] = guiCreateWindow(283, 263, 282, 352, "", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
  
        gochiefbtton = guiCreateButton(193, 36, 79, 44, "/gochief", false, GUIEditor.window[1]) 
        sackbutton = guiCreateButton(192, 100, 80, 36, "Sack", false, GUIEditor.window[1]) 
        unsackbutton = guiCreateButton(191, 159, 81, 41, "UnSack", false, GUIEditor.window[1]) 
        placeAPBbutton  = guiCreateButton(192, 228, 80, 39, "Place APB", false, GUIEditor.window[1]) 
        closebutton  = guiCreateButton(188, 294, 84, 36, "Close Window", false, GUIEditor.window[1]) 
        grid  = guiCreateGridList(9, 23, 172, 319, false, GUIEditor.window[1]) 
        edit = guiCreateEdit(9,406,182,40,"",false,GUIEditor.window[1]) 
        guiGridListSetSelectionMode(grid,1) 
        column = guiGridListAddColumn(grid,"Players",0.-- s8) -->
        GUIEditor.scrollbar[1] = guiCreateScrollBar(158, 4, 14, 315, false, false, grid) 
        
        guiSetVisible(GUIEditor.window[1], false) 
        showCursor(false) 
        end 
         
      
      
--[[ Create a function to handle toggling of PC GUI ]]-- 
function toggleGUI( source ) 
        if not guiGetVisible( GUIEditor.window[1] ) then 
                showCursor( true ) 
                guiSetVisible( GUIEditor.window[1], true ) 
                guiSetInputEnabled( true ) 
                putAllPlayersInList() 
        else 
                showCursor( false ) 
                guiSetVisible( GUIEditor.window[1], false ) 
                guiSetInputEnabled( false ) 
        end 
end  
addCommandHandler( "gochief", toggleGUI ) 
bindKey( "F7", "down", "pchief" ) 
  
function putAllPlayersInList() 
    guiGridListClear(grid) 
    for i,v in ipairs(getElementsByType("player")) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid,row,1,getPlayerName(v),false,false) 
        guiGridListSetItemColor(grid,row,1,0,255,0) 
    end 
end 
  
function closeGUI( button, state ) 
        if source ~=  GUIEditor.window[1] then 
                if button == "left" and state == "up" then 
                        guiSetVisible(  GUIEditor.window[1], false ) 
                        showCursor( false ) 
                end 
        end 
end 
addEventHandler( "onClientGUIClick", closebutton, closeGUI ) 
  
addEventHandler("onClientGUIClick",root, 
    function () 
        local sel = guiGridListGetSelectedItem(grid) 
        local text = guiGridListGetItemText(grid,sel,1) 
        if ( source == sackbutton ) then                                     -- sack 
            if ( sel ~= -1 ) then 
                triggerServerEvent("sackplr",localPlayer,text) 
            end 
        elseif ( source == unsackbutton ) then                                     -- Unsack 
            if ( sel ~= -1 ) then 
                triggerServerEvent("unsackplr",localPlayer,text) 
            end 
        elseif ( source == placeAPBbutton ) then                             --- APB 
            if ( sel ~= -1 ) then 
                                triggerServerEvent("onDes",localPlayer,text) 
                        end 
        elseif ( source == gochiefbtton ) then                              -- chief 
            if ( sel ~= -1 ) then 
                                triggerServerEvent("setteam",localPlayer,text) 
                        end 
        end 
    end 
) 
  

Still got 1 error @ line 65 , Bad argument @ 'addEventHandler'[Expected element at argument 2, got nil]

I don't see anything to handle or create the 'GUI' " function theGUI()" So Maybe u should to recheck on your code.

Link to comment

alright remove the function but still this error there

line 11: attempt to index global 'GUIEditor' (a nil value)

------>> 
-- GUI 
------->> 
  
--Window 
local sWidth,sHeight = guiGetScreenSize() 
local Width,Height = 600,500 
local X = (sWidth/2) - (Width/2) 
local Y = (sHeight/2) - (Height/2) 
      
        GUIEditor.window[1] = guiCreateWindow(283, 263, 282, 352, "", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
  
        gochiefbtton = guiCreateButton(193, 36, 79, 44, "/gochief", false, GUIEditor.window[1]) 
        sackbutton = guiCreateButton(192, 100, 80, 36, "Sack", false, GUIEditor.window[1]) 
        unsackbutton = guiCreateButton(191, 159, 81, 41, "UnSack", false, GUIEditor.window[1]) 
        placeAPBbutton  = guiCreateButton(192, 228, 80, 39, "Place APB", false, GUIEditor.window[1]) 
        closebutton  = guiCreateButton(188, 294, 84, 36, "Close Window", false, GUIEditor.window[1]) 
        grid  = guiCreateGridList(9, 23, 172, 319, false, GUIEditor.window[1]) 
        edit = guiCreateEdit(9,406,182,40,"",false,GUIEditor.window[1]) 
        guiGridListSetSelectionMode(grid,1) 
        column = guiGridListAddColumn(grid,"Players",30) 
        GUIEditor.scrollbar[1] = guiCreateScrollBar(158, 4, 14, 315, false, false, grid) 
        
        guiSetVisible(GUIEditor.window[1], false) 
        showCursor(false) 
        
      
      
--[[ Create a function to handle toggling of PC GUI ]]-- 
function toggleGUI( source ) 
        if not guiGetVisible( GUIEditor.window[1] ) then 
                showCursor( true ) 
                guiSetVisible( GUIEditor.window[1], true ) 
                guiSetInputEnabled( true ) 
                putAllPlayersInList() 
        else 
                showCursor( false ) 
                guiSetVisible( GUIEditor.window[1], false ) 
                guiSetInputEnabled( false ) 
        end 
end 
addCommandHandler( "gochief", toggleGUI ) 
bindKey( "F7", "down", "pchief" ) 
  
function putAllPlayersInList() 
    guiGridListClear(grid) 
    for i,v in ipairs(getElementsByType("player")) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid,row,1,getPlayerName(v),false,false) 
        guiGridListSetItemColor(grid,row,1,0,255,0) 
    end 
end 
  
function closeGUI( button, state ) 
        if source ~=  GUIEditor.window[1] then 
                if button == "left" and state == "up" then 
                        guiSetVisible(  GUIEditor.window[1], false ) 
                        showCursor( false ) 
                end 
        end 
end 
addEventHandler( "onClientGUIClick", closebutton, closeGUI ) 
  
addEventHandler("onClientGUIClick",root, 
    function () 
        local sel = guiGridListGetSelectedItem(grid) 
        local text = guiGridListGetItemText(grid,sel,1) 
        if ( source == sackbutton ) then                                     -- sack 
            if ( sel ~= -1 ) then 
                triggerServerEvent("sackplr",localPlayer,text) 
            end 
        elseif ( source == unsackbutton ) then                                     -- Unsack 
            if ( sel ~= -1 ) then 
                triggerServerEvent("unsackplr",localPlayer,text) 
            end 
        elseif ( source == placeAPBbutton ) then                             --- APB 
            if ( sel ~= -1 ) then 
                                triggerServerEvent("onDes",localPlayer,text) 
                        end 
        elseif ( source == gochiefbtton ) then                              -- chief 
            if ( sel ~= -1 ) then 
                                triggerServerEvent("setteam",localPlayer,text) 
                        end 
        end 
    end 
) 
  

Link to comment
instead editing the rest to GUI editor, could i just edit GUIEditor.window[1] to window = guicreatwindow ?

Yes but also u have to edit all the other arguments for sure just add the table.

** EDIT : ADD THIS IN THE TOP OF THE CODE :

local GUIEditor = { 
    gridlist = {}, 
    window = {}, 
    scrollbar = {}, 
    button = {} 
} 

Link to comment
------>> 
-- GUI 
------->> 
 local GUIEditor = { 
    gridlist = {}, 
    window = {}, 
    scrollbar = {}, 
    button = {} 
} 
--Window 
local sWidth,sHeight = guiGetScreenSize() 
local Width,Height = 600,500 
local X = (sWidth/2) - (Width/2) 
local Y = (sHeight/2) - (Height/2) 
      
        GUIEditor.window[1] = guiCreateWindow(283, 263, 282, 352, "", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
  
        gochiefbtton = guiCreateButton(193, 36, 79, 44, "/gochief", false, GUIEditor.window[1]) 
        sackbutton = guiCreateButton(192, 100, 80, 36, "Sack", false, GUIEditor.window[1]) 
        unsackbutton = guiCreateButton(191, 159, 81, 41, "UnSack", false, GUIEditor.window[1]) 
        placeAPBbutton  = guiCreateButton(192, 228, 80, 39, "Place APB", false, GUIEditor.window[1]) 
        closebutton  = guiCreateButton(188, 294, 84, 36, "Close Window", false, GUIEditor.window[1]) 
        grid  = guiCreateGridList(9, 23, 172, 319, false, GUIEditor.window[1]) 
        edit = guiCreateEdit(9,406,182,40,"",false,GUIEditor.window[1]) 
        guiGridListSetSelectionMode(grid,1) 
        column = guiGridListAddColumn(grid,"Players",30) 
        GUIEditor.scrollbar[1] = guiCreateScrollBar(158, 4, 14, 315, false, false, grid) 
        
        guiSetVisible(GUIEditor.window[1], false) 
        showCursor(false) 
        
      
      
--[[ Create a function to handle toggling of PC GUI ]]-- 
function toggleGUI( source ) 
        if not guiGetVisible( GUIEditor.window[1] ) then 
                showCursor( true ) 
                guiSetVisible( GUIEditor.window[1], true ) 
                guiSetInputEnabled( true ) 
                putAllPlayersInList() 
        else 
                showCursor( false ) 
                guiSetVisible( GUIEditor.window[1], false ) 
                guiSetInputEnabled( false ) 
        end 
end 
addCommandHandler( "gochief", toggleGUI ) 
bindKey( "F7", "down", "pchief" ) 
  
function putAllPlayersInList() 
    guiGridListClear(grid) 
    for i,v in ipairs(getElementsByType("player")) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid,row,1,getPlayerName(v),false,false) 
        guiGridListSetItemColor(grid,row,1,0,255,0) 
    end 
end 
  
function closeGUI( button, state ) 
        if source ~=  GUIEditor.window[1] then 
                if button == "left" and state == "up" then 
                        guiSetVisible(  GUIEditor.window[1], false ) 
                        showCursor( false ) 
                end 
        end 
end 
addEventHandler( "onClientGUIClick", closebutton, closeGUI ) 
  
addEventHandler("onClientGUIClick",root, 
    function () 
        local sel = guiGridListGetSelectedItem(grid) 
        local text = guiGridListGetItemText(grid,sel,1) 
        if ( source == sackbutton ) then                                     -- sack 
            if ( sel ~= -1 ) then 
                triggerServerEvent("sackplr",localPlayer,text) 
            end 
        elseif ( source == unsackbutton ) then                                     -- Unsack 
            if ( sel ~= -1 ) then 
                triggerServerEvent("unsackplr",localPlayer,text) 
            end 
        elseif ( source == placeAPBbutton ) then                             --- APB 
            if ( sel ~= -1 ) then 
                                triggerServerEvent("onDes",localPlayer,text) 
                        end 
        elseif ( source == gochiefbtton ) then                              -- chief 
            if ( sel ~= -1 ) then 
                                triggerServerEvent("setteam",localPlayer,text) 
                        end 
        end 
    end 
) 
  

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