Jump to content

Excluding maps from the map cycle


Tails

Recommended Posts

Hi Mta fans and scripters,

I was wondering if there's a way to exclude maps from the race gamemode because we'd like to only have maps that have the [DDAS] tag in our random map cycle but still be able to play other maps.

Any bit of help is appreciated.

Thanks,

Tails

Edit:

I'm guessing something needs to be added to this bit of script from the race's base.lua:

function RaceMode.endMap() 
    if stateAllowsPostFinish() then 
        gotoState('PostFinish') 
        local text = g_GameOptions.randommaps and 'Next map starts in:' or 'Vote for next map starts in:' 
        Countdown.create(5, RaceMode.startNextMapSelect, text, 255, 255, 255, 0.6, 2.5 ):start() 
        triggerEvent('onPostFinish', g_Root) 
    end 
end 
  
function RaceMode.startNextMapSelect() 
    if stateAllowsNextMapSelect() then 
        gotoState('NextMapSelect') 
        Countdown.destroyAll() 
        destroyAllMessages() 
        if g_GameOptions.randommaps then 
            startRandomMap() 
        else 
            startNextMapVote() 
        end 
    end 
end 

Edited by Guest
Link to comment

found this

function problemChangingMap() 
    outputRace( 'Changing to random map in 5 seconds' ) 
    local currentMap = exports.mapmanager:getRunningGamemodeMap() 
    TimerManager.createTimerFor("resource","mapproblem"):setTimer( 
        function() 
            -- Check that something else hasn't already changed the map 
            if currentMap == exports.mapmanager:getRunningGamemodeMap() then 
                startRandomMap() 
            end 
        end, 
        math.random(4500,5500), 1 ) 
end 

I think it's linked to the mapmanager resource

Link to comment
found this
function problemChangingMap() 
    outputRace( 'Changing to random map in 5 seconds' ) 
    local currentMap = exports.mapmanager:getRunningGamemodeMap() 
    TimerManager.createTimerFor("resource","mapproblem"):setTimer( 
        function() 
            -- Check that something else hasn't already changed the map 
            if currentMap == exports.mapmanager:getRunningGamemodeMap() then 
                startRandomMap() 
            end 
        end, 
        math.random(4500,5500), 1 ) 
end 

I think it's linked to the mapmanager resource

It is linked ... in the script u can see easily this line:

exports.mapmanager:getRunningGamemodeMap() 

which has map manager in it

Link to comment

That's why I said it.

I also found this code:

