Jump to content

Need help with my map search!


Recommended Posts

Posted (edited)

Hello,

I have a userpanel where you can buy maps i wanted to add a search option to it but that didnt went so good.

When i type something in the search bar (ResourceListSearch) all maps go away and when i delete everything i typed maps dont show again.

Plz help me

Client Sided:

triggerServerEvent('getMaps', g_Root) 
addEvent('sendMaps', true) 
addEventHandler('sendMaps', g_Root, 
    function(name) 
        local row = guiGridListAddRow(Shop) 
        guiGridListSetItemText(Shop, row, 1, name, false, false) 
    end 
) 
  
-- Map search 
function mapSearch() 
    guiGridListClear(Shop) 
    local searchString = string.lower(guiGetText(ResourceListSearch)) 
    if ( searchString == "" ) then 
        for id,gamemode in pairs (aGamemodeMapTable) do 
            if (gamemode.name == "Race") then 
                for id,map in ipairs (gamemode.maps) do 
                    local row = guiGridListAddRow (Shop) 
                    guiGridListSetItemText(Shop, row, 1,  map.name, false, false) 
                end 
            end 
        end 
    else 
        for id,gamemode in pairs (aGamemodeMapTable) do 
            if (gamemode.name == "Race") then 
                local noMapsFound = true 
                for id,map in ipairs (gamemode.maps) do 
                    if string.find(string.lower(map.name.." "..map.resname), searchString, 1, true) then 
                        local row = guiGridListAddRow (Shop) 
                        guiGridListSetItemText(Shop, row, 1,  map.name, false, false) 
                        noMapsFound = false 
                    end 
                end 
                if noMapsFound == true then 
                    local row = guiGridListAddRow(Shop) 
                    guiGridListSetItemText (Shop, row, 1, "No maps matching your search query!", false, false) 
                    guiGridListSetItemColor (Shop, row, 1, 0,0,255) 
                end 
            end 
        end 
    end 
end 
addEventHandler("onClientGUIChanged",ResourceListSearch,mapSearch) 

Server sided:

function mapsList() 
    local resourceTable = getResources() 
    for resourceKey, resourceValue in ipairs(resourceTable) do 
        local name = getResourceInfo(resourceValue, "name") 
        local type = getResourceInfo(resourceValue, "type") 
        local game = getResourceInfo(resourceValue, "gamemodes") 
        if type == "map" and game == "race" then 
            triggerClientEvent("sendMaps", g_Root, name) 
        else 
            cancelEvent() 
        end 
    end 
end 
addEvent("getMaps", true) 
addEventHandler("getMaps", g_Root, mapsList) 

Edited by Guest
Posted

you mean this

table.insert(tableOut[countGmodes]["maps"] ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)}) 

Posted

well before all that i used this script:

client sided:

function loadMaps(gamemodeMapTable, gamemode, map) 
    guiGridListClear(Shop) 
    local totalServerMaps = 0 
    if gamemodeMapTable then 
        aGamemodeMapTable = gamemodeMapTable 
        for id,gamemode in pairs (gamemodeMapTable) do 
            if (gamemode.name == "Race") then 
                for id,map in ipairs (gamemode.maps) do 
                    local row = guiGridListAddRow (Shop) 
                    guiGridListSetItemText(Shop, row, 1,  map.name, false, false) 
                    totalServerMaps = totalServerMaps + 1  
                end 
            end 
        end 
    end 
end 
triggerServerEvent('getMaps', g_Root) 
addEvent("sendMaps",true) 
addEventHandler("sendMaps",getRootElement(),loadMaps) 
  
