Jump to content

question


Sparrow

Recommended Posts

Posted

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 :)

Posted

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) 

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

Posted

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 

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