Jump to content

About Search in the grid list


Annas

Recommended Posts

Hello community Members, as what the title says , About Search in the grid list

When player write in Edit

it search in the grid list bellow.

(Search for Text in the Grid list)

D6m2SSb.png

I mean , when i type Example "Rules" in the Edit , it only shows "Rules" in the Grid List.

and when there is nothing in the edit , it shows every text in the Grid List.

Help me and thx.

Link to comment
addEventHandler("onClientGUIChanged", gridlistSearchbar, function(theElement) 
   local rowsToRemove = {} 
   local counter = 0 
   local searchFor = guiGetText(theElement) 
   local rows = guiGridListGetRowCount(gridlist) 
   for i=1, rows do 
      rowText = guiGridListGetItemText(gridlist, i, 1) 
      if not (string.match(rowText, searchFor) then 
         rowsToRemove[counter] = i 
         counter = counter + 1 
      end 
   end 
   for i,v in rowsToRemove do 
      guiGridListRemoveRow(gridlist, v) 
      for i, v in rowsToRemove do 
         rowsToRemove[i] = rowsToRemove[i] - 1 
      end 
   end 
end) 

I'm by far not sure if this will work but this is the way I'd try to do it. I'm not that good in advanced LUA tho.

Link to comment
addEventHandler("onClientGUIChanged", gridlistSearchbar, function(theElement) 
   local rowsToRemove = {} 
   local counter = 0 
   local searchFor = guiGetText(theElement) 
   local rows = guiGridListGetRowCount(gridlist) 
   for i=1, rows do 
      rowText = guiGridListGetItemText(gridlist, i, 1) 
      if not (string.match(rowText, searchFor) then 
         rowsToRemove[counter] = i 
         counter = counter + 1 
      end 
   end 
   for i,v in rowsToRemove do 
      guiGridListRemoveRow(gridlist, v) 
      for i, v in rowsToRemove do 
         rowsToRemove[i] = rowsToRemove[i] - 1 
      end 
   end 
end) 

I'm by far not sure if this will work but this is the way I'd try to do it. I'm not that good in advanced LUA tho.

Not Working..

Here is my Client Side script

local windowTitle = "CST Rules, Documentation and Answers" 
  
GUIEditor = { 
    button = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        local sx, sy = guiGetScreenSize() 
        rule = guiCreateWindow((sx/2)-400, (sy/2)-300, 800, 600, windowTitle, false) 
  
        guiWindowSetSizable(rule, false) 
        guiSetAlpha (rule, 1) 
      
        grid = guiCreateGridList(9, 64, 781, 164, false, rule) 
        guiGridListSetSelectionMode(grid, 1) 
        guiGridListSetSortingEnabled(grid, false) 
        colum = guiGridListAddColumn(grid, "Question", 0.9) 
        for index, val in pairs(griditem) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row, colum, val[1], false, false) 
        end 
        guiSetVisible( rule, false ) 
        memo = guiCreateMemo(3, 238, 700, 350, "Select a Question above to learn about the game.", false, rule) 
        guiMemoSetReadOnly(memo, true) 
        ask = guiCreateButton(713, 238, 78, 89, "Ask a question that isn't answered here", false, rule) 
        close = guiCreateButton(713, 532, 78, 55, "Close", false, rule)  
        search = guiCreateEdit(10, 24, 780, 35, "", false, rule)  
        --combo = guiCreateComboBox(597, 100, 171, 29, "", false, rule)   
        --for i, k in pairs ( rulesToFile ) do 
        --guiComboBoxAddItem ( combo, i ) 
        --end 
        guiMemoSetReadOnly (memo, true) 
        addEventHandler("onClientGUIClick", grid, clickedGridlist, false) 
        addEventHandler("onClientGUIClick", close, function () guiSetVisible(rule, false) showCursor(false) end, false) 
        addEventHandler("onClientGUIClick", ask, showSupports, false) 
    end 
) 
  
addEventHandler("onClientGUIChanged", search, function() 
   local rowsToRemove = {} 
   local counter = 0 
   local searchFor = guiGetText(search) 
   local rows = guiGridListGetRowCount(grid) 
   for i=1, rows do 
      rowText = guiGridListGetItemText(grid, i, 1) 
      if not (string.match(rowText, searchFor)) then 
         rowsToRemove[counter] = i 
         counter = counter + 1 
      end 
   end 
   for i,v in rowsToRemove do 
      guiGridListRemoveRow(grid, v) 
      for i, v in rowsToRemove do 
         rowsToRemove[i] = rowsToRemove[i] - 1 
      end 
   end 
end 

Link to comment
local rows = {"thing 1","thing 2"} 
  
addEventHandler("onClientGUIChanged", search, 
function() 
    local text = guiGetText(source) 
    guiGridListClear(gridlist) 
    for k,v in ipairs(rows) do 
        if v:find(text) then 
            local row = guiGridListAddRow(gridlist) 
            guiGridListSetItemText (gridlist,row,column,v,false,false) 
        end 
    end 
end 

Link to comment
local rows = {"thing 1","thing 2"} 
  
addEventHandler("onClientGUIChanged", search, 
function() 
    local text = guiGetText(source) 
    guiGridListClear(gridlist) 
    for k,v in ipairs(rows) do 
        if v:find(text) then 
            local row = guiGridListAddRow(gridlist) 
            guiGridListSetItemText (gridlist,row,column,v,false,false) 
        end 
    end 
end 

Not working :/ , please fellow my code

Link to comment
local windowTitle = "CST Rules, Documentation and Answers" 
  
GUIEditor = { 
    button = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        local sx, sy = guiGetScreenSize() 
        rule = guiCreateWindow((sx/2)-400, (sy/2)-300, 800, 600, windowTitle, false) 
  
        guiWindowSetSizable(rule, false) 
        guiSetAlpha (rule, 1) 
      
        grid = guiCreateGridList(9, 64, 781, 164, false, rule) 
        guiGridListSetSelectionMode(grid, 1) 
        guiGridListSetSortingEnabled(grid, false) 
        colum = guiGridListAddColumn(grid, "Question", 0.9) 
        for index, val in pairs(griditem) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row, colum, val[1], false, false) 
        end 
        guiSetVisible( rule, false ) 
        memo = guiCreateMemo(3, 238, 700, 350, "Select a Question above to learn about the game.", false, rule) 
        guiMemoSetReadOnly(memo, true) 
        ask = guiCreateButton(713, 238, 78, 89, "Ask a question that isn't answered here", false, rule) 
        close = guiCreateButton(713, 532, 78, 55, "Close", false, rule) 
        search = guiCreateEdit(10, 24, 780, 35, "", false, rule) 
        --combo = guiCreateComboBox(597, 100, 171, 29, "", false, rule)   
        --for i, k in pairs ( rulesToFile ) do 
        --guiComboBoxAddItem ( combo, i ) 
        --end 
        guiMemoSetReadOnly (memo, true) 
        addEventHandler("onClientGUIClick", grid, clickedGridlist, false) 
        addEventHandler("onClientGUIClick", close, function () guiSetVisible(rule, false) showCursor(false) end, false) 
        addEventHandler("onClientGUIClick", ask, showSupports, false) 
    end 
) 
  
addEventHandler("onClientGUIChanged", search,  
function() 
    local text = guiGetText(search) 
    local sItems = { } 
    for i, v in pairs(griditem) do 
        if not (text == "" ) then 
            if (string.find(string.upper(v[1]), string.upper(text), 1, true)) then 
                table.insert(sItems, v[1]) 
            end 
        else 
            table.insert(sItems, v[1]) 
        end 
    end 
    guiGridListClear(grid) 
    for i, v in pairs(sItems) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row, colum, tostring(v), false, false) 
    end 
end 

Link to comment
local windowTitle = "CST Rules, Documentation and Answers" 
  
GUIEditor = { 
    button = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        local sx, sy = guiGetScreenSize() 
        rule = guiCreateWindow((sx/2)-400, (sy/2)-300, 800, 600, windowTitle, false) 
  
        guiWindowSetSizable(rule, false) 
        guiSetAlpha (rule, 1) 
      
        grid = guiCreateGridList(9, 64, 781, 164, false, rule) 
        guiGridListSetSelectionMode(grid, 1) 
        guiGridListSetSortingEnabled(grid, false) 
        colum = guiGridListAddColumn(grid, "Question", 0.9) 
        for index, val in pairs(griditem) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row, colum, val[1], false, false) 
        end 
        guiSetVisible( rule, false ) 
        memo = guiCreateMemo(3, 238, 700, 350, "Select a Question above to learn about the game.", false, rule) 
        guiMemoSetReadOnly(memo, true) 
        ask = guiCreateButton(713, 238, 78, 89, "Ask a question that isn't answered here", false, rule) 
        close = guiCreateButton(713, 532, 78, 55, "Close", false, rule) 
        search = guiCreateEdit(10, 24, 780, 35, "", false, rule) 
        --combo = guiCreateComboBox(597, 100, 171, 29, "", false, rule)   
        --for i, k in pairs ( rulesToFile ) do 
        --guiComboBoxAddItem ( combo, i ) 
        --end 
        guiMemoSetReadOnly (memo, true) 
        addEventHandler("onClientGUIClick", grid, clickedGridlist, false) 
        addEventHandler("onClientGUIClick", close, function () guiSetVisible(rule, false) showCursor(false) end, false) 
        addEventHandler("onClientGUIClick", ask, showSupports, false) 
    end 
) 
  
addEventHandler("onClientGUIChanged", search,  
function() 
    local text = guiGetText(search) 
    local sItems = { } 
    for i, v in pairs(griditem) do 
        if not (text == "" ) then 
            if (string.find(string.upper(v[1]), string.upper(text), 1, true)) then 
                table.insert(sItems, v[1]) 
            end 
        else 
            table.insert(sItems, v[1]) 
        end 
    end 
    guiGridListClear(grid) 
    for i, v in pairs(sItems) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row, colum, tostring(v), false, false) 
    end 
end 

Not working :cry: HELPP PLEASE

Link to comment
local windowTitle = "CST Rules, Documentation and Answers" 
  
GUIEditor = { 
    button = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        local sx, sy = guiGetScreenSize() 
        rule = guiCreateWindow((sx/2)-400, (sy/2)-300, 800, 600, windowTitle, false) 
  
        guiWindowSetSizable(rule, false) 
        guiSetAlpha (rule, 1) 
      
        grid = guiCreateGridList(9, 64, 781, 164, false, rule) 
        guiGridListSetSelectionMode(grid, 1) 
        guiGridListSetSortingEnabled(grid, false) 
        colum = guiGridListAddColumn(grid, "Question", 0.9) 
        for index, val in pairs(griditem) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row, colum, val[1], false, false) 
        end 
        guiSetVisible( rule, false ) 
        memo = guiCreateMemo(3, 238, 700, 350, "Select a Question above to learn about the game.", false, rule) 
        guiMemoSetReadOnly(memo, true) 
        ask = guiCreateButton(713, 238, 78, 89, "Ask a question that isn't answered here", false, rule) 
        close = guiCreateButton(713, 532, 78, 55, "Close", false, rule) 
        search = guiCreateEdit(10, 24, 780, 35, "", false, rule) 
        --combo = guiCreateComboBox(597, 100, 171, 29, "", false, rule)   
        --for i, k in pairs ( rulesToFile ) do 
        --guiComboBoxAddItem ( combo, i ) 
        --end 
        guiMemoSetReadOnly (memo, true) 
        addEventHandler("onClientGUIClick", grid, clickedGridlist, false) 
        addEventHandler("onClientGUIClick", close, function () guiSetVisible(rule, false) showCursor(false) end, false) 
        addEventHandler("onClientGUIClick", ask, showSupports, false) 
    end 
) 
  
addEventHandler("onClientGUIChanged", search,  
function() 
    local text = guiGetText(search) 
    local sItems = { } 
    for i, v in pairs(griditem) do 
        if not (text == "" ) then 
            if (string.find(string.upper(v[1]), string.upper(text), 1, true)) then 
                table.insert(sItems, v[1]) 
            end 
        else 
            table.insert(sItems, v[1]) 
        end 
    end 
    guiGridListClear(grid) 
    for i, v in pairs(sItems) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row, colum, tostring(v), false, false) 
    end 
end 

Not working :cry: HELPP PLEASE

Link to comment

Try that and tell me the result to help you out

local windowTitle = "CST Rules, Documentation and Answers" 
  
GUIEditor = { 
    button = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        local sx, sy = guiGetScreenSize() 
        rule = guiCreateWindow((sx/2)-400, (sy/2)-300, 800, 600, windowTitle, false) 
  
        guiWindowSetSizable(rule, false) 
        guiSetAlpha (rule, 1) 
      
        grid = guiCreateGridList(9, 64, 781, 164, false, rule) 
        guiGridListSetSelectionMode(grid, 1) 
        guiGridListSetSortingEnabled(grid, false) 
        colum = guiGridListAddColumn(grid, "Question", 0.9) 
        for index, val in pairs(griditem) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row, colum, val[1], false, false) 
        end 
        guiSetVisible( rule, false ) 
        memo = guiCreateMemo(3, 238, 700, 350, "Select a Question above to learn about the game.", false, rule) 
        guiMemoSetReadOnly(memo, true) 
        ask = guiCreateButton(713, 238, 78, 89, "Ask a question that isn't answered here", false, rule) 
        close = guiCreateButton(713, 532, 78, 55, "Close", false, rule) 
        search = guiCreateEdit(10, 24, 780, 35, "", false, rule) 
        --combo = guiCreateComboBox(597, 100, 171, 29, "", false, rule)   
        --for i, k in pairs ( rulesToFile ) do 
        --guiComboBoxAddItem ( combo, i ) 
        --end 
        guiMemoSetReadOnly (memo, true) 
        addEventHandler("onClientGUIClick", grid, clickedGridlist, false) 
        addEventHandler("onClientGUIClick", close, function () guiSetVisible(rule, false) showCursor(false) end, false) 
        addEventHandler("onClientGUIClick", ask, showSupports, false) 
    end 
) 
   
