• 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 create temporary teleport onuse

wafuboe

Member
Joined
Dec 24, 2010
Messages
881
Solutions
2
Reaction score
22
Hello,

Im looking for a script that you use with item id "30179" a mallet on itemid on map itemid"28424" then item #2 will be a teleport with a destination that will turn back to item 28424 after 8 seconds. you will lose item 30179 in this process.

also if someone has a script that if you damage a boss you get a certain storage after its killed.

Thank you!
 
Solution
Hello,

Im looking for a script that you use with item id "30179" a mallet on itemid on map itemid"28424" then item #2 will be a teleport with a destination that will turn back to item 28424 after 8 seconds. you will lose item 30179 in this process.

XML:
<action itemid="30179" script="teleport_mallet.lua"/>

Lua:
local malletId = 30179 -- mallet ID
local teleportId = 1387 -- teleport ID
local revertToId = 28424 -- item ID to revert after 8 seconds
local destination = Position(100, 100, 7) -- replace with the correct destination coordinates

function doCreateTeleport(itemId, destination, position)
    local item = Game.createItem(itemId, 1, position)
    if item and item:isTeleport() then
        item:setDestination(destination)...
Hello,

Im looking for a script that you use with item id "30179" a mallet on itemid on map itemid"28424" then item #2 will be a teleport with a destination that will turn back to item 28424 after 8 seconds. you will lose item 30179 in this process.

XML:
<action itemid="30179" script="teleport_mallet.lua"/>

Lua:
local malletId = 30179 -- mallet ID
local teleportId = 1387 -- teleport ID
local revertToId = 28424 -- item ID to revert after 8 seconds
local destination = Position(100, 100, 7) -- replace with the correct destination coordinates

function doCreateTeleport(itemId, destination, position)
    local item = Game.createItem(itemId, 1, position)
    if item and item:isTeleport() then
        item:setDestination(destination)
        return true
    elseif item then
        item:remove()
    end
    return false
end

local function revertTeleport(position)
    local tile = Tile(position)
    if tile then
        local teleport = tile:getItemById(teleportId)
        if teleport then
            teleport:remove()
        end
        Game.createItem(revertToId, 1, position)
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target:getId() == revertToId and item:getId() == malletId then
        if player:removeItem(malletId, 1) then
            if doCreateTeleport(teleportId, destination, toPosition) then
                target:remove()               
                addEvent(revertTeleport, 8000, toPosition)
            else
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "There was a problem creating the teleport.")
            end
            return true
        else
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need a mallet to use on this.")
            return true
        end
    end
    return false
end
 
Solution
XML:
<action itemid="30179" script="teleport_mallet.lua"/>

Lua:
local malletId = 30179 -- mallet ID
local teleportId = 1387 -- teleport ID
local revertToId = 28424 -- item ID to revert after 8 seconds
local destination = Position(100, 100, 7) -- replace with the correct destination coordinates

function doCreateTeleport(itemId, destination, position)
    local item = Game.createItem(itemId, 1, position)
    if item and item:isTeleport() then
        item:setDestination(destination)
        return true
    elseif item then
        item:remove()
    end
    return false
end

local function revertTeleport(position)
    local tile = Tile(position)
    if tile then
        local teleport = tile:getItemById(teleportId)
        if teleport then
            teleport:remove()
        end
        Game.createItem(revertToId, 1, position)
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target:getId() == revertToId and item:getId() == malletId then
        if player:removeItem(malletId, 1) then
            if doCreateTeleport(teleportId, destination, toPosition) then
                target:remove()              
                addEvent(revertTeleport, 8000, toPosition)
            else
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "There was a problem creating the teleport.")
            end
            return true
        else
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need a mallet to use on this.")
            return true
        end
    end
    return false
end
thanks works smoothly!!!!!!!!!!!!!!
 
Back
Top