-- Map search 
function mapSearch() 
    guiGridListClear(Shop) 
    local searchString = string.lower(guiGetText(ResourceListSearch)) 
    if ( searchString == "" ) then 
        for id,gamemode in pairs (aGamemodeMapTable) do 
            if (gamemode.name == "Race") then 
                for id,map in ipairs (gamemode.maps) do 
                    local row = guiGridListAddRow (Shop) 
                    guiGridListSetItemText(Shop, row, 1,  map.name, false, false) 
                end 
            end 
        end 
    else 
        for id,gamemode in pairs (aGamemodeMapTable) do 
            if (gamemode.name == "Race") then 
                local noMapsFound = true 
                for id,map in ipairs (gamemode.maps) do 
                    if string.find(string.lower(map.name.." "..map.resname), searchString, 1, true) then 
                        local row = guiGridListAddRow (Shop) 
                        guiGridListSetItemText(Shop, row, 1,  map.name, false, false) 
                        noMapsFound = false 
                    end 
                end 
                if noMapsFound == true then 
                    local row = guiGridListAddRow(Shop) 
                    guiGridListSetItemText (Shop, row, 1, "No maps matching your search query!", false, false) 
                    guiGridListSetItemColor (Shop, row, 1, 0,0,255) 
                end 
            end 
        end 
    end 
end 
addEventHandler("onClientGUIChanged",ResourceListSearch,mapSearch) 

Server sided:

-- GET SERVER MAPS 
function getMaps (loadList) 
    if checkClient( true, source, 'getServerMaps' ) then return end 
    local tableOut 
    if loadList then 
        tableOut = {} 
        -- local deletedMaps = {} 
        local gamemodes = {} 
        gamemodes = call(getResourceFromName("mapmanager"), "getGamemodes") 
        for id,gamemode in ipairs (gamemodes) do 
            tableOut[id] = {} 
            tableOut[id].name = getResourceInfo(gamemode, "name") or getResourceName(gamemode) 
            tableOut[id].resname = getResourceName(gamemode) 
            tableOut[id].maps = {} 
            local maps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode" , gamemode) 
            for _,map in ipairs (maps) do 
                table.insert(tableOut[id]["maps"] ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)}) 
            end 
            table.sort(tableOut[id]["maps"], sortCompareFunction) 
        end 
        table.sort((tableOut), sortCompareFunction) 
        table.insert(tableOut, {name = "no gamemode", resname = "no gamemode", maps = {}}) 
        local countGmodes = #tableOut 
        local maps = call(getResourceFromName("mapmanager"), "getMapsCompatibleWithGamemode") 
        for id,map in ipairs (maps) do 
            -- if fileOpen(":"..getResourceName(map).."/deleted") then 
                -- table.insert(deletedMaps ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)}) 
            -- else 
                table.insert(tableOut[countGmodes]["maps"] ,{name = getResourceInfo(map, "name") or getResourceName(map), resname = getResourceName(map)}) 
            -- end 
        end 
        -- table.sort(deletedMaps, sortCompareFunction) 
        table.sort(tableOut[countGmodes]["maps"], sortCompareFunction) 
        -- table.insert(tableOut, {name = "deleted maps", resname = "deleted maps", maps = {}}) 
        -- local countGmodes = countGmodes + 1 
        -- tableOut[countGmodes]["maps"] = deletedMaps 
    end 
    local map = call(getResourceFromName("mapmanager"), "getRunningGamemodeMap") 
    local gamemode = call(getResourceFromName("mapmanager"), "getRunningGamemode") 
    gamemode = gamemode and getResourceName(gamemode) or "N/A" 
    map = map and getResourceName(map) or "N/A" 
    triggerClientEvent(source ,"loadMaps", source, tableOut, gamemode, map) 
end 
  
function sortCompareFunction(s1, s2) 
    if type(s1) == "table" and type(s2) == "table" then 
        s1, s2 = s1.name, s2.name 
    end 
    s1, s2 = s1:lower(), s2:lower() 
    if s1 == s2 then 
        return false 
    end 
    local byte1, byte2 = string.byte(s1:sub(1,1)), string.byte(s2:sub(1,1)) 
    if not byte1 then 
        return true 
    elseif not byte2 then 
        return false 
    elseif byte1 < byte2 then 
        return true 
    elseif byte1 == byte2 then 
        return sortCompareFunction(s1:sub(2), s2:sub(2)) 
    else 
        return false 
    end 
end 
  
addEvent("getMaps", true) 
addEventHandler("getMaps", g_Root, getMaps) 
-- END GET SERVER MAPS 

But then it didnt show the maps but the map search worked

  • Moderators
Posted

The table is "tableOut" in the server-side Solidsnake ^^

I will see your system later SoundWave 'cause I'm not at home.

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