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

TFS 1.X+ create tile on no ground tile 1.5

bpm91

Intermediate OT User
Joined
May 23, 2019
Messages
882
Solutions
7
Reaction score
123
Location
Brazil
YouTube
caruniawikibr
Hey guys, I'm trying to make the bridge do and undo when pulling levers, but it doesn't create the floor, the lever moves

Lua:
function onUse(cid, item, frompos, item2, topos)

gatepos1 = {x=32426, y=32201, z=14, stackpos=1}
getgate1 = getThingfromPos(gatepos1)
gatepos2 = {x=32426, y=32202, z=14, stackpos=1}
getgate2 = getThingfromPos(gatepos2)

switchpos1 = {x=32428, y=32198, z=14}
switchpos2 = {x=32428, y=32203, z=14}


    
if item.itemid == 1946 then   

doCreateItem(1284,1,gatepos1)
doCreateItem(1284,1,gatepos2)

doTransformItem(getTileItemById(switchpos1, 1946).uid,1945)
doTransformItem(getTileItemById(switchpos2, 1946).uid,1945)         

elseif item.itemid == 1945 then

doRemoveItem(1284,1,gatepos1)
doRemoveItem(1284,1,gatepos2)

doTransformItem(getTileItemById(switchpos1, 1945).uid,1946)
doTransformItem(getTileItemById(switchpos2, 1945).uid,1946)
      
else
doPlayerSendCancel(cid,"Sorry not possible.")
end
  return 1
  end

Screenshot_1.png
 
i change line local tile = t[4]:getTile()
to local tile = t[4]:getTile(Position)
and work Constme Poff
but no create item
Post automatically merged:


Now Work, i chnge to scripts/action <3 ty so much u save me <3
So happy it helped friend! Good luck with your project!

Btw :
on line 6 add :
Lua:
local effect = CONST_ME_POFF
on line 45 add :
Lua:
bridgePos1:sendMagicEffect(effect)
bridgePos2:sendMagicEffect(effect)
If you want that visual effect aswell.
 
nice i want effect too <3
Post automatically merged:

I have a small problem, I need to be kicked when I'm in the middle of the bridge and someone closes..
 
The player on the bridge is not being teleported
nice i want effect too <3
Post automatically merged:

I have a small problem, I need to be kicked when I'm in the middle of the bridge and someone closes..


Lua:
local switchBridge = Action()

local leverOn = 1946
local leverOff = 1945
local bridgeTile = 405
local effect = CONST_ME_POFF

local bridgePos = {Position({
    x = 1090,
    y = 1003,
    z = 8
}), Position({
    x = 1091,
    y = 1003,
    z = 8
})}

local leverTile = {Position({
    x = 1089,
    y = 1002,
    z = 8
}), Position({
    x = 1092,
    y = 1004,
    z = 8
})}

local teleportToPos = Position({x = 1089, y = 1003, z = 8})

function Position:createItem(itemid, count)
    local toTile = Tile(self)
    if not toTile or not toTile:getItems() or not toTile:getGround() then
        doAreaCombatHealth(0, 0, self, 0, 0, 0, CONST_ME_NONE)
        Game.createItem(itemid, count, self)
    end
end

function switchBridge.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not player then
        return
    end

    for i, v in ipairs(leverTile) do
        if Tile(v):getItemById(leverOff) then
            Tile(v):getItemById(leverOff):transform(leverOn)
        else
            Tile(v):getItemById(leverOn):transform(leverOff)
        end
    end

    if item.itemid == leverOn then
        for i, v in ipairs(bridgePos) do
            v:sendMagicEffect(effect)
            v:createItem(bridgeTile, 1)
        end
    else
        for i, v in ipairs(bridgePos) do
            local bridgeTilePos = Tile(v):getItemById(bridgeTile)
            print(Tile(v):getItemById(2120))
            local searchCreature = getTopCreature(v).uid
            if Creature(searchCreature) then
                Creature(searchCreature):teleportTo(teleportToPos)
            end
            bridgeTilePos:remove()
        end
    end
end

switchBridge:aid(32191)
switchBridge:register()
 
Lua:
local switchBridge = Action()

local leverOn = 1946
local leverOff = 1945
local bridgeTile = 405
local effect = CONST_ME_POFF

local bridgePos = {Position({
    x = 1090,
    y = 1003,
    z = 8
}), Position({
    x = 1091,
    y = 1003,
    z = 8
})}

local leverTile = {Position({
    x = 1089,
    y = 1002,
    z = 8
}), Position({
    x = 1092,
    y = 1004,
    z = 8
})}

local teleportToPos = Position({x = 1089, y = 1003, z = 8})

function Position:createItem(itemid, count)
    local toTile = Tile(self)
    if not toTile or not toTile:getItems() or not toTile:getGround() then
        doAreaCombatHealth(0, 0, self, 0, 0, 0, CONST_ME_NONE)
        Game.createItem(itemid, count, self)
    end
end

