Jump to content

Buymap / racevoting_server.lua ?


=KoG=Rouche

Recommended Posts

Hi all,

I try to make the Buy Map function of my userpanel working.

I know i've to edit something in racevoting_server.lua but can't remember what.

There is nothing in Debugscript .

Does anyone have an idea ?

racevoting_server.lua

  
function buyMap(player, ...) 
    if mapAllow ~= true then 
        outputChatBox('* You are not allowed to buy map right now!', player, 255, 0, 0, true) 
        return 
    end 
    local query = #{...}>0 and table.concat({...},' ') or nil 
    if not query then 
        if g_ForcedNextMap then 
            outputRace( 'Next map is ' .. getMapName( g_ForcedNextMap ), player ) 
        else 
            outputRace( 'Next map is not set', player ) 
        end 
        return 
    end 
    local map, errormsg = findMap( query ) 
    if not map then 
        outputRace( errormsg, player ) 
        return 
    end 
    if g_ForcedNextMap == map then 
        outputRace( 'Next map is already set to ' .. getMapName( g_ForcedNextMap ), player ) 
        return 
    end 
    if g_ForcedNextMap ~= nil then 
        table.insert(mapQueue, map) 
        outputChatBox('* ' .. getMapName( map ) .. ' has been bought and added to queue by ' .. getPlayerName( player ), g_Root, 0, 240, 0) 
    else 
        g_ForcedNextMap = map 
        outputChatBox('* Next map has been bought and set to ' .. getMapName( map ) .. ' by ' .. getPlayerName( player ), g_Root, 0, 240, 0) 
    end 
end 
addEvent("buyMap", true) 
addEventHandler("buyMap", root, buyMap) 
  
--Find a map which matches, or nil and a text message if there is not one match 
function findMap( query ) 
    local maps = findMaps( query ) 
  
    -- Make status string 
    local status = "Found " .. #maps .. " match" .. ( #maps==1 and "" or "es" ) 
    for i=1,math.min(5,#maps) do 
        status = status .. ( i==1 and ": " or ", " ) .. "'" .. getMapName( maps[i] ) .. "'" 
    end 
    if #maps > 5 then 
        status = status .. " (" .. #maps - 5 .. " more)" 
    end 
  
    if #maps == 0 then 
        return nil, status .. " for '" .. query .. "'" 
    end 
    if #maps == 1 then 
        return maps[1], status 
    end 
    if #maps > 1 then 
        return nil, status 
    end 
end 
  
-- Find all maps which match the query string 
function findMaps( query ) 
    local results = {} 
    --escape all meta chars 
    query = string.gsub(query, "([%*%+%?%.%(%)%[%]%{%}%\%/%|%^%$%-])","%%%1") 
    -- Loop through and find matching maps 
    for i,resource in ipairs(exports.mapmanager:getMapsCompatibleWithGamemode(getThisResource())) do 
        local resName = getResourceName( resource ) 
        local infoName = getMapName( resource  ) 
  
        -- Look for exact match first 
        if query == resName or query == infoName then 
            return {resource} 
        end 
  
        -- Find match for query within infoName 
        if string.find( infoName:lower(), query:lower() ) then 
            table.insert( results, resource ) 
        end 
    end 
    return results 
end 
  
function getMapName( map ) 
    return getResourceInfo( map, "name" ) or getResourceName( map ) or "unknown" 
end 
  
addCommandHandler('buymap', 
    function( player, command, ... ) 
        local query = #{...}>0 and table.concat({...},' ') or nil 
        if not query then 
            if g_ForcedNextMap then 
                outputRace( 'Next map is ' .. getMapName( g_ForcedNextMap ), player ) 
            else 
                outputRace( 'Next map is not set', player ) 
            end 
            return 
        end 
        local map, errormsg = findMap( query ) 
        if not map then 
            outputRace( errormsg, player ) 
            return 
        end 
        if g_ForcedNextMap == map then 
            outputRace( 'Next map is already set to ' .. getMapName( g_ForcedNextMap ), player ) 
            return 
        end 
        g_ForcedNextMap = map 
        outputChatBox('' .. getPlayerName( player )..' Buy Next map ' .. getMapName( g_ForcedNextMap ) .. '', g_Root, 255, 200, 0) 
    end 
) 
  

Thanks for helping.

Link to comment

Lel you said its your userpanel. If it was made by you, you would know what to do.

The idea is: the map queue is stored in the userpanel and when a player buys a map (using command) it triggers event that is placed in the racevoting file.

The function that should be in the racevoting file is similar to the "nextmap" command.

So the buy map command should be in the userpanel's code, not in the race gamemode.

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