function searchFor() 
    local text = guiGetText(search) 
    local sItems = { } 
    for i, v in pairs(griditem) do 
        if not (text == "" ) then 
            if (string.find(string.upper(v[1]), string.upper(text), 1, true)) then 
                table.insert(sItems, v[1]) 
            end 
        else 
            table.insert(sItems, v[1]) 
        end 
    end 
    guiGridListClear(grid) 
    for i, v in pairs(sItems) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row, colum, tostring(v), false, false) 
    end 
end 
addEventHandler("onClientGUIChanged", search,searchFor,false) 

Link to comment
local windowTitle = "CST Rules, Documentation and Answers" 
  
GUIEditor = { 
    button = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        local sx, sy = guiGetScreenSize() 
        rule = guiCreateWindow((sx/2)-400, (sy/2)-300, 800, 600, windowTitle, false) 
  
        guiWindowSetSizable(rule, false) 
        guiSetAlpha (rule, 1) 
      
        grid = guiCreateGridList(9, 64, 781, 164, false, rule) 
        guiGridListSetSelectionMode(grid, 1) 
        guiGridListSetSortingEnabled(grid, false) 
        colum = guiGridListAddColumn(grid, "Question", 0.9) 
        for index, val in pairs(griditem) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row, colum, val[1], false, false) 
        end 
        guiSetVisible( rule, false ) 
        memo = guiCreateMemo(3, 238, 700, 350, "Select a Question above to learn about the game.", false, rule) 
        guiMemoSetReadOnly(memo, true) 
        ask = guiCreateButton(713, 238, 78, 89, "Ask a question that isn't answered here", false, rule) 
        close = guiCreateButton(713, 532, 78, 55, "Close", false, rule) 
        search = guiCreateEdit(10, 24, 780, 35, "", false, rule) 
        --combo = guiCreateComboBox(597, 100, 171, 29, "", false, rule)   
        --for i, k in pairs ( rulesToFile ) do 
        --guiComboBoxAddItem ( combo, i ) 
        --end 
        guiMemoSetReadOnly (memo, true) 
        addEventHandler("onClientGUIClick", grid, clickedGridlist, false) 
        addEventHandler("onClientGUIClick", close, function () guiSetVisible(rule, false) showCursor(false) end, false) 
        addEventHandler("onClientGUIClick", ask, showSupports, false) 
    end 
) 
  
