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

function to check tile tfs 1.2

president vankk

Web Developer & AuraOT Owner
Joined
Jul 10, 2009
Messages
5,719
Solutions
9
Reaction score
339
Hi everyone, I got stucked with the code below it is suppost to check the tile id. I'll explain it.. If you are under a tile with id 999 and you're in proctetion zone then you can use the item if not returns a error msg.

Code:
function onUse(player, item, fromPosition, position, target, toPosition, isHotkey)
   local tile = Tile(position)
   if not tile then
     return false
   end

   local tile = tile:getItemById(9999)
   if tile and Tile(player:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) then
    -- shit happens
   else
     player:sendCancelMessage("You can't do it without be in a protection zones.")
   end
   return true
end

Thanks.
 
Solution
Hi everyone, I got stucked with the code below it is suppost to check the tile id. I'll explain it.. If you are under a tile with id 999 and you're in proctetion zone then you can use the item if not returns a error msg.

Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   local tile = Tile(position)
   if not tile then
     return false
   end

   local tile = tile:getItemById(9999)
   if tile and Tile(player:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) then
    -- shit happens
   else
     player:sendCancelMessage("You can't do it without be in a protection zones.")
   end
   return true
end

Thanks.
"local tile = Tile(position)" There is no variable position so Tile(nil) = nil so its returning...
Hi everyone, I got stucked with the code below it is suppost to check the tile id. I'll explain it.. If you are under a tile with id 999 and you're in proctetion zone then you can use the item if not returns a error msg.

Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   local tile = Tile(position)
   if not tile then
     return false
   end

   local tile = tile:getItemById(9999)
   if tile and Tile(player:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) then
    -- shit happens
   else
     player:sendCancelMessage("You can't do it without be in a protection zones.")
   end
   return true
end

Thanks.
"local tile = Tile(position)" There is no variable position so Tile(nil) = nil so its returning false and doing nothing.

Try this:
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local tile = Tile(player:getPosition())
    if not tile then
        return false
    end

    local tileid = tile:getItemById(9999)
    if tileid and tile:hasFlag(TILESTATE_PROTECTIONZONE) then
        -- shit happens
    else
        player:sendCancelMessage("You can't do it without be in a protection zones.")
    end
    return true
end
 
Solution
Try this:

Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   local ntile = Tile(player:getPosition())
   local stile = ntile:getItemById(9999)
   if not ntile then
     return true
   end

   if stile and Tile(player:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) then
    -- shit happens
   else
     player:sendCancelMessage("You can't do it without be in a protection zones.")
   end
   return true
end
 
sorry to bump how do i check if tile if pvpzone? im tring to add an exception at changemap function but im having this error in console
tfs 1.4
LUA:
    local town = Town(Game.getStorageValue(config.globalStorage))
    local position = town:getTemplePosition()
   local tile = hasFlag(cid, TILESTATE_PVPZONE)
if not tile then
    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 .."Next map change will be in 30 minutes! Type !shop list to view the items available in shop!")
    end
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 t

Code:
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/changeMap.lua:onThink
data/globalevents/scripts/changeMap.lua:26: attempt to call global 'hasFlag' (a nil value)
stack traceback:
        [C]: in function 'hasFlag'
        data/globalevents/scripts/changeMap.lua:26: 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:26: attempt to call global 'hasFlag' (a nil value)
stack traceback:
        [C]: in function 'hasFlag'
        data/globalevents/scripts/changeMap.lua:26: in function <data/globalevents/scripts/changeMap.lua:12>
[Error - GlobalEvents::think] Failed to execute event: ChangeMap
 
sorry to bump how do i check if tile if pvpzone? im tring to add an exception at changemap function but im having this error in console
tfs 1.4
LUA:
    local town = Town(Game.getStorageValue(config.globalStorage))
    local position = town:getTemplePosition()
   local tile = hasFlag(cid, TILESTATE_PVPZONE)
if not tile then
    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 .."Next map change will be in 30 minutes! Type !shop list to view the items available in shop!")
    end
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 t

Code:
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/changeMap.lua:onThink
data/globalevents/scripts/changeMap.lua:26: attempt to call global 'hasFlag' (a nil value)
stack traceback:
        [C]: in function 'hasFlag'
        data/globalevents/scripts/changeMap.lua:26: 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:26: attempt to call global 'hasFlag' (a nil value)
stack traceback:
        [C]: in function 'hasFlag'
        data/globalevents/scripts/changeMap.lua:26: in function <data/globalevents/scripts/changeMap.lua:12>
[Error - GlobalEvents::think] Failed to execute event: ChangeMap

an example
LUA:
local position = Position(1000, 1000, 7)
local tile = Tile(position)
if not tile then
    -- no tile exists at this position
    return
end
if tile:hasFlag(TILESTATE_PVPZONE) then
    -- tile is pvpzone
    return
end
 
Back
Top