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

Lua add an exception to this script change map script tfs 1.3

johnsamir

Advanced OT User
Joined
Oct 13, 2009
Messages
965
Solutions
6
Reaction score
164
Location
Nowhere
Hi

I'm using this script at my server GlobalEvent - Change Map [TFS 1.X] (https://otland.net/threads/change-map-tfs-1-x.227517/) it does work very good. The problem is that, have other events in server, and the problem is that when an event is on going and the global event change the map it moves all players, i want to add an exception for the event, like for example is playing is standing in nologout tile it wont be teleport it will be excluded from the change map event or if you have a better idea on how to do this please point it out. is this possible? can you tell me how to do it, please?

thank
Post automatically merged:

have made this
Lua:
    local town = Town(Game.getStorageValue(config.globalStorage))
    local position = town:getTemplePosition()
    for i = 1, #players do
        local player = players[i]
        local tile = hasFlag(TILESTATE_PVPZONE)
        if not tile then
        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 .."Next map change will be in 30 minutes! Type !shop list to view the items available in shop!")
    end
end
and im getting this error
Code:
data/globalevents/scripts/changeMap.lua:onThink
data/globalevents/scripts/changeMap.lua:28: attempt to call global 'hasFlag' (a nil value)
stack traceback:
        [C]: in function 'hasFlag'
        data/globalevents/scripts/changeMap.lua:28: in function <data/globalevents/scripts/changeMap.lua:12>
[Error - GlobalEvents::think] Failed to execute event: ChangeMap

Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/changeMap.lua:onThink
data/globalevents/scripts/changeMap.lua:28: attempt to call global 'hasFlag' (a nil value)
stack traceback:
        [C]: in function 'hasFlag'
        data/globalevents/scripts/changeMap.lua:28: in function <data/globalevents/scripts/changeMap.lua:12>
[Error - GlobalEvents::think] Failed to execute event: ChangeMap
 
Last edited:
Solution
does not work the player that was in map with the red square "pvp zone tool" added in remeres map editor was teleported as every other player. i used pvp zone tool in remeres
and there is no error displayed in console
up
oops.

change line 30
Lua:
local tile = Tile(position)
to
Lua:
local tile = Tile(playerPosition)
try this
Lua:
local config = {
    townIds = {
        [1] = "Thais",
        [2] = "Edron",
        [3] = "Carlin",
        [4] = "Venore",
        [5] = "Werida",
        [6] = "sanislan"
    },
    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)
        local playerPosition = player:getPosition() -- added
        local tile = Tile(position)                 -- added
        if not tile:hasFlag(TILESTATE_PVPZONE) then -- added
            player:teleportTo(position)
            player:addHealth(player:getMaxHealth())
            player:addMana(player:getMaxMana())
        end                                         -- added
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "The map has been changed to ".. towns .."Next map change will be in 30 minutes! Type !shop list to view the items available in shop!")
    end
    position:sendMagicEffect(CONST_ME_TELEPORT)
    print("The map has been changed to ".. towns .."Next map change will be in 30 minutes! Type !shop list to view the items available in shop!")
    return true
end
 
try this
Lua:
local config = {
    townIds = {
        [1] = "Thais",
        [2] = "Edron",
        [3] = "Carlin",
        [4] = "Venore",
        [5] = "Werida",
        [6] = "sanislan"
    },
    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)
        local playerPosition = player:getPosition() -- added
        local tile = Tile(position)                 -- added
        if not tile:hasFlag(TILESTATE_PVPZONE) then -- added
            player:teleportTo(position)
            player:addHealth(player:getMaxHealth())
            player:addMana(player:getMaxMana())
        end                                         -- added
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "The map has been changed to ".. towns .."Next map change will be in 30 minutes! Type !shop list to view the items available in shop!")
    end
    position:sendMagicEffect(CONST_ME_TELEPORT)
    print("The map has been changed to ".. towns .."Next map change will be in 30 minutes! Type !shop list to view the items available in shop!")
    return true
end
does not work the player that was in map with the red square "pvp zone tool" added in remeres map editor was teleported as every other player. i used pvp zone tool in remeres
and there is no error displayed in console
up
 
does not work the player that was in map with the red square "pvp zone tool" added in remeres map editor was teleported as every other player. i used pvp zone tool in remeres
and there is no error displayed in console
up
oops.

change line 30
Lua:
local tile = Tile(position)
to
Lua:
local tile = Tile(playerPosition)
 
