Jump to content

help with EditBox


Blaawee

Recommended Posts

i'm tryn to make an edit box to search for the payer in the freeroam gamemode , this is what i did :

function warpsearch( player )  
    guiGridListClear ( search ) 
    if ( source == wndWarp.search ) then 
        guiGridListClear ( playerlist ) 
        local text = guiGetText ( source ) 
        if ( text == "" ) then 
            for id, player in ipairs ( getElementsByType ( "player" ) ) do 
                guiGridListSetItemPlayerName ( playerlist, guiGridListAddRow ( playerlist ), 1, getPlayerName ( player ), false, false ) 
            end 
        end  
    end 
end 
addEventHandler ( "onClientGUIChanged", search, warpsearch ) 

{'txt', id='search', text='', width=250}, 

need help with it

Link to comment

Ok, this should work:

--------------------------- 
-- Warp to player window 
--------------------------- 
  
function warpInit() 
    local players = table.map(getElementsByType('player'), function(p) return { name = getPlayerName(p) } end) 
    table.sort(players, function(a, b) return a.name < b.name end) 
    bindGridListToTable(wndWarp, 'playerlist', players, true) 
    local gui = getControl(wndWarp, 'search') 
    addEventHandler ( "onClientGUIChanged", gui, findPlayer, false ) 
end 
  
function findPlayer () 
local text = guiGetText ( source ) 
if (text == "") then 
    local players = table.map(getElementsByType('player'), function(p) return { name = getPlayerName(p) } end) 
    table.sort(players, function(a, b) return a.name < b.name end) 
    bindGridListToTable(wndWarp, 'playerlist', players, true) 
    return 
end 
local matches = {} 
for index, playeritem in ipairs (getElementsByType("player")) do 
    if ( string.find ( string.upper ( getPlayerName ( playeritem ) ), string.upper ( text ), 1, true ) ) then 
        table.insert(matches, playeritem) 
    end 
end 
local players = table.map(matches, function(p) return { name = getPlayerName(p) } end) 
table.sort(players, function(a, b) return a.name < b.name end) 
bindGridListToTable(wndWarp, 'playerlist', players, true) 
end 
  
function warpTo(leaf) 
    if not leaf then 
        leaf = getSelectedGridListLeaf(wndWarp, 'playerlist') 
        if not leaf then 
            return 
        end 
    end 
    local player = getPlayerFromNick(leaf.name) 
    if player then 
        server.warpMe(player) 
    end 
    closeWindow(wndWarp) 
end 
  
wndWarp = { 
    'wnd', 
    text = 'Warp to player', 
    width = 300, 
    controls = { 
        {'txt', id='search', text='', width=280}, 
        { 
            'lst', 
            id='playerlist', 
            width=280, 
            height=300, 
            columns={ 
                {text='Player', attr='name'} 
            }, 
            onitemdoubleclick=warpTo 
        }, 
        {'btn', id='warp', onclick=warpTo}, 
        {'btn', id='cancel', closeswindow=true} 
    }, 
    oncreate = warpInit 
} 

I only tested it with myself, so I'm not sure if it completely works.

Link to comment
function findPlayer () 
    local text = guiGetText ( source ) 
    if (text == "") then 
    local players = table.map(getElementsByType('player'), function(p) return { name = getPlayerName(p):gsub("#%x%x%x%x%x%x","") } end) 
    table.sort(players, function(a, b) return a.name < b.name end) 
    bindGridListToTable(wndWarp, 'playerlist', players, true) 
    return end 
    local matches = {} 
    for index, playeritem in ipairs (getElementsByType("player")) do 
        if ( string.find ( string.upper ( getPlayerName ( playeritem ) ), string.upper ( text ), 1, true ) ) then 
        table.insert(matches, playeritem) 
    end 
end 
    local players = table.map(matches, function(p) return { name = getPlayerName(p):gsub("#%x%x%x%x%x%x","") } end) 
    table.sort(players, function(a, b) return a.name < b.name end) 
    bindGridListToTable(wndWarp, 'playerlist', players, true) 
end 

that's what i did

Link to comment
function warpInit() 
    local players = table.map(getElementsByType('player'), function(p) return { name = getPlayerName(p):gsub("#%x%x%x%x%x%x","") } end) 
    table.sort(players, function(a, b) return a.name < b.name end) 
    bindGridListToTable(wndWarp, 'playerlist', players, true) 
    local gui = getControl(wndWarp, 'search') 
    removeEventHandler ( "onClientGUIChanged", gui, findPlayer, false ) 
    addEventHandler ( "onClientGUIChanged", gui, findPlayer, false ) 
end 
  
function findPlayer () 
    local text = guiGetText ( source ) 
    if (text == "") then 
        local players = table.map(getElementsByType('player'), function(p) return { name = getPlayerName(p):gsub("#%x%x%x%x%x%x","") } end) 
        table.sort(players, function(a, b) return a.name < b.name end) 
        bindGridListToTable(wndWarp, 'playerlist', players, true) 
        return 
    end 
    local matches = {} 
    for index, playeritem in ipairs (getElementsByType("player")) do 
        if ( string.find ( string.upper ( getPlayerName ( playeritem ):gsub("#%x%x%x%x%x%x","") ), string.upper ( text ), 1, true ) ) then 
            table.insert(matches, playeritem) 
        end 
    end 
    local players = table.map(matches, function(p) return { name = getPlayerName(p):gsub("#%x%x%x%x%x%x","") } end) 
    table.sort(players, function(a, b) return a.name < b.name end) 
    bindGridListToTable(wndWarp, 'playerlist', players, true) 
end 

Link to comment
go to the "gui.lua"

and in the line 199 add this :

guiLabelSetColor ( elem, math.random(0, 255), math.random(0, 255), math.random(0, 255) ) 

I'm not sure if it will work

not work :(

try this :

guiLabelSetColor ( elem, wnd.align, math.random(0, 255), math.random(0, 255), math.random(0, 255) ) 

Link to comment
go to the "gui.lua"

and in the line 199 add this :

guiLabelSetColor ( elem, math.random(0, 255), math.random(0, 255), math.random(0, 255) ) 

I'm not sure if it will work

not work

try this :

guiLabelSetColor ( elem, wnd.align, math.random(0, 255), math.random(0, 255), math.random(0, 255) ) 

still not work

Link to comment
  • 4 years later...

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