Hello I'm using this mapchanger script It was coded by Aled in this thread: [LUA Request] Modal Window changemap with votes (https://otland.net/threads/lua-request-modal-window-changemap-with-votes.251154/)
So it works but is not setting players towns, so when you die you get tped to old town.. script is just giving teleport instead of map change at all.
This is talkaction
and creaturescript:
Is there any way to set town from maps[winner(votes)] instead of just set a storage value and add a +1 ? in this case vote wouldn't work
Thank you
So it works but is not setting players towns, so when you die you get tped to old town.. script is just giving teleport instead of map change at all.
This is talkaction
Lua:
votemapconfig = {
storage = 200134, -- player storage value, to store votes
globalstorage = 20035, -- global storage value, for map change cooldown
timer1 = 10, -- seconds to teleport everybody
timer2 = 1, -- minutes per gamemode
percent = 10 -- % of active players to vote to cause map change
}
function onSay(player, words, param)
maps = {
[1] = {pos = Position(32681,31686,7), name = "Abdendriel", townid = 1},
[2] = {pos = Position(32345,32222,7), name = "Thais", townid = 3},
[3] = {pos = Position(33214,32459,8), name = "Darashia", townid = 7}
}
local currenttime = tonumber(os.date("%H%M", os.time()))
local stor = Game.getStorageValue(votemapconfig.globalstorage) or 0
local h,m = math.floor(stor/100), stor-math.floor(stor/100)*100
if stor > 0 then
player:sendTextMessage(MESSAGE_INFO_DESCR, "Game mode was changed at "..h..":"..m..", cooldown is "..votemapconfig.timer2.." minutes, please wait "..currenttime-stor.." minutes before attempting to change the map again.")
return false
end
local padWindow = ModalWindow(2000, "Select map to vote for:", "Total Players:"..Game.getPlayerCount().."")
for i=1,3 do
padWindow:addChoice(i, maps[i].name .. ", Votes: "..votes[i]..".")
end
padWindow:addButton(1, "VOTE")
padWindow:addButton(2, "EXIT")
padWindow:setDefaultEnterButton(1)
padWindow:setDefaultEscapeButton(2)
padWindow:sendToPlayer(player)
return false
end
and creaturescript:
Code:
votes = {0,0,0}
voters = {}
function winner(Table) -- Couldn't find an easier way to do this lol
local high = 1
for i, k in ipairs(Table) do
if Table[i] > high then
high = Table[i]
end
end
return high
end
function onModalWindow(player, modalWindowId, buttonId, choiceId)
local currenttime = tonumber(os.date("%H%M", os.time()))
local players = Game.getPlayerCount()
if modalWindowId == 2000 then
if buttonId == 1 then
if player:getStorageValue(votemapconfig.storage) > 0 then
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already voted for "..maps[player:getStorageValue(votemapconfig.storage)].name..". You must wait until the next map change to vote again.")
return false
else
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have voted for "..maps[choiceId].name..", when half or more of the active players have voted, the game mode will change.")
player:setStorageValue(votemapconfig.storage,choiceId)
votes[choiceId] = votes[choiceId]+1
voters[#voters+1] = player
if #voters > players*(votemapconfig.percent/100) then
Game.setStorageValue(votemapconfig.globalstorage,currenttime)
for i=1,#voters do
voters[i]:setStorageValue(votemapconfig.storage,-1)
end
votes = {0,0,0}
voters = {}
Game.broadcastMessage("Enough players have voted! The next map is "..maps[choiceId].name.."!", MESSAGE_EVENT_DEFAULT)
Game.broadcastMessage("Teleporting in "..votemapconfig.timer1.." seconds.", MESSAGE_INFO_DESCR)
addEvent(function()
local targetplayers = Game.getPlayers()
for i = 1, #targetplayers do
targetplayer = targetplayers[i]
targetplayer:teleportTo(maps[winner(votes)].pos)
maps[winner(votes)].pos:sendMagicEffect(CONST_ME_TELEPORT)
targetplayer:setTown(maps[winner(votes)].townid)
end
local globalstoraged = 100
addEvent(function()
Game.setStorageValue(votemapconfig.globalstorage,-1)
end,votemapconfig.timer2*60*1000)
end,votemapconfig.timer1*1000)
end
end
end
end
return true
end
Is there any way to set town from maps[winner(votes)] instead of just set a storage value and add a +1 ? in this case vote wouldn't work
Thank you