• 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 TFS 1.3 - Lever that requires few specific items on basin

Niloahs

Well-Known Member
Joined
Feb 10, 2020
Messages
110
Solutions
1
Reaction score
82
I tried editing other existing scripts with a similar function but i couldn't make it work.

So, all i need is:

I-) Items must be dropped on specific basin.
II-) Once all items are on their basins, someone pulls the lever and Items + walls disappear.
III-) The lever only can be pulled after 1 hour.

That's it guys. That's all i need. I Hope someone can help me out.
 
Solution
I cannot see any part of your requirements in this script.
There is no code responsible for check whether items are in specified positions, no wall removing and no 1h delay.
Unfortunately, being honest, I cannot find any modifications done to the code ;p.

You can take a look into scripts like: Globalevent - Create and remove Wall from the map every two hours. (https://otland.net/threads/globalevent-create-and-remove-wall-from-the-map-every-two-hours.264017/#post-2551571)
or Remove wall on StepIn (https://otland.net/threads/remove-wall-on-stepin.247171/#post-2404332)
and take it as an example next time ;p it is more similar to your case.

I wrote something like that. I didn't test it so it might contain some typos or other...
According to your first sentence... Please upload your script.
It is much better to help someone who puts an effort to find the solution instead of one who came to the forum with an empty request (I know that this is a subforum for requests but you said that you already made some attempts).
And for sure it will be better to point out small correction instead of pasting random script and telling you to align it to your needs (as it might lead to another issue...). For sure you will learn something and the community will have less work to solve your problem ;)
 
you are totally correct!

this script need 4 players in the tiles

Lua:
local config = {
    requiredLevel = 8,
    daily = false,
    centerDemonRoomPosition = Position(33221, 31659, 13),
    playerPositions = {
        Position(333, 1712, 9)
        Position(333, 1712, 9)
        Position(333, 1712, 9)
    },
    newPositions = {
        Position(336, 1712, 9),
        Position(336, 1713, 9),
        Position(336, 1714, 9),
        Position(336, 1715, 9)
    },
    RotwormPositions = {
        Position(329, 1712, 9),
        Position(329, 1714, 9),
        Position(332, 1714, 9),
        Position(333, 1714, 9),
        Position(33220, 31661, 13),
        Position(33222, 31661, 13)
    }
}


function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 1946 then
        local storePlayers, playerTile = {}

        for i = 1, #config.playerPositions do
            playerTile = Tile(config.playerPositions[i]):getTopCreature()
            if not playerTile or not playerTile:isPlayer() then
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need 4 players.")
                return true
            end

            storePlayers[#storePlayers + 1] = playerTile
        end

        for i = 1, #config.RotwormPositions do
            Game.createMonster("Rotworm", config.RotwormPositions[i])
        end

        local players
        for i = 1, #storePlayers do
            players = storePlayers[i]
            config.playerPositions[i]:sendMagicEffect(CONST_ME_POFF)
            players:teleportTo(config.newPositions[i])
            config.newPositions[i]:sendMagicEffect(CONST_ME_ENERGYAREA)
            players:setDirection(DIRECTION_EAST)
        end
    elseif item.itemid == 1945 then
        if config.daily then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_NOTPOSSIBLE))
            return true
        end
    end

    item:transform(item.itemid == 1946 and 1945 or 1946)
    return true
end
 
I cannot see any part of your requirements in this script.
There is no code responsible for check whether items are in specified positions, no wall removing and no 1h delay.
Unfortunately, being honest, I cannot find any modifications done to the code ;p.

You can take a look into scripts like: Globalevent - Create and remove Wall from the map every two hours. (https://otland.net/threads/globalevent-create-and-remove-wall-from-the-map-every-two-hours.264017/#post-2551571)
or Remove wall on StepIn (https://otland.net/threads/remove-wall-on-stepin.247171/#post-2404332)
and take it as an example next time ;p it is more similar to your case.

I wrote something like that. I didn't test it so it might contain some typos or other issues but after corrections should do the job.
Lua:
local config = {
    items = {
        {position = Position(329, 1712, 9), itemid = 1337},
        {position = Position(329, 1713, 9), itemid = 1338},
        {position = Position(329, 1714, 9), itemid = 1339}
    },
    walls = {
        {position = Position(330, 1716, 9), itemid = 2233},
        {position = Position(331, 1716, 9), itemid = 2233},
        {position = Position(332, 1716, 9), itemid = 2233}
    },
    lever = {
        duration = 60*60,
        storage = 13337
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local currentTime = os.time()

    -- disallow to pull the lever for some time since last pull
    local timerAllowPullLeverAt = Game.getStorageValue(config.lever.storage)
    if timerAllowPullLeverAt ~= nil and currentTime < timerAllowPullLeverAt then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_NOTPOSSIBLE))
        return true
    end
    
    -- disallow to pull the lever if any of walls does not exist
    local wallsToRemove, wallItem = {}
    for _, wall in ipairs(config.walls) do
        wallItem = Tile(wall.position):getItemById(wall.itemid)
        if wallItem == nil then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_NOTPOSSIBLE))
            return true
        end

        wallsToRemove[#wallsToRemove + 1] = wallItem
    end

    -- check if all items are located at their positions
    local requiredItems, foundItem = {}
    for _, requiredItem in ipairs(config.items) do
        foundItem = Tile(requiredItem.position):getItemById(requiredItem.itemid)
        if foundItem == nil then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "Some item is missing.")
            return true
        end
    
        requiredItems[#requiredItems + 1] = foundItem
    end

    -- remove items
    for _, itemToRemove in ipairs(requiredItems) do
        itemToRemove:remove(1)
    end

    -- remove walls
    for _, wallToRemove in ipairs(wallsToRemove) do
        wallToRemove:remove(1)
    end

    -- set timer to next lever pull
    Game.getStorageValue(config.lever.storage, currentTime + config.lever.duration)

    -- set event to recreate walls
    addEvent(function(walls)
        for _, wall in ipairs(walls) do
            Game.createItem(wall.itemid, 1, wall.position)
        end
    end, config.lever.duration * 1000, config.walls)

    -- pull the lever
    item:transform(item.itemid == 1946 and 1945 or 1946)
    return true
end
 
Solution
it is working perfectly, im just trying now put some effect above walls and items when they are removed, can you help me with that?
 
You can do that easily inside those loops commented as "remove items" & "remove walls":
Lua:
-- remove items
for _, itemToRemove in ipairs(requiredItems) do
    itemToRemove:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    itemToRemove:remove(1)
end

-- remove walls
for _, wallToRemove in ipairs(wallsToRemove) do
    wallToRemove:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    wallToRemove:remove(1)
end
 
Back
Top