• 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 SCRIPT- Teleport lever for item

grego94

Member
Joined
Nov 16, 2015
Messages
12
Reaction score
5
Hello guys, i was just lurking for some script here and didn`t find anything usefull. I`m using 0.3.6 TFS (tried some stuff that i found but nothing works)
Im need a script for a lever, to summon a teleport in exchange for some stackable item, this teleport must disappear after a X seconds.
If anyone can help me i will be grate.
cya and thanks!
 
Solution
Hello!
Thanks, we pass through this, now that is what i get:



Its something that i need to do?
Ah I fixed that already as well, maybe you copied before my edit.

Use the updated script below.

Lua:
local teleporterCreatePosition = {x = 1000, y = 1000, z = 7}
local teleporterDestination = {x = 1000, y = 1000, z = 7}
local removeTimer = 5 -- seconds until remove
local teleporterId = 1387
local leverId = {1945, 1946}

local requiredItems = {
    {1111, 1, "Item 1"}, -- {itemid, amount, item_name}
    {2222, 2, "Item 2"},
    {3333, 3, "Item 3"}
}

local function removeItemOnPosition(itemid, position)
    local item = getTileItemById(position, itemid).uid
    if item > 0 then
        doRemoveItem(item)
        return true
    end...
Hello dude, take this example from the demon helmet quest, I just added AddEvent()
to remove teleport in 15sec
not tested.

In case of an error you edit it yourself and just give /reload actions with gm. in the place you want it to work and test.


Lua:
local t = {
    Position(33316, 31574, 15), -- teleport creation position
    Position(33322, 31592, 14) -- where the teleport takes you
}

function  TimeTeleport()
    teleport:remove()
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    if item.itemid == 1945 then
       
    local teleport = Game.createItem(1387, 1, t[1])

    if teleport then
    addEvent(TimeTeleport, 15000, cid)
         teleport:setDestination(t[2])
         t[2]:sendMagicEffect(CONST_ME_TELEPORT)
end
    elseif item.itemid == 1946 then
   
    local tile = t[1]:getTile()

    if tile then
       
    local teleport = tile:getItemById(1387)

    if teleport and teleport:isTeleport() then
    teleport:remove()
    end
end
    t[1]:sendMagicEffect(CONST_ME_POFF)
end
    return item:transform(item.itemid == 1945 and 1946 or 1945)
end
 
Hello dude, take this example from the demon helmet quest, I just added AddEvent()
to remove teleport in 15sec
not tested.

In case of an error you edit it yourself and just give /reload actions with gm. in the place you want it to work and test.


Lua:
local t = {
    Position(33316, 31574, 15), -- teleport creation position
    Position(33322, 31592, 14) -- where the teleport takes you
}

function  TimeTeleport()
    teleport:remove()
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    if item.itemid == 1945 then
     
    local teleport = Game.createItem(1387, 1, t[1])

    if teleport then
    addEvent(TimeTeleport, 15000, cid)
         teleport:setDestination(t[2])
         t[2]:sendMagicEffect(CONST_ME_TELEPORT)
end
    elseif item.itemid == 1946 then
 
    local tile = t[1]:getTile()

    if tile then
     
    local teleport = tile:getItemById(1387)

    if teleport and teleport:isTeleport() then
    teleport:remove()
    end
end
    t[1]:sendMagicEffect(CONST_ME_POFF)
end
    return item:transform(item.itemid == 1945 and 1946 or 1945)
end
This is TFS 1.0+ scripting. He's using 0.3.6, so this won't work for him.

Try this instead.
Lua:
local teleporterPosition = {x = 1000, y = 1000, z = 7}
local removeTimer = 5 -- seconds until remove
local teleporterId = 1387
local leverId = {1945, 1946}

local function removeItemOnPosition(itemid, position)
    local item = getTileItemById(position, itemid).uid
    if item > 0 then
        doRemoveItem(item)
        return true
    end
    return false
end

function onUse(cid, item, fromPosition, itemEx, toPosition)

    -- check if teleport has already been spawned
    local teleport = getTileItemById(teleporterPosition, teleporterId).uid
    if teleport > 0 then
        return true
    end
    
    -- create teleport and remove after x time
    doCreateItem(teleporterId, 1, teleporterPosition)
    addEvent(removeItemOnPosition, removeTimer * 1000, teleporterId, teleporterPosition)
    
    -- lever flopping
    doTransformItem(item.uid, item.itemid == leverId[1] and leverId[2] or leverId[1])
    return true
end
 
This is TFS 1.0+ scripting. He's using 0.3.6, so this won't work for him.

