Hi
I have a local server which I play race with friends
So... I got one userpanel, but there is a problem, the function buy map and buy redo actually set the map, but the next map isn't the bought map the same for redo, I was searching about, and I think I can solve this putting something in racevoting_server. Anyone know what to put in there?
Here's the function
-- Buy a next map
function buyMap(thePlayer,mapName,command)
if not PVP[thePlayer] then
local account = getPlayerAccount(thePlayer)
if not (isGuestAccount(account)) then
local playerCash = tonumber(getAccountData(account,"cash"))
if not (mapName == "") then
if playerCash >= mapCost then
if command then
mapName = getMapName(mapName)
else
mapName = tostring(mapName)
end
if not mapTimer[mapName] then
table.insert(mapQueue,mapName)
local freeMaps = tonumber(getAccountData(account,"freeMaps"))
if freeMaps ~= 0 then
addStat(account,"freeMaps",-1)
else
setAccountData(account,"cash",playerCash - mapCost)
end
addStat(account,"buyedMaps",1)
scoreboardRefresh(thePlayer)
mapTimer[mapName] = true
setTimer(resetMapTimer,900000,1,mapName)
if #mapQueue == 1 then
triggerEvent("onUseranelWantSetMap",getRootElement(),mapQueue[1])
end
callClientFunction(thePlayer,"setFreeMapPurchase",getAccountData(account,"freeMaps"))
unlockAchievement(thePlayer,18)
unlockAchievement(thePlayer)
showServerMsg(getRootElement(),"Map queue",getPlayerName(thePlayer).." #ffffffbought and add "..mapName.." to map queue")
callClientFunction(getRootElement(),"updateMapQueueList",mapQueue)
else
showServerMsg(thePlayer,"Buy nextmap","#FFFFFFYou can't set this map now, wait some time to set!")
end
else
showServerMsg(thePlayer,"Buy nextmap","#FFFFFFYou don't have enough money to set a map!")
end
else
showServerMsg(thePlayer,"Buy nextmap","#FFFFFFPlease select a map from the list first!")
end
end
else
showServerMsg(thePlayer,"Buy nextmap","#FFFFFFYou can't buy maps because you're playing a PVP match now!")
end
end
redo = {}
function buyRedo(thePlayer)
if thePlayer then
local currentMap = exports.mapmanager:getRunningGamemodeMap()
local account = getPlayerAccount(thePlayer)
if isGuestAccount(account) then return end
if getAccountData(account,"donatorEnabled") == 1 then
local mapName = getMapName(currentMap)
if not redo[mapName] then
local freeMaps = tonumber(getAccountData(account,"freeMaps"))
if freeMaps ~= 0 then
addStat(account,"freeMaps",-1)
elseif (getAccountData(account,"cash") >= 2500) then
setAccountData(account,"cash",getAccountData(account,"cash")-2500)
if #mapQueue ~= 0 then
for i=#mapQueue,1 do
mapQueue[i+1] = mapQueue[i]
end
mapQueue[1] = mapName
triggerEvent("onUseranelWantSetMap",getRootElement(),mapQueue[1])
else
mapQueue[1] = mapName
triggerEvent("onUseranelWantSetMap",getRootElement(),mapQueue[1])
end
callClientFunction(thePlayer,"setFreeMapPurchase",getAccountData(account,"freeMaps"))
redo[mapName] = setTimer(function(mapName) redo[mapName] = false end,900000,1,mapName)
showServerMsg(getRootElement(),"Redo",getPlayerName(thePlayer).." #ffffffadded this map to map queue as redo!")
callClientFunction(getRootElement(),"updateMapQueueList",mapQueue)
scoreboardRefresh(thePlayer)
else
showServerMsg(thePlayer,"Redo","You don't have enough money!")
end
else
showServerMsg(thePlayer,"Redo","You cant redo this map at this moment!")
end
else
showServerMsg(thePlayer,"Buy redo","This option is just for donators")
end
end
end
addCommandHandler("buyredo",buyRedo)
function resetMapSetStatus(g_MapInfo)
if nextByRedo then
nextByRedo = false
if #mapQueue ~= 0 then
triggerEvent("onUseranelWantSetMap",getRootElement(),mapQueue[1])
end
else
if #mapQueue == 1 then
table.remove(mapQueue,1)
elseif #mapQueue >1 then
triggerEvent("onUseranelWantSetMap",getRootElement(),mapQueue[2])
table.remove(mapQueue,1)
end
end
callClientFunction(getRootElement(),"updateMapQueueList",mapQueue)
end
addEvent("onMapStarting")
addEventHandler("onMapStarting",getRootElement(),resetMapSetStatus)
addCommandHandler("redo",
function()
nextByRedo = true
end)
function resetMapTimer(mapName)
if mapTimer[mapName] then
mapTimer[mapName] = nil
showServerMsg( getRootElement(),"Map",mapName.." can be bought again!")
end
end
function buyMapCommand(player,command,mapString)
local map, errormsg = findMap( mapString )
if not map then
showServerMsg( player,"Next map",errormsg)
return
end
buyMap(player,map,true)
end
addCommandHandler("bm",buyMapCommand)
function onMapStartingStatsReset()
for _,player in ipairs(getElementsByType("player")) do
respawnFix[player] = nil
hunterFix[player] = nil
end
respawnFix = {}
hunterFix = {}
allowPVP()
end
addEvent("onMapStarting",true)
addEventHandler("onMapStarting",getRootElement(),onMapStartingStatsReset)