Solution
does not work either and there are no error in console, is there an other way to check if player is in an position to exclude him from this globalevent? GlobalEvent - Change Map [TFS 1.X] (https://otland.net/threads/change-map-tfs-1-x.227517/)
i'm using tfs 1.4 downgraded datapack by nekiro
maybe remove the storage 100 if player is standing on pvp zone or similar approach like exclude if player is from pos to pos in map
Lua:
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)
        local playerPosition = player:getPosition() -- added
        local tile = Tile(playerPosition)              -- added
        if not tile:hasFlag(TILESTATE_PVPZONE) then -- added
            player:teleportTo(position)
            player:addHealth(player:getMaxHealth())
            player:addMana(player:getMaxMana())
        end                                         -- added
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "The map has been changed to ".. towns .."Next map change will be in 30 minutes! Type !shop list to view the items available in shop!")
    end
    position:sendMagicEffect(CONST_ME_TELEPORT)
    print("The map has been changed to ".. towns .."Next map change will be in 30 minutes! Type !shop list to view the items available in shop!")
    return tru
Post automatically merged:

tried changing
Code:
 if not tile:hasFlag(TILESTATE_PVPZONE) then
to this
Lua:
if not (Tile(playerPosition):hasFlag(TILESTATE_PVPZONE)) then
still no work and no error

tried ths and im getting this error
Lua:
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()
        local playerPosition = player:getPosition() -- added
        local tile = Tile(playerPosition)               -- added
        if not (Tile(pos):hasFlag(TILESTATE_PVPZONE)) then -- added
        for i = 1, #players do
        local player = players[i]
        player:setTown(town)
            player:teleportTo(position)
            player:addHealth(player:getMaxHealth())
            player:addMana(player:getMaxMana())
        end                                         -- added
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "The map has been changed to ".. towns .."Next map change will be in 30 minutes! Type !shop list to view the items available in shop!")
    end
    position:sendMagicEffect(CONST_ME_TELEPORT)
    print("The map has been changed to ".. towns .."Next map change will be in 30 minutes! Type !shop list to view the items available in shop!")
    return true
end
Post automatically merged:

managed to get it working ! thank @Xikini for the help. this might help someone in the future
Lua:
--
for i = 1, #players do
        local player = players[i]
if not tile:hasFlag(TILESTATE_PVPZONE) then -- added
       if not (Tile(pos):hasFlag(TILESTATE_PVPZONE)) then
        player:setTown(town)
 
Last edited:
does not work either and there are no error in console, is there an other way to check if player is in an position to exclude him from this globalevent? GlobalEvent - Change Map [TFS 1.X] (https://otland.net/threads/change-map-tfs-1-x.227517/)
i'm using tfs 1.4 downgraded datapack by nekiro
maybe remove the storage 100 if player is standing on pvp zone or similar approach like exclude if player is from pos to pos in map
Lua:
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)
        local playerPosition = player:getPosition() -- added
        local tile = Tile(playerPosition)              -- added
        if not tile:hasFlag(TILESTATE_PVPZONE) then -- added
            player:teleportTo(position)
            player:addHealth(player:getMaxHealth())
            player:addMana(player:getMaxMana())
        end                                         -- added
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "The map has been changed to ".. towns .."Next map change will be in 30 minutes! Type !shop list to view the items available in shop!")
    end
    position:sendMagicEffect(CONST_ME_TELEPORT)
    print("The map has been changed to ".. towns .."Next map change will be in 30 minutes! Type !shop list to view the items available in shop!")
    return tru
Post automatically merged:

tried changing
Code:
 if not tile:hasFlag(TILESTATE_PVPZONE) then
to this
Lua:
if not (Tile(playerPosition):hasFlag(TILESTATE_PVPZONE)) then
still no work and no error

tried ths and im getting this error
Lua:
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()
        local playerPosition = player:getPosition() -- added
        local tile = Tile(playerPosition)               -- added
        if not (Tile(pos):hasFlag(TILESTATE_PVPZONE)) then -- added
        for i = 1, #players do
        local player = players[i]
        player:setTown(town)
            player:teleportTo(position)
            player:addHealth(player:getMaxHealth())
            player:addMana(player:getMaxMana())
        end                                         -- added
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "The map has been changed to ".. towns .."Next map change will be in 30 minutes! Type !shop list to view the items available in shop!")
    end
    position:sendMagicEffect(CONST_ME_TELEPORT)
    print("The map has been changed to ".. towns .."Next map change will be in 30 minutes! Type !shop list to view the items available in shop!")
    return true
end
Post automatically merged:

managed to get it working ! thank @Xikini for the help. this might help someone in the future
Lua:
--
for i = 1, #players do
        local player = players[i]
if not tile:hasFlag(TILESTATE_PVPZONE) then -- added
       if not (Tile(pos):hasFlag(TILESTATE_PVPZONE)) then
        player:setTown(town)
Glad you got it working.
 
Back
Top