• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[MOD] Map Change (for war servers)

LucasFerraz

Systems Analyst
Joined
Jun 10, 2010
Messages
2,858
Reaction score
96
Location
Brazil
Thank you to Bogart for sharing this script.

XML:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Map Change" version="2.0" author="Syntax" contact="otland.net" enabled="yes">
   <description>
        This should teleport all players to a new random town in intervals.
   </description>
    <config name="mapchange_config"><![CDATA[
        config = {
            access = 10, -- minimum access to bypass teleportation.
        temples = {1,2,3} --townids to teleport to.
        }
]]></config>
   <event type="login" name="Map Login" event="script"><![CDATA[
    function onLogin(cid)
        doPlayerSetTown(cid, getGlobalStorageValue(3454))
        doTeleportThing(cid, getPlayerMasterPos(cid))
    return true
    end
]]></event>
    <globalevent name="Map Change" interval="1500000" event="script"><![CDATA[
    domodlib('mapchange_config')
        function onThink(interval, lastExecution, thinkInterval)
            repeat
                RDM = math.random(1,#config.temples)
            until RDM ~= getGlobalStorageValue(3454) and isInArray(config.temples, RDM)
            for _, pid in ipairs(getPlayersOnline()) do
                if getPlayerAccess(pid) < config.access and
                        doPlayerSetTown(pid, config.temples[RDM])
                        doTeleportThing(pid, getTownTemplePosition(config.temples[RDM]), false)
                        doSendMagicEffect(getCreaturePosition(pid), 37)
                        doRemoveCondition(pid, CONDITION_INFIGHT)
                        doCreatureAddHealth(pid, getCreatureMaxHealth(pid))
                        doCreatureAddMana(pid, (getCreatureMaxMana(pid) - getCreatureMana(pid)))
                            doBroadcastMessage("Map has been changed! Next map change will be in 25 minutes!", MESSAGE_STATUS_WARNING)
                        setGlobalStorageValue(3454, config.temples[RDM])
                end
            end
        return true
        end
]]></globalevent>

</mod>

or in globalevents
XML:
<globalevent name="changemap" interval="1500000" event="script" value="changemap.lua"/>
Lua:
local config, new = {
    minTownId = 1,
    maxTownId = 3
}, 0
function onThink(interval, lastExecution)
    for _, pid in ipairs(getPlayersOnline()) do
        local town = getPlayerTown(pid)
        new = town < config.maxTownId and town + 1 or config.minTownId
        doPlayerSetTown(pid, new)
        doTeleportThing(pid, getTownTemplePosition(new))
        doRemoveConditions(pid)
        doCreatureAddHealth(pid, getCreatureMaxHealth(pid))
        doCreatureAddMana(pid, getCreatureMaxMana(pid))
            doBroadcastMessage("Map has been changed! Next map change will be in 25 minutes!", MESSAGE_STATUS_WARNING)
    end
    db.executeQuery("UPDATE players SET town_id = ".. new ..", posx = 0, posy = 0, posz = 0;")
    return true
end

Recent solution:
[MOD] Map Change (for war servers)
 
Last edited:
you added 2 or 3 lines and the author is LucasOlzon?, and if you actually read the "author" at my post, it will say Syntax.
 
Last edited:
you added 2 or 3 lines and the author is LucasOlzon?, and if you actually read the "author" at my post, it will say Syntax.

Sorry, it's because i've made things and forget do re-change author before posting here. check now
 
I get this error using TFS 1.0

e97d32eb2d44e7a4f99a1cf08a48266d.png
 
I get this error using TFS 1.0

e97d32eb2d44e7a4f99a1cf08a48266d.png

Try this: (not tested)

Code:
local config, new = {
minTownId = 1,
maxTownId = 3
},

function onThink(interval, lastExecution)
    for _, pid in ipairs(Game.getPlayers()) do
        local player = Player(pid)
        local town = player:getTown()
        new = town < config.maxTownId and town + 1 or config.minTownId
        player:setTown(new)
        player:teleportTo(player:getTown():getTemplePosition())
        player:removeCondition(CONDITION_INFIGHT) -- not sure which condition should be removed? or all conditions?
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        Game.broadcastMessage("Map has been changed! Next map change will be in 25 minutes!", MESSAGE_STATUS_WARNING)
    end
   
db.query("UPDATE players SET town_id = ".. new ..", posx = 0, posy = 0, posz = 0;")
return true
end
 
Try this: (not tested)

Code:
local config, new = {
minTownId = 1,
maxTownId = 3
},

function onThink(interval, lastExecution)
    for _, pid in ipairs(Game.getPlayers()) do
        local player = Player(pid)
        local town = player:getTown()
        new = town < config.maxTownId and town + 1 or config.minTownId
        player:setTown(new)
        player:teleportTo(player:getTown():getTemplePosition())
        player:removeCondition(CONDITION_INFIGHT) -- not sure which condition should be removed? or all conditions?
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        Game.broadcastMessage("Map has been changed! Next map change will be in 25 minutes!", MESSAGE_STATUS_WARNING)
    end
 
db.query("UPDATE players SET town_id = ".. new ..", posx = 0, posy = 0, posz = 0;")
return true
end
was doing the same but i dont know the new system :(
 
Try this: (not tested)

Code:
local config, new = {
minTownId = 1,
maxTownId = 3
},

function onThink(interval, lastExecution)
    for _, pid in ipairs(Game.getPlayers()) do
        local player = Player(pid)
        local town = player:getTown()
        new = town < config.maxTownId and town + 1 or config.minTownId
        player:setTown(new)
        player:teleportTo(player:getTown():getTemplePosition())
        player:removeCondition(CONDITION_INFIGHT) -- not sure which condition should be removed? or all conditions?
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        Game.broadcastMessage("Map has been changed! Next map change will be in 25 minutes!", MESSAGE_STATUS_WARNING)
    end
  
db.query("UPDATE players SET town_id = ".. new ..", posx = 0, posy = 0, posz = 0;")
return true
end

1bd310561fbf895e5ebd79897a60da98.png
 
Okey so no errors at startup now, but when I try to login to a character I get this
726895ae14d036b026767e2666c890bb.png


Thank you guys for helping me btw!
 
Okey so no errors at startup now, but when I try to login to a character I get this
726895ae14d036b026767e2666c890bb.png


Thank you guys for helping me btw!

There might be a more correct way but try this:

Code:
local config, new = {
minTownId = 1,
maxTownId = 3
}, 0

function onThink(interval, lastExecution)
    for _, pid in ipairs(Game.getPlayers()) do
        local player = Player(pid)
        local town = player:getTown()
        if town == 1 then
            new = 2
        elseif town == 2 then
            new = 3
        else
            new = 1
        end
        player:setTown(new)
        player:teleportTo(player:getTown():getTemplePosition())
        player:removeCondition(CONDITION_INFIGHT) -- not sure which condition should be removed? or all conditions?
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        Game.broadcastMessage("Map has been changed! Next map change will be in 25 minutes!", MESSAGE_STATUS_WARNING)
    end
  
db.query("UPDATE players SET town_id = ".. new ..", posx = 0, posy = 0, posz = 0;")
return true
end
 
Yeah I do, I'm using a RealMap atm.

Trying to create a Warserver that would switch map/town.
 
new = town < config.maxTownId and town + 1 or config.minTownId
that should work I mean
ex.
if town is 0, new = 0 < 3 so 1 or 1
if town is 1, new 1 < 3 so 2 or 1

also use this sql query in ur db

Code:
UPDATE players SET town_id = 1, posx = 0, posy = 0, posz = 0
 
It still gets set to 0.

It's because when the db.query runs the variable new is 0.
 
Code:
local config, new = {
minTownId = 1,
maxTownId = 3
}, 0

function onThink(interval, lastExecution)
    for _, pid in ipairs(Game.getPlayers()) do
        local player = Player(pid)
        local town = player:getTown()
        if town == 1 then
            new = 2
        elseif town == 2 then
            new = 3
        else
            new = 1
        end
        player:setTown(new)
    print(player:setTown(new))
    print(town)
        player:teleportTo(player:getTown():getTemplePosition())
        player:removeCondition(CONDITION_INFIGHT) -- not sure which condition should be removed? or all conditions?
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        Game.broadcastMessage("Map has been changed! Next map change will be in 25 minutes!", MESSAGE_STATUS_WARNING)
    end

db.query("UPDATE players SET town_id = ".. new ..", posx = 0, posy = 0, posz = 0;")
return true
end
 
Back
Top