• 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!

GlobalEvent Change Map [TFS 1.X]

Printer

if Printer then print("LUA") end
Senator
Premium User
Joined
Dec 27, 2009
Messages
5,782
Solutions
31
Reaction score
2,284
Location
Sweden?
Hello, well here is a simple script. That people can use in their War Server. This will change map every 30 minutes, but you can decide for how long until it changes.

In globalevents/globalevents.xml, paste this line:
Code:
<globalevent name="ChangeMap" interval="300000" script="changeMap.lua"/>

And now into globalevents/scripts and create new lua and name it "changeMap.lua" and paste the code below:

Code:
local config = {
    townIds = {
        [1] = "Thais",
        [2] = "Carlin",
        [3] = "Venore"
    },

    globalStorage = 100
}

function onThink(interval, lastExecution)
    local players = Game.getPlayers()
    if #players == 0 then
        return true
    end

    Game.setStorageValue(config.globalStorage, math.max(1, Game.getStorageValue(config.globalStorage) or 1) + 1)

    local towns = config.townIds[Game.getStorageValue(config.globalStorage)]
    if not towns then
        Game.setStorageValue(config.globalStorage, 1)
        towns = config.townIds[Game.getStorageValue(config.globalStorage)]
    end

    local position, player = Town(Game.getStorageValue(config.globalStorage)):getTemplePosition()
    for i = 1, #players do
        player = players[i]
        player:teleportTo(position)
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "The map has been changed to ".. towns .." and all players have been teleported to the respective temple. Next map change will be in 30 minutes!")
    end

    position:sendMagicEffect(CONST_ME_TELEPORT)
    print("The map has been changed to ".. towns .." and all players have been teleported to the respective  temple. Next map change will be in 30 minutes!")
    return true
end

Now go into creaturescripts/scripts/login.lua and paste this before the return true:
Code:
    local currentTown = Game.getStorageValue(100) or 1
    if currentTown then
        player:teleportTo(Town(currentTown):getTemplePosition())
    end

Cheers.
 
bringing up this old post because i would like to use this script
I've noticed the login script doesn't check if the town has been changed or not

every time a player logs out he gets teleported back to temple, even if he's already in the town
how can i add something to check if the player is already in the current town or not?
 
I found a solution. not exactly what i wanted but it works.
I added tps in all the towns temples/depots taking you to a room where you need to place a tile with some unique id

in case anyone needs (im using tfs 1.2 ver 7.4 -- [7.4] TFS 1.2 )

in creaturescripts/login.lua ( i made this only for players that login for the first time, it will teleport them to the current map)
Lua:
local currentTown = Game.getStorageValue(100) or 1
        if currentTown and player:getLastLoginSaved() == 0 then
        player:setTown(Town(currentTown))
        player:teleportTo(Town(currentTown):getTemplePosition())
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        player:setDirection(DIRECTION_SOUTH)
 end

in movements/movements.xml
XML:
 <movevent event="StepIn" uniqueid="53000" script="backtile.lua" />
in movements/scripts create a lua named backtile
Lua:
function onStepIn(creature, item, position, fromPosition)
    if item.uid == 53000 then
        local player = creature:getPlayer()
        if player == nil then
            return false
        end
    local currentTown = Game.getStorageValue(100) or 1
        player:setTown(Town(currentTown))
        player:teleportTo(Town(currentTown):getTemplePosition())
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        player:setDirection(DIRECTION_SOUTH)
    end
    return true
end
and lastly add a tile with the uniqueid 53000 on map editor
hope it helps!
 
