Sparrow Posted March 2, 2012 Share Posted March 2, 2012 hello all, imagine that I've done admin panel or clan system or soemthing else, how to set an edit search for the connection players? and thanks Link to comment
Ludo Posted March 2, 2012 Share Posted March 2, 2012 If i have understood... This may work, but you have to adapt the names with your gui names, anyway this way is done by using gridlist. theWindow = guiCreateWindow(240, 200, 550, 330, "", false) searchPlayer = guiCreateEdit(15, 25, 180, 20, "",false, theWindow) playersList = guiCreateGridList(10, 50, 500, 210, false, theWindow) players = getElementsByType("player") for n, player in ipairs(players) do playerRow = guiGridListAddRow(playersList) guiGridListSetItemText(playersList, playerRow, 1, getPlayerName(player):gsub("#%x%x%x%x%x%x", ""), false, false) guiGridListSetItemData(playersList, playerRow, 1, player) end function searchPlayers() playerString = guiGetText(searchPlayer) playerFound = false guiGridListClear(playersList) if playerString == "" then for k, player in ipairs(players) do playerRow = guiGridListAddRow(playersList) guiGridListSetItemText(playersList, playerRow, 1, getPlayerName(player):gsub("#%x%x%x%x%x%x", ""), false, false) guiGridListSetItemData(playersList, playerRow, 1, player) end else for k, player in ipairs(players) do if string.find(string.lower(getPlayerName(player):gsub("#%x%x%x%x%x%x", "")), string.lower(playerString), 1, true) then playerRow = guiGridListAddRow(playersList) guiGridListSetItemText(playersList, playerRow, 1, getPlayerName(player):gsub("#%x%x%x%x%x%x", ""), false, false) guiGridListSetItemData(playersList, playerRow, 1, player) playerFound = true end end if playerFound == false then playerRow = guiGridListAddRow(playersListt) guiGridListSetItemText(playersList, playerRow, 1, "No player has been found", false, false) guiGridListSetItemColor(playersList, playerRow, 1, 255, 0, 0) end end end addEventHandler("onClientGUIChanged", searchPlayer, searchPlayers) Link to comment
drk Posted March 2, 2012 Share Posted March 2, 2012 If i have understood...This may work, but you have to adapt the names with your gui names, anyway this way is done by using gridlist. theWindow = guiCreateWindow(240, 200, 550, 330, "", false) searchPlayer = guiCreateEdit(15, 25, 180, 20, "",false, theWindow) playersList = guiCreateGridList(10, 50, 500, 210, false, theWindow) players = getElementsByType("player") for n, player in ipairs(players) do playerRow = guiGridListAddRow(playersList) guiGridListSetItemText(playersList, playerRow, 1, getPlayerName(player):gsub("#%x%x%x%x%x%x", ""), false, false) guiGridListSetItemData(playersList, playerRow, 1, player) end function searchPlayers() playerString = guiGetText(searchPlayer) playerFound = false guiGridListClear(playersList) if playerString == "" then for k, player in ipairs(players) do playerRow = guiGridListAddRow(playersList) guiGridListSetItemText(playersList, playerRow, 1, getPlayerName(player):gsub("#%x%x%x%x%x%x", ""), false, false) guiGridListSetItemData(playersList, playerRow, 1, player) end else for k, player in ipairs(players) do if string.find(string.lower(getPlayerName(player):gsub("#%x%x%x%x%x%x", "")), string.lower(playerString), 1, true) then playerRow = guiGridListAddRow(playersList) guiGridListSetItemText(playersList, playerRow, 1, getPlayerName(player):gsub("#%x%x%x%x%x%x", ""), false, false) guiGridListSetItemData(playersList, playerRow, 1, player) playerFound = true end end if playerFound == false then playerRow = guiGridListAddRow(playersListt) guiGridListSetItemText(playersList, playerRow, 1, "No player has been found", false, false) guiGridListSetItemColor(playersList, playerRow, 1, 255, 0, 0) end end end addEventHandler("onClientGUIChanged", searchPlayer, searchPlayers) Some mistakes in the code... Link to comment
Ludo Posted March 2, 2012 Share Posted March 2, 2012 Some mistakes in the code... Maybe if you tell us where, you may be more useful Link to comment
Castillo Posted March 2, 2012 Share Posted March 2, 2012 The only problem I see in your code Ludo is that you forgot about the grid list column. Anyway, I think this code is a lot easier to understand: addEventHandler("onClientResourceStart",resourceRoot, function () theWindow = guiCreateWindow(240, 200, 550, 330, "", false) searchPlayer = guiCreateEdit(15, 25, 180, 20, "",false, theWindow) addEventHandler ("onClientGUIChanged", searchPlayer, findPlayers, false) playersList = guiCreateGridList(10, 50, 500, 210, false, theWindow) guiGridListAddColumn(playersList,"Player name:",0.90) for index, player in ipairs(getElementsByType("player")) do local playerRow = guiGridListAddRow(playersList) guiGridListSetItemText(playersList, playerRow, 1, getPlayerName(player):gsub("#%x%x%x%x%x%x", ""), false, false) end end ) function findPlayers () guiGridListClear( playersList ) local text = guiGetText ( source ) if (text ~= "") then for index, player in ipairs (getElementsByType("player")) do local playerRow = guiGridListAddRow(playersList) local playerName = getPlayerName(player):gsub("#%x%x%x%x%x%x", "") if ( string.find ( string.upper ( playerName ), string.upper ( text ), 1, true ) ) then guiGridListSetItemText(playersList, playerRow, 1, playerName, false, false) else guiGridListSetItemText(playersList, playerRow, 1, "No player found.", false, false) break end end else for index, player in ipairs (getElementsByType("player")) do local playerName = getPlayerName(player):gsub("#%x%x%x%x%x%x", "") local playerRow = guiGridListAddRow(playersList) guiGridListSetItemText(playersList, playerRow, 1, playerName, false, false) end end end 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