Try this instead.
Lua:
local teleporterPosition = {x = 1000, y = 1000, z = 7}
local removeTimer = 5 -- seconds until remove
local teleporterId = 1387
local leverId = {1945, 1946}

local function removeItemOnPosition(itemid, position)
    local item = getTileItemById(position, itemid).uid
    if item > 0 then
        doRemoveItem(item)
        return true
    end
    return false
end

function onUse(cid, item, fromPosition, itemEx, toPosition)

    -- check if teleport has already been spawned
    local teleport = getTileItemById(teleporterPosition, teleporterId).uid
    if teleport > 0 then
        return true
    end
  
    -- create teleport and remove after x time
    doCreateItem(teleporterId, 1, teleporterPosition)
    addEvent(removeItemOnPosition, removeTimer * 1000, teleporterId, teleporterPosition)
  
    -- lever flopping
    doTransformItem(item.uid, item.itemid == leverId[1] and leverId[2] or leverId[1])
    return true
end
Hello!
Thanks for the answer, i really appreciate your help.
I have some points about what i get:
The lever is working fine, when pulled, the teleport appears. But i need a lever that consume itens from player to create the teleport.
And another point, the teleport (already configurated) dont send me anywhere :( it appears, but when i step in i still in the same place.

If u need something from me, i can show you my TFS logs and script, but i just changed the xyz pos.
 
Last edited:
Hello!
Thanks for the answer, i really appreciate your help.
I have some points about what i get:
The lever is working fine, when pulled, the teleport appears. But i need a lever that consume itens from player to create the teleport.
And another point, the teleport (already configurated) dont send me anywhere :( it appears, but when i step in i still in the same place.

If u need something from me, i can show you my TFS logs and script, but i just changed the xyz pos.
Lua:
local teleporterCreatePosition = {x = 1000, y = 1000, z = 7}
local teleporterDestination = {x = 1000, y = 1000, z = 7}
local removeTimer = 5 -- seconds until remove
local teleporterId = 1387
local leverId = {1945, 1946}

local requiredItems = {
    {1111, 1, "Item 1"}, -- {itemid, amount, item_name}
    {2222, 2, "Item 2"},
    {3333, 3, "Item 3"}
}

local function removeItemOnPosition(itemid, position)
    local item = getTileItemById(position, itemid).uid
    if item > 0 then
        doRemoveItem(item)
        return true
    end
    return false
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
  
    -- check if teleport has already been spawned
    local teleport = getTileItemById(teleporterCreatePosition, teleporterId).uid
    if teleport > 0 then
        return true
    end
  
    local itemsRequiredText = ""
    local hasItems = true
    for i = 1, #requiredItems do
        if getPlayerItemCount(cid, requiredItems[i][1]) < requiredItems[i][2] then
            hasItems = false
        end
        if text ~= "" then
            text = text .. ", "
        end
        text = text .. requiredItems[i][2] .. " " .. requiredItems[i][3]
    end
  
    if not hasItems then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Missing required items to create teleporter. (" .. itemsRequiredText .. ")")
        return true
    end
  
    for i = 1, #requiredItems do
        doPlayerRemoveItem(cid, requiredItems[i][1], requiredItems[i][2])
    end
  
    -- create teleport and remove after x time
    doCreateTeleport(teleporterId, teleporterDestination, teleporterCreatePosition)
    addEvent(removeItemOnPosition, removeTimer * 1000, teleporterId, teleporterPosition)
  
    -- lever flopping
    doTransformItem(item.uid, item.itemid == leverId[1] and leverId[2] or leverId[1])
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Teleporter has been created, and will disappear in " .. removeTimer .. " seconds.")
    return true
end
 
Lua:
local teleporterCreatePosition = {x = 1000, y = 1000, z = 7}
local teleporterDestination = {x = 1000, y = 1000, z = 7}
local removeTimer = 5 -- seconds until remove
local teleporterId = 1387
local leverId = {1945, 1946}

local requiredItems = {
    {1111, 1, "Item 1"}, -- {itemid, amount, item_name}
    {2222, 2, "Item 2"},
    {3333, 3, "Item 3"}
}

local function removeItemOnPosition(itemid, position)
    local item = getTileItemById(position, itemid).uid
    if item > 0 then
        doRemoveItem(item)
        return true
    end
    return false
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
   
    -- check if teleport has already been spawned
    local teleport = getTileItemById(teleporterPosition, teleporterId).uid
    if teleport > 0 then
        return true
    end
   
    local itemsRequiredText = ""
    local hasItems = true
    for i = 1, #requiredItems do
        if getPlayerItemCount(cid, requiredItems[i][1]) < requiredItems[i][2] then
            hasItems = false
        end
        if text ~= "" then
            text = text .. ", "
        end
        text = text .. requiredItems[i][2] .. " " requiredItems[i][3]
    end
   
    if not hasItems then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Missing required items to create teleporter. (" .. itemsRequiredText .. ")")
        return true
    end
   
    for i = 1, #requiredItems do
        doPlayerRemoveItem(cid, requiredItems[i][1], requiredItems[i][2])
    end
   
    -- create teleport and remove after x time
    doCreateTeleport(teleporterId, teleporterDestination, teleporterCreatePosition)
    addEvent(removeItemOnPosition, removeTimer * 1000, teleporterId, teleporterPosition)
   
    -- lever flopping
    doTransformItem(item.uid, item.itemid == leverId[1] and leverId[2] or leverId[1])
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Teleporter has been created, and will disappear in " .. removeTimer .. " seconds.")
    return true
end
Hello dear friend, thank you again for your time.
Now that's what im facing:

[22/03/2022 22:14:37] [Error - LuaScriptInterface::loadFile] data/actions/scripts/levers/genios1.lua:39: '=' expected near 'end'
[22/03/2022 22:14:37] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/levers/genios1.lua)
[22/03/2022 22:14:37] data/actions/scripts/levers/genios1.lua:39: '=' expected near 'end'

But what i saw in functions that u have add, its exactly what i want/need!
Can u help me with this point too? :)