function switchBridge.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not player then
        return
    end

    for i, v in ipairs(leverTile) do
        if Tile(v):getItemById(leverOff) then
            Tile(v):getItemById(leverOff):transform(leverOn)
        else
            Tile(v):getItemById(leverOn):transform(leverOff)
        end
    end

    if item.itemid == leverOn then
        for i, v in ipairs(bridgePos) do
            v:sendMagicEffect(effect)
            v:createItem(bridgeTile, 1)
        end
    else
        for i, v in ipairs(bridgePos) do
            local bridgeTilePos = Tile(v):getItemById(bridgeTile)
            print(Tile(v):getItemById(2120))
            local searchCreature = getTopCreature(v).uid
            if Creature(searchCreature) then
                Creature(searchCreature):teleportTo(teleportToPos)
            end
            bridgeTilePos:remove()
        end
    end
end

switchBridge:aid(32191)
switchBridge:register()
bad argument #1 to 'ipairs' (table expected, got nil)
 
Fixed so that it removes items + fluids aswell
Lua:
local switchBridge = Action()

local leverOn = 1946
local leverOff = 1945
local bridgeTile = 405
local effect = CONST_ME_POFF

local bridgePos = {Position({
    x = 1090,
    y = 1003,
    z = 8
}), Position({
    x = 1091,
    y = 1003,
    z = 8
})}

local leverTile = {Position({
    x = 1089,
    y = 1002,
    z = 8
}), Position({
    x = 1092,
    y = 1004,
    z = 8
})}

local teleportToPos = Position({
    x = 1089,
    y = 1003,
    z = 8
})

function Position:createItem(itemid, count)
    local toTile = Tile(self)
    if not toTile or not toTile:getItems() or not toTile:getGround() then
        doAreaCombatHealth(0, 0, self, 0, 0, 0, CONST_ME_NONE)
        Game.createItem(itemid, count, self)
    end
end

function switchBridge.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not player then
        return
    end

    for i, v in ipairs(leverTile) do
        if Tile(v):getItemById(leverOff) then
            Tile(v):getItemById(leverOff):transform(leverOn)
        else
            Tile(v):getItemById(leverOn):transform(leverOff)
        end
    end

    if item.itemid == leverOn then
        for i, v in ipairs(bridgePos) do
            v:sendMagicEffect(effect)
            v:createItem(bridgeTile, 1)
        end
    else
        for i, v in ipairs(bridgePos) do
            local bridgeTilePos = Tile(v):getItemById(bridgeTile)
            local items = Tile(v):getItems()
            if items then
                for i = 1, #items do
                    items[i]:remove()
                end
            end
            local searchCreature = getTopCreature(v).uid
            if Creature(searchCreature) then
                Creature(searchCreature):teleportTo(teleportToPos)
            end
            bridgeTilePos:remove()
        end
    end
end

switchBridge:aid(32191)
switchBridge:register()
bad argument #1 to 'ipairs' (table expected, got nil)
Post full error
 
@bpm91 Show the whole script so we can see why it has null instead of array in that loop, (most likely bridgePos is wrongly defined - but line number do not match with posted script)
 
Lua:
local switchBridge = Action()

local leverOn = 1946
local leverOff = 1945
local bridgeTile = 1284
local effect = CONST_ME_POFF

local bridgePos1 = Position({
    x = 32426,
    y = 32201,
    z = 14
})
local bridgePos2 = Position({
    x = 32426,
    y = 32202,
    z = 14
})

local bridgePos3 = Position({
    x = 32427,
    y = 32201,
    z = 14
})
local bridgePos4 = Position({
    x = 32427,
    y = 32202,
    z = 14
})


local leverTile1 = Position({
    x = 32428,
    y = 32198,
    z = 14
})

local leverTile2 = Position({
    x = 32428,
    y = 32203,
    z = 14
})


local teleportToPos = Position({
    x = 32426,
    y = 32200,
    z = 14
})

function Position:createItem(itemid, count)
    local toTile = Tile(self)
    if not toTile or not toTile:getItems() or not toTile:getGround() then
        doAreaCombatHealth(0, 0, self, 0, 0, 0, CONST_ME_NONE)
        Game.createItem(itemid, count, self)
    end
end

function switchBridge.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not player then
        return
    end

    for i, v in ipairs(leverTile) do
        if Tile(v):getItemById(leverOff) then
            Tile(v):getItemById(leverOff):transform(leverOn)
        else
            Tile(v):getItemById(leverOn):transform(leverOff)
        end
    end

    if item.itemid == leverOn then
        for i, v in ipairs(bridgePos) do
            v:sendMagicEffect(effect)
            v:createItem(bridgeTile, 1)
        end
    else
        for i, v in ipairs(bridgePos) do
            local bridgeTilePos = Tile(v):getItemById(bridgeTile)
            local items = Tile(v):getItems()
            if items then
                for i = 1, #items do
                    items[i]:remove()
                end
            end
            local searchCreature = getTopCreature(v).uid
            if Creature(searchCreature) then
                Creature(searchCreature):teleportTo(teleportToPos)
            end
            bridgeTilePos:remove()
        end
    end