addEventHandler("onClientGUIChanged", search,  
function() 
    local text = guiGetText(search) 
    local sItems = { } 
    for i, v in pairs(griditem) do 
        if not (text == "" ) then 
            if (string.find(string.upper(v[1]), string.upper(text), 1, true)) then 
                table.insert(sItems, v[1]) 
            end 
        else 
            table.insert(sItems, v[1]) 
        end 
    end 
    guiGridListClear(grid) 
    for i, v in pairs(sItems) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row, colum, tostring(v), false, false) 
    end 
end 

Not working :cry: HELPP PLEASE

Post WHOLE client side or at least the part where you store messages/strings.

Link to comment

Last Edit:

I've edited your code as well, it must works correctly, try that

local windowTitle = "CST Rules, Documentation and Answers" 
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        local sx, sy = guiGetScreenSize() 
        rule = guiCreateWindow((sx/2)-400, (sy/2)-300, 800, 600, tostring(windowTitle), false) 
  
        guiWindowSetSizable(rule, false) 
        guiSetAlpha (rule, 1) 
      
        grid = guiCreateGridList(9, 64, 781, 164, false, rule) 
        guiGridListSetSelectionMode(grid, 1) 
        guiGridListSetSortingEnabled(grid, false) 
        guiGridListAddColumn(grid, "Question", 0.9) 
        for index, val in pairs(griditem) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row,1, val[1], false, false) 
        end 
        guiSetVisible( rule, false ) 
        memo = guiCreateMemo(3, 238, 700, 350, "Select a Question above to learn about the game.", false, rule) 
        guiMemoSetReadOnly(memo, true) 
        ask = guiCreateButton(713, 238, 78, 89, "Ask a question that isn't answered here", false, rule) 
        closebtn = guiCreateButton(713, 532, 78, 55, "Close", false, rule) 
        search = guiCreateEdit(10, 24, 780, 35, "", false, rule) 
        --combo = guiCreateComboBox(597, 100, 171, 29, "", false, rule)   
        --for i, k in pairs ( rulesToFile ) do 
        --guiComboBoxAddItem ( combo, i ) 
        --end 
        guiMemoSetReadOnly (memo, true) 
        addEventHandler("onClientGUIClick", grid, clickedGridlist, false) 
        addEventHandler("onClientGUIClick", closebtn, function () guiSetVisible(rule, false) showCursor(false) end, false) 
        addEventHandler("onClientGUIClick", ask, showSupports, false) 
