I need some help on map queue.When i bought a map and redo current map,it says Next map:Random map Example:
-----Before redo-----
Map:[DM]1
Next Map:[DM]Bought Map
------After redo-----
Map:[DM]1
Next Map:Random map
local mapQueue = {}
local mapTimers = {}
local randomMap = 0
local specialMapCost = 75000
mapBuyDelay = 35 -- Here delay in minutes
function addMapToQueue(thePlayer,resourceName)
if isPlayerLogged(thePlayer) then
local playerCash = getPlayerData(thePlayer,'cash')
if playerCash>=shopPrice.map then
local errorCode = false
if #mapQueue ~= 0 then
for i,tableQ in pairs(mapQueue) do
if tableQ[4] == resourceName then
errorCode = 1
break
elseif tableQ[3] == thePlayer then
errorCode = 2
break
end
end
end
if errorCode then
if errorCode == 1 then
return displayNotification(thePlayer,"Map queue","This map is already in map queue!",0,100,255)
elseif errorCode == 2 then
return displayNotification(thePlayer,"Map queue","You have one map in map queue now!",0,100,255)
end
end
local mapQueueTable = {}
local map = getResourceFromName(resourceName)
if map then
local mapQueueTable = {
getResourceInfo(map, "name") or resourceName,
getPlayerName(thePlayer),
thePlayer,
resourceName
}
if not mapTimers[mapQueueTable[4]] then
if string.find(mapQueueTable[1],"DD",1) or string.find(mapQueueTable[1],"FUN",1) then
if playerCash<specialMapCost then
return displayNotification(thePlayer,"Map queue","You dont have enough cash! (Need: $"..specialMapCost..")",0,100,255)
end
addValue(thePlayer,'specialMaps',1)
addValue(thePlayer,'cash',-specialMapCost)
else
addValue(thePlayer,'cash',-shopPrice.map)
addValue(thePlayer,'mapsBought',1)
end
table.insert(mapQueue,mapQueueTable)
if #mapQueue == 1 then
triggerEvent("onUserpanelWantNextmap",getRootElement(),mapQueue[1])
end
mapTimers[mapQueueTable[4]] = setTimer(resetMapTimer,mapBuyDelay*60000,1,mapQueueTable[4])
displayNotification(thePlayer,"Map queue","You successfully add new map to map queue!",0,100,255)
outputChatBox("[MAP] #ffffff"..getPlayerName(thePlayer).." #ffffffadd {colorCode}"..mapQueueTable[1].."#ffffff to map queue.",getRootElement(),255,255,255,true)
refreshScoreboard(thePlayer)
checkAchievements(thePlayer,4)
checkAchievements(thePlayer)
else
if isTimer(mapTimers[mapQueueTable[4]]) then
local rem = getTimerDetails(mapTimers[mapQueueTable[4]])
local rem = math.ceil(rem/60000)
displayNotification(thePlayer,"Map queue","You can set this map in: "..rem.." minutes.",0,100,255)
end
end
else
displayNotification(thePlayer,"Map queue","Cant find a map!",0,100,255)
end
else
displayNotification(thePlayer,"Map queue","You dont have enough cash!",0,100,255)
end
end
sentMapQueueToClients()
end
addEvent("onRaceCallNextMapCommand",true)
addEventHandler("onRaceCallNextMapCommand",getRootElement(),addMapToQueue)
function resetMapTimer(mapString)
if isTimer(mapTimers[mapString]) then
killTimer(mapTimers[mapString])
end
mapTimers[mapString] = nil
end
function sentMapQueueToClients()
callClientFunction(getRootElement(),"updateMapQueue",mapQueue)
end
function updateMapQueueOnMapStart()
randomMap = randomMap + 1
if randomMap ~= 4 then
if #mapQueue ~= 0 then
if #mapQueue == 1 then
table.remove(mapQueue,1)
else
table.remove(mapQueue,1)
triggerEvent("onUserpanelWantNextmap",getRootElement(),mapQueue[1])
outputDebugString("Calling next map to race",1,255,255,255)
end
end
else
randomMap = 0
triggerEvent("onUserpanelWantNextmap",getRootElement(),'Random map')
end
sentMapQueueToClients()
end
addEvent("onRaceCallNextMap",true)
addEventHandler("onRaceCallNextMap",getRootElement(),updateMapQueueOnMapStart)