Strangely enough, i could not edit the first post. Nice way to fix it. But i would done something like this, then you would not need the teleports.
Lua:
local config = {
    townIds = {
        [1] = "Thais",
        [2] = "Carlin",
        [3] = "Venore"
    },
    globalStorage = 100
}
function onThink(interval, lastExecution)
    local players = Game.getPlayers()
    if #players == 0 then
        return true
    end
    Game.setStorageValue(config.globalStorage, math.max(1, Game.getStorageValue(config.globalStorage) or 1) + 1)
    local towns = config.townIds[Game.getStorageValue(config.globalStorage)]
    if not towns then
        Game.setStorageValue(config.globalStorage, 1)
        towns = config.townIds[Game.getStorageValue(config.globalStorage)]
    end

    local town = Town(Game.getStorageValue(config.globalStorage))
    local position = town:getTemplePosition()
    for i = 1, #players do
        local player = players[i]
        player:setTown(town)
        player:teleportTo(position)
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "The map has been changed to ".. towns .." and all players have been teleported to the respective temple. Next map change will be in 30 minutes!")
    end
    position:sendMagicEffect(CONST_ME_TELEPORT)
    print("The map has been changed to ".. towns .." and all players have been teleported to the respective  temple. Next map change will be in 30 minutes!")
    return true
end

Lua:
    local currentTown = Game.getStorageValue(100) or 1
    if currentTown > 0 and player:getTown() ~= currentTown then
        player:teleportTo(Town(currentTown):getTemplePosition())
    end
 
Last edited by a moderator:
Lua:
    local currentTown = Game.getStorageValue(100) or 1
    if currentTown > 0 and player:getTown() != currentTown then
        player:teleportTo(Town(currentTown):getTemplePosition())
    end

Should be ~= instead != xD
 
Strangely enough, i could not edit the first post. Nice way to fix it. But i would done something like this, then you would not need the teleports.
Lua:
local config = {
    townIds = {
        [1] = "Thais",
        [2] = "Carlin",
        [3] = "Venore"
    },
    globalStorage = 100
}
function onThink(interval, lastExecution)
    local players = Game.getPlayers()
    if #players == 0 then
        return true
    end
    Game.setStorageValue(config.globalStorage, math.max(1, Game.getStorageValue(config.globalStorage) or 1) + 1)
    local towns = config.townIds[Game.getStorageValue(config.globalStorage)]
    if not towns then
        Game.setStorageValue(config.globalStorage, 1)
        towns = config.townIds[Game.getStorageValue(config.globalStorage)]
    end

    local town = Town(Game.getStorageValue(config.globalStorage))
    local position = town:getTemplePosition()
    for i = 1, #players do
        local player = players[i]
        player:setTown(town)
        player:teleportTo(position)
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "The map has been changed to ".. towns .." and all players have been teleported to the respective temple. Next map change will be in 30 minutes!")
    end
    position:sendMagicEffect(CONST_ME_TELEPORT)
    print("The map has been changed to ".. towns .." and all players have been teleported to the respective  temple. Next map change will be in 30 minutes!")
    return true
end

Lua:
    local currentTown = Game.getStorageValue(100) or 1
    if currentTown > 0 and player:getTown() ~= currentTown then
        player:teleportTo(Town(currentTown):getTemplePosition())
    end
Hmmmm... The only thing you changed was Onlogin?
Lua:
    if currentTown > 0 and player:getTown() ~= currentTown then
this?
If so, this still teleports players back to temple even if the town hasn't been changed. :(
 
Update the globalevent aswell
 
hmm.. I'm still facing the same problem
I've been trying to think how to solve it
For now I'll just put the teleport and extra long pz
 
Is there any way to make something like this to switch actual map files and transfer people to that map at certain Temple Coordinates on the next map FILE*? That's what I want :p. Or have two maps running for the server at one time without having to edit the source? Grrr I need a coder of C++ I think.
 
when players log out no matter if they are in the correct current map they always get teleported to temple, how to fix this?
 
have solved the issue regarding teleport player all the time on login but now is not checking in which city player is so if palyer is in another city has to wait till next change map in order to be placed with all the others players is there a way to fix this?
Lua:
    --  if not player:getStorageValue(43214, player:getStorageValue(43214) + 1) then --agregado ahora solo teleporta al cambio de mapa y no cada vez que el player logea
    --if currentTown then
     if  not player:getTown() == currentTown then --agregado solucion?
        player:teleportTo(Town(currentTown):getTemplePosition())
    end--agregado war
    return true
end
 
Back
Top