end) 
  
function searchFor() 
guiGridListClear(grid) 
       local text = guiGetText(search) 
        if (text ~= "" ) then 
                for  i, v  in  pairs(griditem) do 
                local row = guiGridListAddRow(grid) 
                 if (string.find(string.upper(v), string.upper(text), 1, true)) then 
                  guiGridListSetItemText(grid, row, 1, tostring(v), false, false) 
                 end 
           end 
     end 
end 
addEventHandler("onClientGUIChanged", search,searchFor,false) 

Goodluck ~

Link to comment

Still not working :/

- You see those Grid List texts? , VIP / Rules ext..

- When i type exemple: VIP , it will only show the VIP grid list text.

- And when i type nothing, it will show all of them (VIP/ Rules ext..)

SS Token now:

http://i.imgur.com/7M535JG.png

7M535JG.png

The whole Client Side script:

  
local rulesToFile = { 
    ["English"] = "Rules/EN.xml", 
    ["German"] = "Rules/GM.xml", 
    ["Greece"] = "Rules/GR.xml", 
    ["Hungarian"] = "Rules/HR.xml", 
    ["Indonisian"] = "Rules/ID.xml", 
    ["Dutch"] = "Rules/NL.xml", 
    ["Portugese"] = "Rules/PT.xml", 
    ["Russian"] = "Rules/RU.xml", 
    ["Spanish"] = "Rules/SP.xml", 
    ["Thai"] = "Rules/TI.xml", 
    ["Tunisian"] = "Rules/TN.xml", 
    ["Turkish"] = "Rules/TR.xml" 
} 
  