cya
 
Hello dear friend, thank you again for your time.
Now that's what im facing:



But what i saw in functions that u have add, its exactly what i want/need!
Can u help me with this point too? :)

cya
change
Lua:
text = text .. requiredItems[i][2] .. " " requiredItems[i][3]
to
Lua:
text = text .. requiredItems[i][2] .. " " .. requiredItems[i][3]
 
change
Lua:
text = text .. requiredItems[i][2] .. " " requiredItems[i][3]
to
Lua:
text = text .. requiredItems[i][2] .. " " .. requiredItems[i][3]
Hello!
Thanks, we pass through this, now that is what i get:

data/actions/scripts/levers/genios1.lua:eek:nUse
[22/03/2022 22:52:35] Description:
[22/03/2022 22:52:35] attempt to index a nil value
[22/03/2022 22:52:35] stack traceback:
[22/03/2022 22:52:35] [C]: in function 'getTileItemById'
[22/03/2022 22:52:35] data/actions/scripts/levers/genios1.lua:24: in function <data/actions/scripts/levers/genios1.lua:21>

Its something that i need to do?
 
Hello!
Thanks, we pass through this, now that is what i get:



Its something that i need to do?
Ah I fixed that already as well, maybe you copied before my edit.

Use the updated script below.

Lua:
local teleporterCreatePosition = {x = 1000, y = 1000, z = 7}
local teleporterDestination = {x = 1000, y = 1000, z = 7}
local removeTimer = 5 -- seconds until remove
local teleporterId = 1387
local leverId = {1945, 1946}

local requiredItems = {
    {1111, 1, "Item 1"}, -- {itemid, amount, item_name}
    {2222, 2, "Item 2"},
    {3333, 3, "Item 3"}
}

local function removeItemOnPosition(itemid, position)
    local item = getTileItemById(position, itemid).uid
    if item > 0 then
        doRemoveItem(item)
        return true
    end
    return false
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    
    -- check if teleport has already been spawned
    local teleport = getTileItemById(teleporterCreatePosition, teleporterId).uid
    if teleport > 0 then
        return true
    end
    
    local itemsRequiredText = ""
    local hasItems = true
    for i = 1, #requiredItems do
        if getPlayerItemCount(cid, requiredItems[i][1]) < requiredItems[i][2] then
            hasItems = false
        end
        if itemsRequiredText ~= "" then
            itemsRequiredText = itemsRequiredText .. ", "
        end
        itemsRequiredText = itemsRequiredText .. requiredItems[i][2] .. " " .. requiredItems[i][3]
    end
    
    if not hasItems then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Missing required items to create teleporter. (" .. itemsRequiredText .. ")")
        return true
    end
    
    for i = 1, #requiredItems do
        doPlayerRemoveItem(cid, requiredItems[i][1], requiredItems[i][2])
    end
    
    -- create teleport and remove after x time
    doCreateTeleport(teleporterId, teleporterDestination, teleporterCreatePosition)
    addEvent(removeItemOnPosition, removeTimer * 1000, teleporterId, teleporterCreatePosition)
    
    -- lever flopping
    doTransformItem(item.uid, item.itemid == leverId[1] and leverId[2] or leverId[1])
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Teleporter has been created, and will disappear in " .. removeTimer .. " seconds.")
    return true
end
 
Last edited:
Solution
Back
Top