end

switchBridge:aid(19120)
switchBridge:register()
 
@bpm91 Show the whole script so we can see why it has null instead of array in that loop, (most likely bridgePos is wrongly defined - but line number do not match with posted script)
Yea exactly what I thought, I was like "how does he get an Ipair error on this line
Lua:
local items = Tile(v):getItems()
XD
Post automatically merged:

Lua:
local switchBridge = Action()

local leverOn = 1946
local leverOff = 1945
local bridgeTile = 1284
local effect = CONST_ME_POFF

local bridgePos1 = Position({
    x = 32426,
    y = 32201,
    z = 14
})
local bridgePos2 = Position({
    x = 32426,
    y = 32202,
    z = 14
})

local bridgePos3 = Position({
    x = 32427,
    y = 32201,
    z = 14
})
local bridgePos4 = Position({
    x = 32427,
    y = 32202,
    z = 14
})


local leverTile1 = Position({
    x = 32428,
    y = 32198,
    z = 14
})

local leverTile2 = Position({
    x = 32428,
    y = 32203,
    z = 14
})


local teleportToPos = Position({
    x = 32426,
    y = 32200,
    z = 14
})

function Position:createItem(itemid, count)
    local toTile = Tile(self)
    if not toTile or not toTile:getItems() or not toTile:getGround() then
        doAreaCombatHealth(0, 0, self, 0, 0, 0, CONST_ME_NONE)
        Game.createItem(itemid, count, self)
    end
end

function switchBridge.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not player then
        return
    end

    for i, v in ipairs(leverTile) do
        if Tile(v):getItemById(leverOff) then
            Tile(v):getItemById(leverOff):transform(leverOn)
        else
            Tile(v):getItemById(leverOn):transform(leverOff)
        end
    end

    if item.itemid == leverOn then
        for i, v in ipairs(bridgePos) do
            v:sendMagicEffect(effect)
            v:createItem(bridgeTile, 1)
        end
    else
        for i, v in ipairs(bridgePos) do
            local bridgeTilePos = Tile(v):getItemById(bridgeTile)
            local items = Tile(v):getItems()
            if items then
                for i = 1, #items do
                    items[i]:remove()
                end
            end
            local searchCreature = getTopCreature(v).uid
            if Creature(searchCreature) then
                Creature(searchCreature):teleportTo(teleportToPos)
            end
            bridgeTilePos:remove()
        end
    end
end

switchBridge:aid(19120)
switchBridge:register()
Ohh, you need to change the positions. Check how I did it, they are supposed to be grouped under bridgePos instead of bridgePos1 etc
 
Yea exactly what I thougt, I was like "how does he get an Ipair error on this line
Lua:
local items = Tile(v):getItems()
XD
Post automatically merged:


Ohh, you need to change the positions. Check how I did it, they are supposed to be grouped under bridgePos instead of bridgePos1 etc
How do I do?
 
Yea exactly what I thougt, I was like "how does he get an Ipair error on this line
Lua:
local items = Tile(v):getItems()
XD
Post automatically merged:


Ohh, you need to change the positions. Check how I did it, they are supposed to be grouped under bridgePos instead of bridgePos1 etc
Should look like :


Lua:
local bridgePos = { Position({
    x = 32426,
    y = 32201,
    z = 14
}),
Position({
    x = 32426,
    y = 32202,
    z = 14
}),
Position({
    x = 32427,
    y = 32201,
    z = 14
}),
Position({
    x = 32427,
    y = 32202,
    z = 14
})}


local leverTile = { Position({
    x = 32428,
    y = 32198,
    z = 14
}),
Position({
    x = 32428,
    y = 32203,
    z = 14
})
}
Post automatically merged:

Should look like :


Lua:
local bridgePos = { Position({
    x = 32426,
    y = 32201,
    z = 14
}),
Position({
    x = 32426,
    y = 32202,
    z = 14
}),
Position({
    x = 32427,
    y = 32201,
    z = 14
}),
Position({
    x = 32427,
    y = 32202,
    z = 14
})}


local leverTile = { Position({
    x = 32428,
    y = 32198,
    z = 14
}),
Position({
    x = 32428,
    y = 32203,
    z = 14
})
}
This is because I made it loop instead of having to to everything per tile.
 
Should look like :


Lua:
local bridgePos = { Position({
    x = 32426,
    y = 32201,
    z = 14
}),
Position({
    x = 32426,
    y = 32202,
    z = 14
}),
Position({
    x = 32427,
    y = 32201,
    z = 14
}),
Position({
    x = 32427,
    y = 32202,
    z = 14
})}


local leverTile = { Position({
    x = 32428,
    y = 32198,
    z = 14
}),
Position({
    x = 32428,
    y = 32203,
    z = 14
})
}
Post automatically merged:


This is because I made it loop instead of having to to everything per tile.
Perfect bro THX!
 
Back
Top