infotable = nil 
  
griditem = { 
    {"Rules", "Rules/EN.xml"}, 
    {"VIP", "Others/vip.xml"}, 
    {"CnR", "Others/CnR.xml"}, 
    {"PnR", "Others/PnR.xml"}, 
    {"MW", "Others/MW.xml"}, 
    {"Jobs n Ranks", "Others/jobs.xml"}, 
    {"Commands", "Others/commands.xml"}, 
    {"Donators", "Others/donate.xml"}, 
    {"House System", "Others/house.xml"}, 
    {"Groups", "Others/groups.xml"}, 
    {"Companys", "Others/companys.xml"}, 
} 
  
local windowTitle = "CST Rules, Documentation and Answers" 
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        local sx, sy = guiGetScreenSize() 
        rule = guiCreateWindow((sx/2)-400, (sy/2)-300, 800, 600, tostring(windowTitle), false) 
  
        guiWindowSetSizable(rule, false) 
        guiSetAlpha (rule, 1) 
      
        grid = guiCreateGridList(9, 64, 781, 164, false, rule) 
        guiGridListSetSelectionMode(grid, 1) 
        guiGridListSetSortingEnabled(grid, false) 
        guiGridListAddColumn(grid, "Question", 0.9) 
        for index, val in pairs(griditem) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row,1, val[1], false, false) 
        end 
        guiSetVisible( rule, false ) 
        memo = guiCreateMemo(3, 238, 700, 350, "Select a Question above to learn about the game.", false, rule) 
        guiMemoSetReadOnly(memo, true) 
        ask = guiCreateButton(713, 238, 78, 89, "Ask a question that isn't answered here", false, rule) 
        closebtn = guiCreateButton(713, 532, 78, 55, "Close", false, rule) 
        search = guiCreateEdit(10, 24, 780, 35, "", false, rule) 
        --combo = guiCreateComboBox(597, 100, 171, 29, "", false, rule)   
        --for i, k in pairs ( rulesToFile ) do 
        --guiComboBoxAddItem ( combo, i ) 
        --end 
        guiMemoSetReadOnly (memo, true) 
        addEventHandler("onClientGUIClick", grid, clickedGridlist, false) 
        addEventHandler("onClientGUIClick", closebtn, function () guiSetVisible(rule, false) showCursor(false) end, false) 
        addEventHandler("onClientGUIClick", ask, showSupports, false) 
end) 
  
function searchFor() 
guiGridListClear(grid) 
       local text = guiGetText(search) 
        if (text ~= "" ) then 
                for  i, v  in  pairs(griditem) do 
                local row = guiGridListAddRow(grid) 
                 if (string.find(string.upper(v), string.upper(text), 1, true)) then 
                  guiGridListSetItemText(grid, row, 1, tostring(v), false, false) 
                 end 
           end 
     end 
