Tails Posted November 12, 2012 Share Posted November 12, 2012 (edited) 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 November 13, 2012 by Guest Link to comment
Renkon Posted November 12, 2012 Share Posted November 12, 2012 You can edit the code of the resource and make when the poll starts that if [DDAS] appears on the name, then you show it. Link to comment
Tails Posted November 12, 2012 Author Share Posted November 12, 2012 We don't want them to vote for maps, they have to stay random. Link to comment
Renkon Posted November 12, 2012 Share Posted November 12, 2012 Show us startRandomMap() Link to comment
Tails Posted November 12, 2012 Author Share Posted November 12, 2012 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
manve1 Posted November 12, 2012 Share Posted November 12, 2012 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
Tails Posted November 12, 2012 Author Share Posted November 12, 2012 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
Renkon Posted November 12, 2012 Share Posted November 12, 2012 if g_GameOptions.randommaps then startRandomMap() else search for startRandoMMap (function is in that same resource) Link to comment
Tails Posted November 12, 2012 Author Share Posted November 12, 2012 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
Renkon Posted November 12, 2012 Share Posted November 12, 2012 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
Tails Posted November 13, 2012 Author Share Posted November 13, 2012 Edited and tested it but won't work. Am getting bugs, game freezes after the 5 seconds countdown. Thanks for trying to help though! Link to comment
Renkon Posted November 13, 2012 Share Posted November 13, 2012 Yeah, it's not wrong that it freezes after the countdown, but still, any bugs in debugscript? Link to comment
Tails Posted November 13, 2012 Author Share Posted November 13, 2012 (edited) Yeah, it's not wrong that it freezes after the countdown, but still, any bugs in debugscript? Error on the last line: This starts after a few maps have been played. Edited November 13, 2012 by Guest Link to comment
Renkon Posted November 13, 2012 Share Posted November 13, 2012 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
Tails Posted November 13, 2012 Author Share Posted November 13, 2012 Same problem..Also forgot to mention, it starts bugging after a few maps and it still changes to non [ddas] maps. Link to comment
Renkon Posted November 13, 2012 Share Posted November 13, 2012 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
Renkon Posted November 14, 2012 Share Posted November 14, 2012 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
Tails Posted November 14, 2012 Author Share Posted November 14, 2012 startRandomMap failed. Are you sure nothing else needs to be modified? The piece of script above is from the race gamemode resource. Link to comment
Renkon Posted November 14, 2012 Share Posted November 14, 2012 Then.. show us: getRandomMapCompatibleWithGamemode() But I don't know then, if that didn't work, let's try modifying that function Link to comment
Tails Posted November 14, 2012 Author Share Posted November 14, 2012 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
Renkon Posted November 15, 2012 Share Posted November 15, 2012 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
Tails Posted November 15, 2012 Author Share Posted November 15, 2012 Nope ain't working, but this time no errors at all. Thanks for trying atleast Renkon! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now