addEventHandler("onResourceStart", rootElement,  
    function (startedResource) 
        --Is this resource a gamemode? 
        if isGamemode(startedResource) then 
            --Check no gamemode is running already 
            if getRunningGamemode() then 
                return 
            end 
            if triggerEvent("onGamemodeStart", getResourceRootElement(startedResource), startedResource) then 
                currentGamemode = startedResource 
                --Setup our announcements 
                local gamemodeName = getResourceInfo(currentGamemode, "name") or getResourceName(currentGamemode) 
                if get("ASE") then 
                    setGameType(gamemodeName) 
                end 
                if get("messages") then 
                    local name = getInstigatorName ( " by " ) or "" 
                    outputMapManager("Gamemode '"..gamemodeName.."' started" .. name .. "." ) 
                end 
                --We need to wait a while to see if any maps were started.  If not, lets try and start a random one 
                setTimer(  
                    function() 
                        if not getRunningGamemodeMap() then 
                            --Lets check if there are any maps for this gamemode 
                            local maps = getMapsCompatibleWithGamemode(getRunningGamemode()) 
                            --If we have any, we'll start a random one 
                            if #maps > 0 then 
                                changeGamemodeMap (maps[math.random(1,#maps)]) 
                            end 
                        end 
                    end,  
                50, 1 ) 
            else 
                currentGamemode = nil 
            end 

I'm not really a good scripter, but I was hoping if anyone could lead me in the right direction.

Link to comment

This might be it:

function startRandomMap() 
  
    -- Handle forced nextmap setting 
    if maybeApplyForcedNextMap() then 
        return 
    end 
  
    -- Get a random map chosen from the 10% of least recently player maps, with enough spawn points for all the players (if required) 
    local map = getRandomMapCompatibleWithGamemode( getThisResource(), 10, g_GameOptions.ghostmode and 0 or getTotalPlayerCount() ) 
    if map then 
        g_IgnoreSpawnCountProblems = map    -- Uber hack 4000 
        if not exports.mapmanager:changeGamemodeMap ( map, nil, true ) then 
            problemChangingMap() 
        end 
    else 
        outputWarning( 'startRandomMap failed' ) 
    end 
end 
  

Link to comment
function startRandomMap() 
  
    -- Handle forced nextmap setting 
    if maybeApplyForcedNextMap() then 
        return 
    end 
  
    -- Get a random map chosen from the 10% of least recently player maps, with enough spawn points for all the players (if required) 
    local map = getRandomMapCompatibleWithGamemode( getThisResource(), 10, g_GameOptions.ghostmode and 0 or getTotalPlayerCount() ) 
    if map then 
        g_IgnoreSpawnCountProblems = map    -- Uber hack 4000 
        if not string.find(getResourceName(map), "[DDAS]") then startRandomMap() return end 
        if not exports.mapmanager:changeGamemodeMap ( map, nil, true ) then 
            problemChangingMap() 
        end 
    else 
        outputWarning( 'startRandomMap failed' ) 
    end 
end 

Link to comment
function AntiInfinite() 
     startRandomMap() 
end 
  
function startRandomMap() 
  
    -- Handle forced nextmap setting 
    if maybeApplyForcedNextMap() then 
        return 
    end 
  
    -- Get a random map chosen from the 10% of least recently player maps, with enough spawn points for all the players (if required) 
    local map = getRandomMapCompatibleWithGamemode( getThisResource(), 10, g_GameOptions.ghostmode and 0 or getTotalPlayerCount() ) 
    if map then 
        g_IgnoreSpawnCountProblems = map    -- Uber hack 4000 
        if not string.find(getResourceName(map), "[DDAS]") then AntiInfinite() return end 
        if not exports.mapmanager:changeGamemodeMap ( map, nil, true ) then 
            problemChangingMap() 
        end 
    else 
        outputWarning( 'startRandomMap failed' ) 
    end 
end 

Link to comment
function getMap() 
     local name = "Somebody" 
     while not string.find(name, "[DDAS]") do 
           local map = getRandomMapCompatibleWithGamemode( getThisResource(), 10, g_GameOptions.ghostmode and 0 or getTotalPlayerCount() ) 
           name = getResourceName(map) 
     end 
     return map 
end 
function startRandomMap() 
  
    -- Handle forced nextmap setting 
    if maybeApplyForcedNextMap() then 
        return 
    end 
  
    -- Get a random map chosen from the 10% of least recently player maps, with enough spawn points for all the players (if required) 
    local map = getMap() 
    if map then 
        g_IgnoreSpawnCountProblems = map    -- Uber hack 4000 
        if not exports.mapmanager:changeGamemodeMap ( map, nil, true ) then 
            problemChangingMap() 
        end 
    else 
        outputWarning( 'startRandomMap failed' ) 
    end 
end 
  

May work.

Link to comment
function getMap() 
     local name = "Somebody" 
     local map 
     while not string.find(name, "[DDAS]") do 
           map = getRandomMapCompatibleWithGamemode( getThisResource(), 10, g_GameOptions.ghostmode and 0 or getTotalPlayerCount() ) 
           name = getResourceName(map) 
     end 
     return map 
end 
function startRandomMap() 
  
    -- Handle forced nextmap setting 
    if maybeApplyForcedNextMap() then 
        return 
    end 
  
    -- Get a random map chosen from the 10% of least recently player maps, with enough spawn points for all the players (if required) 
    local map = getMap() 
    if map then 
        g_IgnoreSpawnCountProblems = map    -- Uber hack 4000 
        if not exports.mapmanager:changeGamemodeMap ( map, nil, true ) then 
            problemChangingMap() 
        end 
    else 
        outputWarning( 'startRandomMap failed' ) 
    end 
end 
  

Link to comment

What giving you the whole .lua file so you can take a look:

http://www.datafilehost.com/codes.php

function getRandomMapCompatibleWithGamemode( gamemode, oldestPercentage, minSpawnCount ) 
  
    -- Get all relevant maps 
    local compatibleMaps = exports.mapmanager:getMapsCompatibleWithGamemode( gamemode ) 
  
    if #compatibleMaps == 0 then 
        outputDebugString( 'getRandomMapCompatibleWithGamemode: No maps.', 1 ) 
        return false 
    end 
  
    -- Sort maps by time since played 
    local sortList = {} 
    for i,map in ipairs(compatibleMaps) do 
        sortList[i] = {} 
        sortList[i].map = map 
        sortList[i].lastTimePlayed = getMapLastTimePlayed( map ) 
    end 
  
    table.sort( sortList, function(a, b) return a.lastTimePlayed > b.lastTimePlayed end ) 
  
    -- Use the bottom n% of maps as the initial selection pool 
    local cutoff = #sortList - math.floor( #sortList * oldestPercentage / 100 ) 
  
    outputDebug( 'RANDMAP', 'getRandomMapCompatibleWithGamemode' ) 
    outputDebug( 'RANDMAP', '' 
            .. ' minSpawns:' .. tostring( minSpawnCount ) 
            .. ' nummaps:' .. tostring( #sortList ) 
            .. ' cutoff:' .. tostring( cutoff ) 
            .. ' poolsize:' .. tostring( #sortList - cutoff + 1 ) 
            ) 
  
    math.randomseed( getTickCount() % 50000 ) 
    local fallbackMap 
    while #sortList > 0 do 
        -- Get random item from range 
        local idx = math.random( cutoff, #sortList ) 
        local map = sortList[idx].map 
  
        if not minSpawnCount or minSpawnCount <= getMapSpawnPointCount( map ) then 
            outputDebug( 'RANDMAP', '' 
                    .. ' ++ using map:' .. tostring( getResourceName( map ) ) 
                    .. ' spawns:' .. tostring( getMapSpawnPointCount( map ) ) 
                    .. ' age:' .. tostring( getRealTimeSeconds() - getMapLastTimePlayed( map ) ) 
                    ) 
            return map 
        end 
  

Link to comment
function getRandomMapCompatibleWithGamemode( gamemode, oldestPercentage, minSpawnCount ) 
  
    -- Get all relevant maps 
    local compatibleMaps = exports.mapmanager:getMapsCompatibleWithGamemode( gamemode ) 
  
    -- WE CLEAR THE ONES THAT DOESN'T HAVE [DDAS] 
    for i, obj in ipairs (compatibleMaps) do 
          if not string.find(getResourceName(obj), "[DDAS]") then compatibleMaps[i] = false end 
    end 
  
    if #compatibleMaps == 0 then 
        outputDebugString( 'getRandomMapCompatibleWithGamemode: No maps.', 1 ) 
        return false 
    end 
  
  
    -- Sort maps by time since played 
    local sortList = {} 
    for i,map in ipairs(compatibleMaps) do 
        sortList[i] = {} 
        sortList[i].map = map 
        sortList[i].lastTimePlayed = getMapLastTimePlayed( map ) 
    end 
  
    table.sort( sortList, function(a, b) return a.lastTimePlayed > b.lastTimePlayed end ) 
  
    -- Use the bottom n% of maps as the initial selection pool 
    local cutoff = #sortList - math.floor( #sortList * oldestPercentage / 100 ) 
  
    outputDebug( 'RANDMAP', 'getRandomMapCompatibleWithGamemode' ) 
    outputDebug( 'RANDMAP', '' 
            .. ' minSpawns:' .. tostring( minSpawnCount ) 
            .. ' nummaps:' .. tostring( #sortList ) 
            .. ' cutoff:' .. tostring( cutoff ) 
            .. ' poolsize:' .. tostring( #sortList - cutoff + 1 ) 
            ) 
  
    math.randomseed( getTickCount() % 50000 ) 
    local fallbackMap 
    while #sortList > 0 do 
        -- Get random item from range 
        local idx = math.random( cutoff, #sortList ) 
        local map = sortList[idx].map 
  
        if not minSpawnCount or minSpawnCount <= getMapSpawnPointCount( map ) then 
            outputDebug( 'RANDMAP', '' 
                    .. ' ++ using map:' .. tostring( getResourceName( map ) ) 
                    .. ' spawns:' .. tostring( getMapSpawnPointCount( map ) ) 
                    .. ' age:' .. tostring( getRealTimeSeconds() - getMapLastTimePlayed( map ) ) 
                    ) 
            return map 
        end 
  

My last try.

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