end 
addEventHandler("onClientGUIChanged", search,searchFor,false) 
       
  
function clickedGridlist() 
    if (guiGridListGetSelectedItem(grid) == -1) then return end 
    local row = guiGridListGetSelectedItem(source) 
    local info = guiGridListGetItemText(grid, row, colum) 
    for index, val in pairs(griditem) do 
        if (info == val[1]) then 
        guiSetText(memo, xmlNodeGetValue( xmlLoadFile( val[2] ) ) or "Error while loading file" ) 
        end 
    end 
end 
-- F1 key bind to open the window 
bindKey( "F1", "down", 
    function () 
        if ( guiGetVisible( rule ) ) then 
            guiSetVisible( rule, false ) 
            showCursor( false ) 
        else 
            guiSetVisible( rule, true ) 
            showCursor( true ) 
        end 
    end 
) 
  
-- When a combo is selected 
addEventHandler ( "onClientGUIComboBoxAccepted", root, 
    function ( theCombo ) 
        if ( theCombo == combo ) then 
            local theItem = guiComboBoxGetSelected ( theCombo ) 
            local theLang = tostring ( guiComboBoxGetItemText ( theCombo , theItem ) ) 
            if ( rulesToFile[theLang] ) then 
                guiSetText( memo, xmlNodeGetValue( xmlLoadFile( rulesToFile[theLang] ) ) or "Error while loading file" ) 
            end 
        end 
    end 
) 
  
function showSupports() 
    guiSetVisible(rule, false) 
    showCursor(false) 
    triggerEvent("showSupportChat", root) 
end 
  
  

Link to comment
local rulesToFile = { 
    ["English"] = "Rules/EN.xml", 
    ["German"] = "Rules/GM.xml", 
    ["Greece"] = "Rules/GR.xml", 
    ["Hungarian"] = "Rules/HR.xml", 
    ["Indonisian"] = "Rules/ID.xml", 
    ["Dutch"] = "Rules/NL.xml", 
    ["Portugese"] = "Rules/PT.xml", 
    ["Russian"] = "Rules/RU.xml", 
    ["Spanish"] = "Rules/SP.xml", 
    ["Thai"] = "Rules/TI.xml", 
    ["Tunisian"] = "Rules/TN.xml", 
    ["Turkish"] = "Rules/TR.xml" 
} 
  
infotable = nil 
  
griditem = { 
    {"Rules", "Rules/EN.xml"}, 
    {"VIP", "Others/vip.xml"}, 
    {"CnR", "Others/CnR.xml"}, 
    {"PnR", "Others/PnR.xml"}, 
    {"MW", "Others/MW.xml"}, 
    {"Jobs n Ranks", "Others/jobs.xml"}, 
    {"Commands", "Others/commands.xml"}, 
    {"Donators", "Others/donate.xml"}, 
    {"House System", "Others/house.xml"}, 
    {"Groups", "Others/groups.xml"}, 
    {"Companys", "Others/companys.xml"}, 
} 
 colum 
local windowTitle = "CST Rules, Documentation and Answers" 
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        local sx, sy = guiGetScreenSize() 
        rule = guiCreateWindow((sx/2)-400, (sy/2)-300, 800, 600, tostring(windowTitle), false) 
  
        guiWindowSetSizable(rule, false) 
        guiSetAlpha (rule, 1) 
      
        grid = guiCreateGridList(9, 64, 781, 164, false, rule) 
        guiGridListSetSelectionMode(grid, 1) 
        guiGridListSetSortingEnabled(grid, false) 
        guiGridListAddColumn(grid, "Question", 0.9) 
        for index, val in pairs(griditem) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row,1, val[1], false, false) 
        end 
        guiSetVisible( rule, false ) 
        memo = guiCreateMemo(3, 238, 700, 350, "Select a Question above to learn about the game.", false, rule) 
        guiMemoSetReadOnly(memo, true) 
        ask = guiCreateButton(713, 238, 78, 89, "Ask a question that isn't answered here", false, rule) 
        closebtn = guiCreateButton(713, 532, 78, 55, "Close", false, rule) 
        search = guiCreateEdit(10, 24, 780, 35, "", false, rule) 
        --combo = guiCreateComboBox(597, 100, 171, 29, "", false, rule)   
        --for i, k in pairs ( rulesToFile ) do 
        --guiComboBoxAddItem ( combo, i ) 
        --end 
        guiMemoSetReadOnly (memo, true) 
        addEventHandler("onClientGUIClick", grid, clickedGridlist, false) 
        addEventHandler("onClientGUIClick", closebtn, function () guiSetVisible(rule, false) showCursor(false) end, false) 
        addEventHandler("onClientGUIClick", ask, showSupports, false) 
end) 
  
function searchFor() 
guiGridListClear(grid) 
       local text = guiGetText(search) 
        if (text ~= "" ) then 
                for  i, v  in  pairs(griditem) do 
                local row = guiGridListAddRow(grid) 
                 if (string.find(string.upper(v), string.upper(text), 1, true)) then 
                  guiGridListSetItemText(grid, row, 1, tostring(v), false, false) 
                 end 
           end 
     end 
end 
addEventHandler("onClientGUIChanged", search,searchFor,false) 
      
  
function clickedGridlist() 
    if (guiGridListGetSelectedItem(grid) == -1) then return end 
    local row = guiGridListGetSelectedItem(source) 
    local info = guiGridListGetItemText(grid, row, 1) 
    for index, val in pairs(griditem) do 
        if (info == val[1]) then 
        guiSetText(memo, xmlNodeGetValue( xmlLoadFile( val[2] ) ) or "Error while loading file" ) 
        end 
    end 
end 
-- F1 key bind to open the window 
bindKey( "F1", "down", 
    function () 
        if ( guiGetVisible( rule ) ) then 
            guiSetVisible( rule, false ) 
            showCursor( false ) 
        else 
            guiSetVisible( rule, true ) 
            showCursor( true ) 
        end 
    end 
) 
  
-- When a combo is selected 
addEventHandler ( "onClientGUIComboBoxAccepted", root, 
    function ( theCombo ) 
        if ( theCombo == combo ) then 
            local theItem = guiComboBoxGetSelected ( theCombo ) 
            local theLang = tostring ( guiComboBoxGetItemText ( theCombo , theItem ) ) 
            if ( rulesToFile[theLang] ) then 
                guiSetText( memo, xmlNodeGetValue( xmlLoadFile( rulesToFile[theLang] ) ) or "Error while loading file" ) 
            end 
        end 
    end 
) 
  
function showSupports() 
    guiSetVisible(rule, false) 
    showCursor(false) 
    triggerEvent("showSupportChat", root) 
end 
  
 addEventHandler("onClientGUIChanged", search, 
function() 
    local text = guiGetText(search) 
    local sItems = { } 
    for i, v in pairs(griditem) do 
        if not (text == "" ) then 
            if (string.find(string.upper(v[1]), string.upper(text), 1, true)) then 
                table.insert(sItems, v[1]) 
            end 
        else 
            table.insert(sItems, v[1]) 
        end 
    end 
    guiGridListClear(grid) 
    for i, v in pairs(sItems) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row, 1, v, false, false) 
    end 
end 

If it didn't work, press f8 and type "debugscript 3". Either post what it says(at bottom of the screen) or take a screenshot.

Link to comment

Not working..

Debug script:

WARNING: CSTinformation\rulesc.lua:78: Bad argument @ 'addEventHandler' [Expected element at argument 2, got nil]

WARNING: CSTinformation\rulesc.lua:123: Bad argument @ 'addEventHandler' [Expected element at argument 2, got nil]

Link to comment
local rows = {"thing 1","thing 2"} 
  
addEventHandler("onClientGUIChanged", search, 
function() 
    local text = guiGetText(source) 
    guiGridListClear(gridlist) 
    for k,v in ipairs(rows) do 
        if v:find(text) then 
            local row = guiGridListAddRow(gridlist) 
            guiGridListSetItemText (gridlist,row,column,v,false,false) 
        end 
    end 
end 

Not working :/ , please fellow my code

I showed you how it works, but I wont make it for you lol

Not working..

Debug script:

WARNING: CSTinformation\rulesc.lua:78: Bad argument @ 'addEventHandler' [Expected element at argument 2, got nil]

WARNING: CSTinformation\rulesc.lua:123: Bad argument @ 'addEventHandler' [Expected element at argument 2, got nil]

Because you're trying to add the event before the gui-element being created

move the addEventHandler Line inside the addEventHandler("onClientResourceStart", ...

Link to comment

Silly mistake...

Alternatively, you can put resourceRoot.

local rulesToFile = { 
    ["English"] = "Rules/EN.xml", 
    ["German"] = "Rules/GM.xml", 
    ["Greece"] = "Rules/GR.xml", 
    ["Hungarian"] = "Rules/HR.xml", 
    ["Indonisian"] = "Rules/ID.xml", 
    ["Dutch"] = "Rules/NL.xml", 
    ["Portugese"] = "Rules/PT.xml", 
    ["Russian"] = "Rules/RU.xml", 
    ["Spanish"] = "Rules/SP.xml", 
    ["Thai"] = "Rules/TI.xml", 
    ["Tunisian"] = "Rules/TN.xml", 
    ["Turkish"] = "Rules/TR.xml" 
} 
  
infotable = nil 
  
griditem = { 
    {"Rules", "Rules/EN.xml"}, 
    {"VIP", "Others/vip.xml"}, 
    {"CnR", "Others/CnR.xml"}, 
    {"PnR", "Others/PnR.xml"}, 
    {"MW", "Others/MW.xml"}, 
    {"Jobs n Ranks", "Others/jobs.xml"}, 
    {"Commands", "Others/commands.xml"}, 
    {"Donators", "Others/donate.xml"}, 
    {"House System", "Others/house.xml"}, 
    {"Groups", "Others/groups.xml"}, 
    {"Companys", "Others/companys.xml"}, 
} 
  
local windowTitle = "CST Rules, Documentation and Answers" 
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function () 
        local sx, sy = guiGetScreenSize() 
        rule = guiCreateWindow((sx/2)-400, (sy/2)-300, 800, 600, tostring(windowTitle), false) 
  
        guiWindowSetSizable(rule, false) 
        guiSetAlpha (rule, 1) 
  
        grid = guiCreateGridList(9, 64, 781, 164, false, rule) 
        guiGridListSetSelectionMode(grid, 1) 
        guiGridListSetSortingEnabled(grid, false) 
        guiGridListAddColumn(grid, "Question", 0.9) 
        for index, val in pairs(griditem) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row,1, val[1], false, false) 
        end 
        guiSetVisible( rule, false ) 
        memo = guiCreateMemo(3, 238, 700, 350, "Select a Question above to learn about the game.", false, rule) 
        guiMemoSetReadOnly(memo, true) 
        ask = guiCreateButton(713, 238, 78, 89, "Ask a question that isn't answered here", false, rule) 
        closebtn = guiCreateButton(713, 532, 78, 55, "Close", false, rule) 
        search = guiCreateEdit(10, 24, 780, 35, "", false, rule) 
        --combo = guiCreateComboBox(597, 100, 171, 29, "", false, rule)   
        --for i, k in pairs ( rulesToFile ) do 
        --guiComboBoxAddItem ( combo, i ) 
        --end 
        guiMemoSetReadOnly (memo, true) 
        addEventHandler("onClientGUIClick", grid, clickedGridlist, false) 
        addEventHandler("onClientGUIClick", closebtn, function () guiSetVisible(rule, false) showCursor(false) end, false) 
        addEventHandler("onClientGUIClick", ask, showSupports, false) 
end) 
      
  
function clickedGridlist() 
    if (guiGridListGetSelectedItem(grid) == -1) then return end 
    local row = guiGridListGetSelectedItem(source) 
    local info = guiGridListGetItemText(grid, row, 1) 
    for index, val in pairs(griditem) do 
        if (info == val[1]) then 
        guiSetText(memo, xmlNodeGetValue( xmlLoadFile( val[2] ) ) or "Error while loading file" ) 
        end 
    end 
end 
-- F1 key bind to open the window 
bindKey( "F4", "down", 
    function () 
        if ( guiGetVisible( rule ) ) then 
            guiSetVisible( rule, false ) 
            showCursor( false ) 
        else 
            guiSetVisible( rule, true ) 
            showCursor( true ) 
        end 
    end 
) 
  
-- When a combo is selected 
addEventHandler ( "onClientGUIComboBoxAccepted", root, 
    function ( theCombo ) 
        if ( theCombo == combo ) then 
            local theItem = guiComboBoxGetSelected ( theCombo ) 
            local theLang = tostring ( guiComboBoxGetItemText ( theCombo , theItem ) ) 
            if ( rulesToFile[theLang] ) then 
                guiSetText( memo, xmlNodeGetValue( xmlLoadFile( rulesToFile[theLang] ) ) or "Error while loading file" ) 
            end 
        end 
    end 
) 
  
function showSupports() 
    guiSetVisible(rule, false) 
    showCursor(false) 
    triggerEvent("showSupportChat", root) 
end 
  
addEventHandler("onClientGUIChanged", resourceRoot, 
function() 
    local text = guiGetText(search) 
    local sItems = { } 
    for i, v in pairs(griditem) do 
        if not (text == "" ) then 
            if (string.find(string.upper(v[1]), string.upper(text), 1, true)) then 
                table.insert(sItems, v[1]) 
            end 
        else 
            table.insert(sItems, v[1]) 
        end 
    end 
    guiGridListClear(grid) 
    for i, v in pairs(sItems) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row, 1, v, false, false) 
    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...